mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:47:36 +00:00
LibLine: Move search-related updates into do_cursor_left/right
This way, arrow-left and arrow-right behave consistently with ctrl-b/ctrl-f.
This commit is contained in:
parent
dc62371439
commit
b0384bb1bb
1 changed files with 34 additions and 34 deletions
|
@ -431,8 +431,7 @@ void Editor::handle_read_event()
|
|||
|
||||
enum Amount { Character, Word };
|
||||
auto do_cursor_left = [&](Amount amount) {
|
||||
if (m_cursor == 0)
|
||||
return;
|
||||
if (m_cursor > 0) {
|
||||
if (amount == Word) {
|
||||
auto skipped_at_least_one_character = false;
|
||||
for (;;) {
|
||||
|
@ -446,10 +445,11 @@ void Editor::handle_read_event()
|
|||
} else {
|
||||
--m_cursor;
|
||||
}
|
||||
}
|
||||
m_inline_search_cursor = m_cursor;
|
||||
};
|
||||
auto do_cursor_right = [&](Amount amount) {
|
||||
if (m_cursor >= m_buffer.size())
|
||||
return;
|
||||
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.
|
||||
|
@ -464,6 +464,9 @@ void Editor::handle_read_event()
|
|||
} 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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue