From eb4bbc337fd4bb9a4407b1ce2732f0712abf71a7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 5 Dec 2018 02:28:29 +0100 Subject: [PATCH] Add some more vi-like movements. --- Editor/Editor.cpp | 10 +++++++++- Editor/Editor.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 33a714146a..e1a539f7bb 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -150,9 +150,11 @@ int Editor::exec() case 'k': move_up(); break; case 'l': move_right(); break; case 'i': set_mode(EditingDocument); break; + case 'I': move_to_start_of_line(); set_mode(EditingDocument); break; case 'A': move_to_end_of_line(); set_mode(EditingDocument); break; + case '0': move_to_start_of_line(); break; + case '$': move_to_end_of_line(); break; case 'a': move_right(); set_mode(EditingDocument); break; - case 'q': m_should_quit = true; break; case '\\': set_mode(EditingCommand); break; } } @@ -233,6 +235,12 @@ void Editor::move_to_end_of_line() update_scroll_position_if_needed(); } +void Editor::move_to_start_of_line() +{ + m_cursor.move_to(m_cursor.line(), 0); + update_scroll_position_if_needed(); +} + size_t Editor::max_line() const { return m_document->line_count() - 1; diff --git a/Editor/Editor.h b/Editor/Editor.h index 7d65b38834..ff637fd667 100644 --- a/Editor/Editor.h +++ b/Editor/Editor.h @@ -43,6 +43,7 @@ private: void move_up(); void move_right(); void move_to_end_of_line(); + void move_to_start_of_line(); size_t max_line() const; size_t max_column() const;