diff options
author | Matthew Hall <matthew@quickbeam.me.uk> | 2021-07-10 21:48:49 +0100 |
---|---|---|
committer | Gunnar Beutner <gunnar@beutner.name> | 2021-07-15 10:10:07 +0200 |
commit | a7e7f62d08c4dab602c082e4919dc3564e3e3f5e (patch) | |
tree | 6280ef9fd77c6d34ef25b080f63ebe6ecac0c9e2 /Userland/Libraries/LibGUI/EditingEngine.cpp | |
parent | 5d1676b05aa7c8a414881f0414ef3370581d8be5 (diff) | |
download | serenity-a7e7f62d08c4dab602c082e4919dc3564e3e3f5e.zip |
VimEditingEngine: Operate on real lines rather than wrapped ones
In the normal editing engine keys like Home, End etc work on visual
lines, but vim operates on real ones. Eg if you have a really long line
and wrapping is on then in normal editing Home would take you to the
beginning of the wrapped line, but 'I' would put you insert mode at the
beginning of the real line in vim.
Diffstat (limited to 'Userland/Libraries/LibGUI/EditingEngine.cpp')
-rw-r--r-- | Userland/Libraries/LibGUI/EditingEngine.cpp | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/Userland/Libraries/LibGUI/EditingEngine.cpp b/Userland/Libraries/LibGUI/EditingEngine.cpp index 99f2f779be..8f49701fb4 100644 --- a/Userland/Libraries/LibGUI/EditingEngine.cpp +++ b/Userland/Libraries/LibGUI/EditingEngine.cpp @@ -241,34 +241,42 @@ void EditingEngine::move_to_next_span(const KeyEvent& event) } } -void EditingEngine::move_to_line_beginning() +void EditingEngine::move_to_logical_line_beginning() { TextPosition new_cursor; + size_t first_nonspace_column = m_editor->current_line().first_non_whitespace_column(); + if (m_editor->cursor().column() == first_nonspace_column) { + new_cursor = { m_editor->cursor().line(), 0 }; + } else { + new_cursor = { m_editor->cursor().line(), first_nonspace_column }; + } + m_editor->set_cursor(new_cursor); +} + +void EditingEngine::move_to_line_beginning() +{ if (m_editor->is_wrapping_enabled()) { // FIXME: Replicate the first_nonspace_column behavior in wrapping mode. auto home_position = m_editor->cursor_content_rect().location().translated(-m_editor->width(), 0); - new_cursor = m_editor->text_position_at_content_position(home_position); + m_editor->set_cursor(m_editor->text_position_at_content_position(home_position)); } else { - size_t first_nonspace_column = m_editor->current_line().first_non_whitespace_column(); - if (m_editor->cursor().column() == first_nonspace_column) { - new_cursor = { m_editor->cursor().line(), 0 }; - } else { - new_cursor = { m_editor->cursor().line(), first_nonspace_column }; - } + move_to_logical_line_beginning(); } - m_editor->set_cursor(new_cursor); } void EditingEngine::move_to_line_end() { - TextPosition new_cursor; if (m_editor->is_wrapping_enabled()) { auto end_position = m_editor->cursor_content_rect().location().translated(m_editor->width(), 0); - new_cursor = m_editor->text_position_at_content_position(end_position); + m_editor->set_cursor(m_editor->text_position_at_content_position(end_position)); } else { - new_cursor = { m_editor->cursor().line(), m_editor->current_line().length() }; + move_to_logical_line_end(); } - m_editor->set_cursor(new_cursor); +} + +void EditingEngine::move_to_logical_line_end() +{ + m_editor->set_cursor({ m_editor->cursor().line(), m_editor->current_line().length() }); } void EditingEngine::move_one_up(const KeyEvent& event) |