adjust cursor movement to optionally allow moving to EOL

This commit is contained in:
josh committed 2016-10-15 18:07:58 -04:00
1 parent 4ebe81c062
commit 261cc9abf8
4 files changed
+24 -15

No files matched your search

+14 -5
View File
@@ -138,7 +138,7 @@ bool PieceTable::Cursor::go_start_of_line()
return rv;
}
bool PieceTable::Cursor::go_end_of_line()
bool PieceTable::Cursor::go_end_of_line(bool allow_on_eol)
{
if (!iterator.valid())
return false;
@@ -148,11 +148,14 @@ bool PieceTable::Cursor::go_end_of_line()
(iterator.piece->next != iterator.piece_table->end_piece))
{
iterator.go_next_piece();
rv = true;
}
uint32_t current_column = column;
iterator.go_end_of_piece();
calculate_column();
if (!allow_on_eol)
{
go_left(1);
}
if (column != current_column)
rv = true;
return rv;
@@ -214,7 +217,7 @@ bool PieceTable::Cursor::go_left(int n)
return true;
}
bool PieceTable::Cursor::go_right(int n)
bool PieceTable::Cursor::go_right(int n, bool allow_on_eol)
{
if (!iterator.valid())
return false;
@@ -222,7 +225,13 @@ bool PieceTable::Cursor::go_right(int n)
{
return false;
}
Iterator iterator_2 = iterator;
iterator.go_next_position();
if ((!allow_on_eol) && is_end_of_line())
{
iterator = iterator_2;
return false;
}
uint32_t chr = *iterator;
if (chr == '\t')
{
@@ -307,7 +316,7 @@ void PieceTable::Cursor::calculate_column()
while ((tmp_cursor.iterator.piece != iterator.piece) ||
(tmp_cursor.iterator.offset < iterator.offset))
{
tmp_cursor.go_right(1);
tmp_cursor.go_right(1, true);
}
column = tmp_cursor.column;
}
@@ -317,7 +326,7 @@ void PieceTable::Cursor::forward_to_column(uint32_t c)
int32_t diff = abs((int32_t)(c - column));
if (diff == 0)
return;
while (go_right(1))
while (go_right(1, false))
{
int32_t new_diff = abs((int32_t)(c - column));
if (new_diff > diff)
+2 -2
View File
@@ -102,11 +102,11 @@ public:
Cursor(PieceTable * pt);
bool go_start_of_line();
bool go_end_of_line();
bool go_end_of_line(bool allow_on_eol);
bool go_up(int n, uint32_t desired_column);
bool go_down(int n, uint32_t desired_column);
bool go_left(int n);
bool go_right(int n);
bool go_right(int n, bool allow_on_eol);
bool operator==(const Cursor & c)
{
return (c.line == line) && (c.column == column);