Skip to content

Commit 279599c

Browse files
one-someawesomekling
authored andcommitted
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.
1 parent 77601e0 commit 279599c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Userland/Libraries/LibGUI/EditingEngine.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,10 @@ TextPosition EditingEngine::find_end_of_next_word()
477477
bool is_first_iteration = true;
478478
auto& lines = m_editor->lines();
479479
auto cursor = m_editor->cursor();
480+
481+
if ((lines.at(cursor.line()).length() - cursor.column()) <= 1)
482+
return { cursor.line(), cursor.column() };
483+
480484
for (size_t line_index = cursor.line(); line_index < lines.size(); line_index++) {
481485
auto& line = lines.at(line_index);
482486

@@ -605,6 +609,10 @@ TextPosition EditingEngine::find_beginning_of_previous_word()
605609
bool is_first_iteration = true;
606610
auto& lines = m_editor->lines();
607611
auto cursor = m_editor->cursor();
612+
613+
if ((lines.at(cursor.line()).length() - cursor.column()) <= 1)
614+
return { cursor.line(), cursor.column() };
615+
608616
for (size_t line_index = cursor.line(); (int)line_index >= 0; line_index--) {
609617
auto& line = lines.at(line_index);
610618

0 commit comments

Comments
 (0)