1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:27:35 +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:
Nico Weber 2020-07-13 08:49:19 -04:00 committed by Andreas Kling
parent dc62371439
commit b0384bb1bb

View file

@ -431,39 +431,42 @@ void Editor::handle_read_event()
enum Amount { Character, Word }; enum Amount { Character, Word };
auto do_cursor_left = [&](Amount amount) { auto do_cursor_left = [&](Amount amount) {
if (m_cursor == 0) if (m_cursor > 0) {
return; if (amount == Word) {
if (amount == Word) { auto skipped_at_least_one_character = false;
auto skipped_at_least_one_character = false; for (;;) {
for (;;) { if (m_cursor == 0)
if (m_cursor == 0) break;
break; if (skipped_at_least_one_character && isspace(m_buffer[m_cursor - 1])) // stop *after* a space, but only if it changes the position
if (skipped_at_least_one_character && isspace(m_buffer[m_cursor - 1])) // stop *after* a space, but only if it changes the position break;
break; skipped_at_least_one_character = true;
skipped_at_least_one_character = true; --m_cursor;
--m_cursor; }
} } else {
} else { --m_cursor;
--m_cursor; }
} }
m_inline_search_cursor = m_cursor;
}; };
auto do_cursor_right = [&](Amount amount) { auto do_cursor_right = [&](Amount amount) {
if (m_cursor >= m_buffer.size()) if (m_cursor < m_buffer.size()) {
return; if (amount == Word) {
if (amount == Word) { // Temporarily put a space at the end of our buffer,
// Temporarily put a space at the end of our buffer, // doing this greatly simplifies the logic below.
// doing this greatly simplifies the logic below. m_buffer.append(' ');
m_buffer.append(' '); for (;;) {
for (;;) { if (m_cursor >= m_buffer.size())
if (m_cursor >= m_buffer.size()) break;
break; if (isspace(m_buffer[++m_cursor]))
if (isspace(m_buffer[++m_cursor])) break;
break; }
} m_buffer.take_last();
m_buffer.take_last(); } else {
} else { ++m_cursor;
++m_cursor; }
} }
m_inline_search_cursor = m_cursor;
m_search_offset = 0;
}; };
auto do_backspace = [&] { auto do_backspace = [&] {
@ -559,14 +562,11 @@ void Editor::handle_read_event()
} }
case 'D': // left case 'D': // left
do_cursor_left(ctrl_held ? Word : Character); do_cursor_left(ctrl_held ? Word : Character);
m_inline_search_cursor = m_cursor;
m_state = InputState::Free; m_state = InputState::Free;
ctrl_held = false; ctrl_held = false;
continue; continue;
case 'C': // right case 'C': // right
do_cursor_right(ctrl_held ? Word : Character); do_cursor_right(ctrl_held ? Word : Character);
m_inline_search_cursor = m_cursor;
m_search_offset = 0;
m_state = InputState::Free; m_state = InputState::Free;
ctrl_held = false; ctrl_held = false;
continue; continue;