diff options
author | one-some <one-some01@protonmail.com> | 2021-03-27 18:13:26 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-30 11:32:59 +0200 |
commit | 279599cbedcb7eb7ab837cb0757e250e42d09f8c (patch) | |
tree | b0f028b26fd65b573648cbf1e378a3ef9d35cf6f /Userland | |
parent | 77601e09c8f1c3c9a6cad5e4881262e6fafb6a92 (diff) | |
download | serenity-279599cbedcb7eb7ab837cb0757e250e42d09f8c.zip |
EditingEngine: Don't jump to the beginning or end of a non-existant word
Previously, when jumping to the next word on the last column of a line,
or when jumping to the previous word on the first column, it would
crash. This checks if that is the case, and if so, will do nothing.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGUI/EditingEngine.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/EditingEngine.cpp b/Userland/Libraries/LibGUI/EditingEngine.cpp index 7907346af7..15a4de5233 100644 --- a/Userland/Libraries/LibGUI/EditingEngine.cpp +++ b/Userland/Libraries/LibGUI/EditingEngine.cpp @@ -477,6 +477,10 @@ TextPosition EditingEngine::find_end_of_next_word() bool is_first_iteration = true; auto& lines = m_editor->lines(); auto cursor = m_editor->cursor(); + + if ((lines.at(cursor.line()).length() - cursor.column()) <= 1) + return { cursor.line(), cursor.column() }; + for (size_t line_index = cursor.line(); line_index < lines.size(); line_index++) { auto& line = lines.at(line_index); @@ -605,6 +609,10 @@ TextPosition EditingEngine::find_beginning_of_previous_word() bool is_first_iteration = true; auto& lines = m_editor->lines(); auto cursor = m_editor->cursor(); + + if ((lines.at(cursor.line()).length() - cursor.column()) <= 1) + return { cursor.line(), cursor.column() }; + for (size_t line_index = cursor.line(); (int)line_index >= 0; line_index--) { auto& line = lines.at(line_index); |