keep a target cursor column to move to when moving cursor up or down
This commit is contained in:
parent
7d3b66fe84
commit
cde71ac70a
@ -135,6 +135,7 @@ bool Window::create(std::shared_ptr<Buffer> buffer)
|
|||||||
m_start_piece = m_buffer->piece_table->start_piece->next;
|
m_start_piece = m_buffer->piece_table->start_piece->next;
|
||||||
m_cursor_row = 0;
|
m_cursor_row = 0;
|
||||||
m_scroll_offset = 5;
|
m_scroll_offset = 5;
|
||||||
|
m_target_column = m_cursor->column;
|
||||||
|
|
||||||
resize();
|
resize();
|
||||||
|
|
||||||
@ -257,32 +258,36 @@ void Window::handle_key(uint32_t scancode, uint32_t mod)
|
|||||||
|
|
||||||
void Window::cursor_move(int which)
|
void Window::cursor_move(int which)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool moved = false;
|
||||||
int current_row_offset = m_cursor->column / m_columns;
|
int current_row_offset = m_cursor->column / m_columns;
|
||||||
int row_offset = 0;
|
int row_offset = 0;
|
||||||
|
|
||||||
switch (which)
|
switch (which)
|
||||||
{
|
{
|
||||||
case CURSOR_LEFT:
|
case CURSOR_LEFT:
|
||||||
success = m_cursor->go_left(1);
|
moved = m_cursor->go_left(1);
|
||||||
|
m_target_column = m_cursor->column;
|
||||||
break;
|
break;
|
||||||
case CURSOR_RIGHT:
|
case CURSOR_RIGHT:
|
||||||
success = m_cursor->go_right(1);
|
moved = m_cursor->go_right(1);
|
||||||
|
m_target_column = m_cursor->column;
|
||||||
break;
|
break;
|
||||||
case CURSOR_UP:
|
case CURSOR_UP:
|
||||||
success = m_cursor->go_up(1, m_cursor->column);
|
moved = m_cursor->go_up(1, m_target_column);
|
||||||
break;
|
break;
|
||||||
case CURSOR_DOWN:
|
case CURSOR_DOWN:
|
||||||
success = m_cursor->go_down(1, m_cursor->column);
|
moved = m_cursor->go_down(1, m_target_column);
|
||||||
break;
|
break;
|
||||||
case CURSOR_SOL:
|
case CURSOR_SOL:
|
||||||
success = m_cursor->go_start_of_line();
|
moved = m_cursor->go_start_of_line();
|
||||||
|
m_target_column = 0u;
|
||||||
break;
|
break;
|
||||||
case CURSOR_EOL:
|
case CURSOR_EOL:
|
||||||
success = m_cursor->go_end_of_line();
|
moved = m_cursor->go_end_of_line();
|
||||||
|
m_target_column = 0x7FFFFFFFu;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (success)
|
if (moved)
|
||||||
{
|
{
|
||||||
switch (which)
|
switch (which)
|
||||||
{
|
{
|
||||||
|
@ -52,6 +52,7 @@ protected:
|
|||||||
int m_rows;
|
int m_rows;
|
||||||
int m_cursor_row;
|
int m_cursor_row;
|
||||||
int m_scroll_offset;
|
int m_scroll_offset;
|
||||||
|
uint32_t m_target_column;
|
||||||
|
|
||||||
std::shared_ptr<Buffer> m_buffer;
|
std::shared_ptr<Buffer> m_buffer;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user