Jump to line number for :<n> commands

This commit is contained in:
josh committed 2018-03-19 23:20:32 -04:00
1 parent 7aa3c3b17f
commit 62868e596d
5 files changed
+70

No files matched your search

+36
View File
@@ -229,6 +229,42 @@ bool BufferView::cursor_move(CursorMovement which, uint32_t c, bool allow_eol)
return moved;
}
bool BufferView::cursor_move_to_line(size_t target_line)
{
size_t current_line = m_iterator->line();
std::shared_ptr<Buffer::Iterator> it;
if (target_line <= current_line / 2u)
{
it = m_buffer->beginp();
}
else if (target_line <= ((current_line + m_buffer->end().line()) / 2u))
{
it = m_iterator->clonep();
}
else
{
it = m_buffer->endp();
it->go_back();
it->go_start_of_line();
}
while (it->line() < target_line)
{
if (!it->go_next_line())
break;
}
while (it->line() > target_line)
{
if (!it->go_previous_line())
break;
}
if (current_line != it->line())
{
*m_iterator = *it;
return true;
}
return false;
}
void BufferView::scroll_view_up(int n_lines, bool allow_eol)
{
int orig_cursor_screen_row = m_cursor_screen_row;
+1
View File
@@ -83,6 +83,7 @@ public:
return BufferLineWalker(m_buffer, start_of_line, m_width, m_character_width_determiner);
}
bool cursor_move(CursorMovement which, uint32_t c, bool allow_eol);
bool cursor_move_to_line(size_t line);
int cursor_screen_row() const { return m_cursor_screen_row; }
int cursor_screen_column() const { return m_cursor_screen_column; }
int cursor_virtual_column() const { return m_cursor_virtual_column; }