VimEditingEngine: Add handling { and } to move between empty lines

This commit is contained in:
Rok Povsic 2021-01-11 22:22:27 +01:00 committed by Andreas Kling
parent f8fffe4613
commit 77d4b6e435
2 changed files with 48 additions and 0 deletions

View file

@ -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);
};
}

View file

@ -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);