add 'g' and 'G' commands to go to first and last line in buffer
This commit is contained in:
parent
8df75f5ab0
commit
237dbf9c2b
@ -19,7 +19,7 @@ public:
|
||||
INVALID_CODE_POINT = 0xFFFFFFFFu,
|
||||
};
|
||||
|
||||
Iterator(Buffer * buffer)
|
||||
Iterator(const Buffer * buffer)
|
||||
{
|
||||
m_buffer = buffer;
|
||||
m_offset = 0u;
|
||||
@ -87,7 +87,7 @@ public:
|
||||
size_t offset() const { return m_offset; }
|
||||
|
||||
protected:
|
||||
Buffer * m_buffer;
|
||||
const Buffer * m_buffer;
|
||||
size_t m_offset;
|
||||
size_t m_line;
|
||||
};
|
||||
@ -114,6 +114,8 @@ public:
|
||||
void insert_code_point(uint32_t code_point, bool adjust_iterators = true);
|
||||
void erase_code_point(const Buffer::Iterator & position);
|
||||
std::string filename() const { return m_filename; }
|
||||
Iterator begin() const { return Iterator(this); }
|
||||
Iterator end() const { return *m_eof_iterator; }
|
||||
|
||||
protected:
|
||||
bool m_eol_at_eof;
|
||||
|
@ -333,6 +333,9 @@ void BufferPane::handle_key(uint32_t keyval)
|
||||
case '$':
|
||||
cursor_move(CursorMovement::EOL);
|
||||
break;
|
||||
case 'G':
|
||||
cursor_move(CursorMovement::LAST_LINE);
|
||||
break;
|
||||
case 'a':
|
||||
if (**m_iterator != '\n')
|
||||
{
|
||||
@ -341,6 +344,9 @@ void BufferPane::handle_key(uint32_t keyval)
|
||||
m_buffer->enter_insert_mode(*m_iterator);
|
||||
m_window->request_redraw();
|
||||
break;
|
||||
case 'g':
|
||||
cursor_move(CursorMovement::FIRST_LINE);
|
||||
break;
|
||||
case 'h':
|
||||
cursor_move(CursorMovement::LEFT);
|
||||
break;
|
||||
@ -419,6 +425,28 @@ void BufferPane::cursor_move(CursorMovement which)
|
||||
case CursorMovement::EOL:
|
||||
moved = m_iterator->go_end_of_line(m_buffer->insert_mode());
|
||||
break;
|
||||
case CursorMovement::FIRST_LINE:
|
||||
{
|
||||
auto it = m_buffer->begin();
|
||||
if (it != *m_iterator)
|
||||
{
|
||||
*m_iterator = it;
|
||||
moved = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CursorMovement::LAST_LINE:
|
||||
{
|
||||
auto it = m_buffer->end();
|
||||
it.go_back();
|
||||
it.go_start_of_line();
|
||||
if (it != *m_iterator)
|
||||
{
|
||||
*m_iterator = it;
|
||||
moved = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (moved)
|
||||
{
|
||||
@ -446,6 +474,12 @@ void BufferPane::cursor_move(CursorMovement which)
|
||||
case CursorMovement::EOL:
|
||||
m_target_column = INT_MAX;
|
||||
break;
|
||||
case CursorMovement::FIRST_LINE:
|
||||
m_cursor_screen_row = 0;
|
||||
break;
|
||||
case CursorMovement::LAST_LINE:
|
||||
m_cursor_screen_row = m_rows;
|
||||
break;
|
||||
}
|
||||
m_cursor_screen_row = determine_new_cursor_screen_row();
|
||||
m_window->request_redraw();
|
||||
|
@ -25,6 +25,8 @@ protected:
|
||||
DOWN,
|
||||
SOL,
|
||||
EOL,
|
||||
FIRST_LINE,
|
||||
LAST_LINE,
|
||||
};
|
||||
|
||||
int effective_scroll_offset()
|
||||
|
Loading…
x
Reference in New Issue
Block a user