summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac <zacary.gillerat@connect.qut.edu.au>2021-01-26 13:30:55 +1000
committerAndreas Kling <kling@serenityos.org>2021-01-27 21:09:18 +0100
commitaec9658b4f217cb5e1b15720499eacb85e95b6ac (patch)
tree4ae494b43294b27218688f42989869729fc534ed
parent76a69be217821ef9c50306c83fb29495517e680a (diff)
downloadserenity-aec9658b4f217cb5e1b15720499eacb85e95b6ac.zip
EditingEngine: Fix move_to_previous_word not working on last char of doc
Code meant for the move_to_next_word functions which set the cursor to the last character in the file if it was reached was copied into the move_to_previous_word functions which lead them not moving when the function was called from the end of the file.
-rw-r--r--Userland/Libraries/LibGUI/EditingEngine.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/Userland/Libraries/LibGUI/EditingEngine.cpp b/Userland/Libraries/LibGUI/EditingEngine.cpp
index b49b3031c0..42c3aeb132 100644
--- a/Userland/Libraries/LibGUI/EditingEngine.cpp
+++ b/Userland/Libraries/LibGUI/EditingEngine.cpp
@@ -566,7 +566,7 @@ void EditingEngine::move_to_end_of_previous_word()
return;
}
- if (line_index == lines.size() - 1 && column_index == line.length() - 1) {
+ if (line_index == 0 && column_index == 0) {
m_editor->set_cursor({ line_index, column_index });
return;
}
@@ -614,9 +614,11 @@ void EditingEngine::move_to_beginning_of_previous_word()
const u32* line_chars = line.view().code_points();
const u32 current_char = line_chars[column_index];
- if (column_index == 0 && !is_first_iteration && (vim_isalnum(current_char) || vim_ispunct(current_char)))
+ if (column_index == 0 && !is_first_iteration && (vim_isalnum(current_char) || vim_ispunct(current_char))) {
+ return m_editor->set_cursor({ line_index, column_index });
+ } else if (line_index == 0 && column_index == 0) {
return m_editor->set_cursor({ line_index, column_index });
- else if (column_index == 0) {
+ } else if (column_index == 0 && is_first_iteration) {
is_first_iteration = false;
continue;
}
@@ -629,10 +631,6 @@ void EditingEngine::move_to_beginning_of_previous_word()
if (!is_first_iteration && vim_ispunct(current_char) && (isspace(next_char) || vim_isalnum(next_char)))
return m_editor->set_cursor({ line_index, column_index });
- if (line_index == lines.size() - 1 && column_index == line.length() - 1) {
- return m_editor->set_cursor({ line_index, column_index });
- }
-
is_first_iteration = false;
}
}