mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
LibLine: Implement internal functions to jump cursor over non-space word
Two new internal functions `cursor_left_nonspace_word()` (`Ctrl+Alt+B`) and `cursor_right_nonspace_word()` (`Ctrl+Alt+F`) that jump the cursor left or right until a non-space character. Same implementation as the alphanumeric word jump functions `cursor_left_word()` (`Alt+B`) and `cursor_right_word()` (`Alt+F`).
This commit is contained in:
parent
a6ce86a4b3
commit
97bcdba2a5
3 changed files with 39 additions and 0 deletions
|
@ -166,6 +166,8 @@ void Editor::set_default_keybinds()
|
||||||
register_key_input_callback(Key { '.', Key::Alt }, EDITOR_INTERNAL_FUNCTION(insert_last_words));
|
register_key_input_callback(Key { '.', Key::Alt }, EDITOR_INTERNAL_FUNCTION(insert_last_words));
|
||||||
register_key_input_callback(Key { 'b', Key::Alt }, EDITOR_INTERNAL_FUNCTION(cursor_left_word));
|
register_key_input_callback(Key { 'b', Key::Alt }, EDITOR_INTERNAL_FUNCTION(cursor_left_word));
|
||||||
register_key_input_callback(Key { 'f', Key::Alt }, EDITOR_INTERNAL_FUNCTION(cursor_right_word));
|
register_key_input_callback(Key { 'f', Key::Alt }, EDITOR_INTERNAL_FUNCTION(cursor_right_word));
|
||||||
|
register_key_input_callback(Key { ctrl('B'), Key::Alt }, EDITOR_INTERNAL_FUNCTION(cursor_left_nonspace_word));
|
||||||
|
register_key_input_callback(Key { ctrl('F'), Key::Alt }, EDITOR_INTERNAL_FUNCTION(cursor_right_nonspace_word));
|
||||||
// ^[^H: alt-backspace: backward delete word
|
// ^[^H: alt-backspace: backward delete word
|
||||||
register_key_input_callback(Key { '\b', Key::Alt }, EDITOR_INTERNAL_FUNCTION(erase_alnum_word_backwards));
|
register_key_input_callback(Key { '\b', Key::Alt }, EDITOR_INTERNAL_FUNCTION(erase_alnum_word_backwards));
|
||||||
register_key_input_callback(Key { 'd', Key::Alt }, EDITOR_INTERNAL_FUNCTION(erase_alnum_word_forwards));
|
register_key_input_callback(Key { 'd', Key::Alt }, EDITOR_INTERNAL_FUNCTION(erase_alnum_word_forwards));
|
||||||
|
|
|
@ -105,8 +105,10 @@ struct Configuration {
|
||||||
M(clear_screen) \
|
M(clear_screen) \
|
||||||
M(cursor_left_character) \
|
M(cursor_left_character) \
|
||||||
M(cursor_left_word) \
|
M(cursor_left_word) \
|
||||||
|
M(cursor_left_nonspace_word) \
|
||||||
M(cursor_right_character) \
|
M(cursor_right_character) \
|
||||||
M(cursor_right_word) \
|
M(cursor_right_word) \
|
||||||
|
M(cursor_right_nonspace_word) \
|
||||||
M(enter_search) \
|
M(enter_search) \
|
||||||
M(erase_character_backwards) \
|
M(erase_character_backwards) \
|
||||||
M(erase_character_forwards) \
|
M(erase_character_forwards) \
|
||||||
|
|
|
@ -93,6 +93,23 @@ void Editor::cursor_left_word()
|
||||||
m_inline_search_cursor = m_cursor;
|
m_inline_search_cursor = m_cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::cursor_left_nonspace_word()
|
||||||
|
{
|
||||||
|
auto has_seen_nonspace = false;
|
||||||
|
while (m_cursor) {
|
||||||
|
// after seeing at least one non-space, stop just before a space
|
||||||
|
if (is_ascii_space(m_buffer[m_cursor - 1])) {
|
||||||
|
if (has_seen_nonspace)
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
has_seen_nonspace = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
--m_cursor;
|
||||||
|
}
|
||||||
|
m_inline_search_cursor = m_cursor;
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::cursor_left_character()
|
void Editor::cursor_left_character()
|
||||||
{
|
{
|
||||||
if (m_cursor > 0) {
|
if (m_cursor > 0) {
|
||||||
|
@ -121,6 +138,24 @@ void Editor::cursor_right_word()
|
||||||
m_search_offset = 0;
|
m_search_offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::cursor_right_nonspace_word()
|
||||||
|
{
|
||||||
|
auto has_seen_nonspace = false;
|
||||||
|
while (m_cursor < m_buffer.size()) {
|
||||||
|
// after seeing at least one non-space, stop at the first space
|
||||||
|
if (is_ascii_space(m_buffer[m_cursor])) {
|
||||||
|
if (has_seen_nonspace)
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
has_seen_nonspace = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
++m_cursor;
|
||||||
|
}
|
||||||
|
m_inline_search_cursor = m_cursor;
|
||||||
|
m_search_offset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::cursor_right_character()
|
void Editor::cursor_right_character()
|
||||||
{
|
{
|
||||||
if (m_cursor < m_buffer.size()) {
|
if (m_cursor < m_buffer.size()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue