Add cursor movements to move to SOL and EOL.
This commit is contained in:
parent
c2166b4bd1
commit
f876b68bd0
@ -122,28 +122,39 @@ PieceTable::Cursor::Cursor(PieceTable * pt) : iterator(pt)
|
|||||||
init_column();
|
init_column();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PieceTable::Cursor::go_start_of_line()
|
bool PieceTable::Cursor::go_start_of_line()
|
||||||
{
|
{
|
||||||
|
bool rv = false;
|
||||||
while (iterator.valid() &&
|
while (iterator.valid() &&
|
||||||
(!iterator.piece->prev->eol()) &&
|
(!iterator.piece->prev->eol()) &&
|
||||||
(iterator.piece->prev != iterator.piece_table->start_piece))
|
(iterator.piece->prev != iterator.piece_table->start_piece))
|
||||||
{
|
{
|
||||||
iterator.go_prev_piece();
|
iterator.go_prev_piece();
|
||||||
|
rv = true;
|
||||||
}
|
}
|
||||||
|
if (iterator.offset != 0u)
|
||||||
|
rv = true;
|
||||||
iterator.offset = 0u;
|
iterator.offset = 0u;
|
||||||
init_column();
|
init_column();
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PieceTable::Cursor::go_end_of_line()
|
bool PieceTable::Cursor::go_end_of_line()
|
||||||
{
|
{
|
||||||
|
bool rv = false;
|
||||||
while (iterator.valid() &&
|
while (iterator.valid() &&
|
||||||
(!iterator.piece->eol()) &&
|
(!iterator.piece->eol()) &&
|
||||||
(iterator.piece->next != iterator.piece_table->end_piece))
|
(iterator.piece->next != iterator.piece_table->end_piece))
|
||||||
{
|
{
|
||||||
iterator.go_next_piece();
|
iterator.go_next_piece();
|
||||||
|
rv = true;
|
||||||
}
|
}
|
||||||
|
uint32_t current_column = column;
|
||||||
iterator.go_end_of_piece();
|
iterator.go_end_of_piece();
|
||||||
calculate_column();
|
calculate_column();
|
||||||
|
if (column != current_column)
|
||||||
|
rv = true;
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PieceTable::Cursor::go_up(int n, uint32_t desired_column)
|
bool PieceTable::Cursor::go_up(int n, uint32_t desired_column)
|
||||||
|
@ -110,8 +110,8 @@ public:
|
|||||||
|
|
||||||
Cursor(PieceTable * pt);
|
Cursor(PieceTable * pt);
|
||||||
|
|
||||||
void go_start_of_line();
|
bool go_start_of_line();
|
||||||
void go_end_of_line();
|
bool go_end_of_line();
|
||||||
bool go_up(int n, uint32_t desired_column);
|
bool go_up(int n, uint32_t desired_column);
|
||||||
bool go_down(int n, uint32_t desired_column);
|
bool go_down(int n, uint32_t desired_column);
|
||||||
bool go_left(int n);
|
bool go_left(int n);
|
||||||
|
@ -234,6 +234,12 @@ void Window::handle_key(uint32_t scancode, uint32_t mod)
|
|||||||
case SDL_SCANCODE_ESCAPE:
|
case SDL_SCANCODE_ESCAPE:
|
||||||
m_exit_requested = true;
|
m_exit_requested = true;
|
||||||
break;
|
break;
|
||||||
|
case SDL_SCANCODE_0:
|
||||||
|
cursor_move(CURSOR_SOL);
|
||||||
|
break;
|
||||||
|
case SDL_SCANCODE_9:
|
||||||
|
cursor_move(CURSOR_EOL);
|
||||||
|
break;
|
||||||
case SDL_SCANCODE_H:
|
case SDL_SCANCODE_H:
|
||||||
cursor_move(CURSOR_LEFT);
|
cursor_move(CURSOR_LEFT);
|
||||||
break;
|
break;
|
||||||
@ -269,6 +275,12 @@ void Window::cursor_move(int which)
|
|||||||
case CURSOR_DOWN:
|
case CURSOR_DOWN:
|
||||||
success = m_cursor->go_down(1, m_cursor->column);
|
success = m_cursor->go_down(1, m_cursor->column);
|
||||||
break;
|
break;
|
||||||
|
case CURSOR_SOL:
|
||||||
|
success = m_cursor->go_start_of_line();
|
||||||
|
break;
|
||||||
|
case CURSOR_EOL:
|
||||||
|
success = m_cursor->go_end_of_line();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
@ -293,6 +305,16 @@ void Window::cursor_move(int which)
|
|||||||
row_offset = c.column / m_columns - current_row_offset + 1 + m_cursor->column / m_columns;
|
row_offset = c.column / m_columns - current_row_offset + 1 + m_cursor->column / m_columns;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case CURSOR_SOL:
|
||||||
|
row_offset = -current_row_offset;
|
||||||
|
break;
|
||||||
|
case CURSOR_EOL:
|
||||||
|
{
|
||||||
|
PieceTable::Cursor c = *m_cursor;
|
||||||
|
c.go_end_of_line();
|
||||||
|
row_offset = c.column / m_columns - current_row_offset;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
update_cursor_row(m_cursor_row + row_offset);
|
update_cursor_row(m_cursor_row + row_offset);
|
||||||
redraw();
|
redraw();
|
||||||
|
@ -22,6 +22,8 @@ protected:
|
|||||||
CURSOR_RIGHT,
|
CURSOR_RIGHT,
|
||||||
CURSOR_UP,
|
CURSOR_UP,
|
||||||
CURSOR_DOWN,
|
CURSOR_DOWN,
|
||||||
|
CURSOR_SOL,
|
||||||
|
CURSOR_EOL,
|
||||||
};
|
};
|
||||||
|
|
||||||
void resize();
|
void resize();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user