summaryrefslogtreecommitdiff
path: root/Libraries/LibLine
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2020-07-13 08:49:19 -0400
committerAndreas Kling <kling@serenityos.org>2020-07-13 19:48:53 +0200
commitb0384bb1bbc26070d2efa9f33556568a5f08d921 (patch)
tree6a77d3e07ef29438703b1df6ce9d48edd7072cae /Libraries/LibLine
parentdc62371439c1a5c6e5fa2f8372b3ab193dc9e561 (diff)
downloadserenity-b0384bb1bbc26070d2efa9f33556568a5f08d921.zip
LibLine: Move search-related updates into do_cursor_left/right
This way, arrow-left and arrow-right behave consistently with ctrl-b/ctrl-f.
Diffstat (limited to 'Libraries/LibLine')
-rw-r--r--Libraries/LibLine/Editor.cpp68
1 files changed, 34 insertions, 34 deletions
diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp
index 076a217c5a..3cd3a6f6f1 100644
--- a/Libraries/LibLine/Editor.cpp
+++ b/Libraries/LibLine/Editor.cpp
@@ -431,39 +431,42 @@ void Editor::handle_read_event()
enum Amount { Character, Word };
auto do_cursor_left = [&](Amount amount) {
- if (m_cursor == 0)
- return;
- if (amount == Word) {
- auto skipped_at_least_one_character = false;
- for (;;) {
- if (m_cursor == 0)
- break;
- if (skipped_at_least_one_character && isspace(m_buffer[m_cursor - 1])) // stop *after* a space, but only if it changes the position
- break;
- skipped_at_least_one_character = true;
- --m_cursor;
- }
- } else {
- --m_cursor;
- }
+ if (m_cursor > 0) {
+ if (amount == Word) {
+ auto skipped_at_least_one_character = false;
+ for (;;) {
+ if (m_cursor == 0)
+ break;
+ if (skipped_at_least_one_character && isspace(m_buffer[m_cursor - 1])) // stop *after* a space, but only if it changes the position
+ break;
+ skipped_at_least_one_character = true;
+ --m_cursor;
+ }
+ } else {
+ --m_cursor;
+ }
+ }
+ m_inline_search_cursor = m_cursor;
};
auto do_cursor_right = [&](Amount amount) {
- if (m_cursor >= m_buffer.size())
- return;
- if (amount == Word) {
- // Temporarily put a space at the end of our buffer,
- // doing this greatly simplifies the logic below.
- m_buffer.append(' ');
- for (;;) {
- if (m_cursor >= m_buffer.size())
- break;
- if (isspace(m_buffer[++m_cursor]))
- break;
- }
- m_buffer.take_last();
- } else {
- ++m_cursor;
- }
+ if (m_cursor < m_buffer.size()) {
+ if (amount == Word) {
+ // Temporarily put a space at the end of our buffer,
+ // doing this greatly simplifies the logic below.
+ m_buffer.append(' ');
+ for (;;) {
+ if (m_cursor >= m_buffer.size())
+ break;
+ if (isspace(m_buffer[++m_cursor]))
+ break;
+ }
+ m_buffer.take_last();
+ } else {
+ ++m_cursor;
+ }
+ }
+ m_inline_search_cursor = m_cursor;
+ m_search_offset = 0;
};
auto do_backspace = [&] {
@@ -559,14 +562,11 @@ void Editor::handle_read_event()
}
case 'D': // left
do_cursor_left(ctrl_held ? Word : Character);
- m_inline_search_cursor = m_cursor;
m_state = InputState::Free;
ctrl_held = false;
continue;
case 'C': // right
do_cursor_right(ctrl_held ? Word : Character);
- m_inline_search_cursor = m_cursor;
- m_search_offset = 0;
m_state = InputState::Free;
ctrl_held = false;
continue;