mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
VimEditingEngine: Add handling { and } to move between empty lines
This commit is contained in:
parent
f8fffe4613
commit
77d4b6e435
Notes:
sideshowbarker
2024-07-18 19:08:11 +09:00
Author: https://github.com/rok-povsic Commit: https://github.com/SerenityOS/serenity/commit/77d4b6e435c Pull-request: https://github.com/SerenityOS/serenity/pull/4911 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/emanuele6
2 changed files with 48 additions and 0 deletions
|
@ -184,6 +184,12 @@ bool VimEditingEngine::on_key_in_normal_mode(const KeyEvent& event)
|
|||
move_one_up(event);
|
||||
switch_to_insert_mode();
|
||||
break;
|
||||
case (KeyCode::Key_LeftBrace):
|
||||
move_to_previous_empty_lines_block();
|
||||
break;
|
||||
case (KeyCode::Key_RightBrace):
|
||||
move_to_next_empty_lines_block();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -519,4 +525,44 @@ void VimEditingEngine::put(const GUI::KeyEvent& event)
|
|||
}
|
||||
}
|
||||
|
||||
void VimEditingEngine::move_to_previous_empty_lines_block()
|
||||
{
|
||||
VERIFY(!m_editor.is_null());
|
||||
size_t line_idx = m_editor->cursor().line();
|
||||
bool skipping_initial_empty_lines = true;
|
||||
while (line_idx > 0) {
|
||||
if (m_editor->document().line(line_idx).is_empty()) {
|
||||
if (!skipping_initial_empty_lines)
|
||||
break;
|
||||
} else {
|
||||
skipping_initial_empty_lines = false;
|
||||
}
|
||||
line_idx--;
|
||||
}
|
||||
|
||||
TextPosition new_cursor = { line_idx, 0 };
|
||||
|
||||
m_editor->set_cursor(new_cursor);
|
||||
};
|
||||
|
||||
void VimEditingEngine::move_to_next_empty_lines_block()
|
||||
{
|
||||
VERIFY(!m_editor.is_null());
|
||||
size_t line_idx = m_editor->cursor().line();
|
||||
bool skipping_initial_empty_lines = true;
|
||||
while (line_idx < m_editor->line_count() - 1) {
|
||||
if (m_editor->document().line(line_idx).is_empty()) {
|
||||
if (!skipping_initial_empty_lines)
|
||||
break;
|
||||
} else {
|
||||
skipping_initial_empty_lines = false;
|
||||
}
|
||||
line_idx++;
|
||||
}
|
||||
|
||||
TextPosition new_cursor = { line_idx, 0 };
|
||||
|
||||
m_editor->set_cursor(new_cursor);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -47,6 +47,8 @@ private:
|
|||
void switch_to_visual_mode();
|
||||
void move_half_page_up(const KeyEvent& event);
|
||||
void move_half_page_down(const KeyEvent& event);
|
||||
void move_to_previous_empty_lines_block();
|
||||
void move_to_next_empty_lines_block();
|
||||
|
||||
bool on_key_in_insert_mode(const KeyEvent& event);
|
||||
bool on_key_in_normal_mode(const KeyEvent& event);
|
||||
|
|
Loading…
Reference in a new issue