Draw text based on new cursor movement system
The cursor row still locked to the first row for now
This commit is contained in:
1 parent
01bf455e68
commit
86246385d4
4 files changed
+135
-50
No files matched your search
+16
-8
@@ -118,22 +118,27 @@ void PieceTable::Iterator::go_prev_piece()
|
||||
|
||||
PieceTable::Cursor::Cursor(PieceTable * pt) : iterator(pt)
|
||||
{
|
||||
line = iterator.valid() ? 1u : 0u;
|
||||
line = 0u;
|
||||
init_column();
|
||||
}
|
||||
|
||||
void PieceTable::Cursor::go_start_of_line()
|
||||
{
|
||||
while (iterator.valid() && (!iterator.piece->prev->eol()))
|
||||
while (iterator.valid() &&
|
||||
(!iterator.piece->prev->eol()) &&
|
||||
(iterator.piece->prev != iterator.piece_table->start_piece))
|
||||
{
|
||||
iterator.go_prev_piece();
|
||||
}
|
||||
iterator.offset = 0u;
|
||||
init_column();
|
||||
}
|
||||
|
||||
void PieceTable::Cursor::go_end_of_line()
|
||||
{
|
||||
while (iterator.valid() && (!iterator.piece->eol()))
|
||||
while (iterator.valid() &&
|
||||
(!iterator.piece->eol()) &&
|
||||
(iterator.piece->next != iterator.piece_table->end_piece))
|
||||
{
|
||||
iterator.go_next_piece();
|
||||
}
|
||||
@@ -201,8 +206,8 @@ bool PieceTable::Cursor::go_right(int n)
|
||||
uint32_t chr = *iterator;
|
||||
if (chr == '\t')
|
||||
{
|
||||
column += iterator.piece_table->tabstop;
|
||||
column -= column % iterator.piece_table->tabstop;
|
||||
uint8_t tabstop = iterator.piece_table->tabstop;
|
||||
column += tabstop - (column + 1u) % tabstop;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -216,14 +221,15 @@ bool PieceTable::Cursor::is_start_of_line()
|
||||
{
|
||||
return iterator.valid() &&
|
||||
(iterator.offset == 0u) &&
|
||||
(iterator.piece->prev->eol());
|
||||
((iterator.piece->prev == iterator.piece_table->start_piece) ||
|
||||
iterator.piece->prev->eol());
|
||||
}
|
||||
|
||||
bool PieceTable::Cursor::is_end_of_line()
|
||||
{
|
||||
return iterator.valid() &&
|
||||
((iterator.offset + iterator.num_bytes_in_code_point()) >= iterator.piece->length) &&
|
||||
iterator.piece->eol();
|
||||
(iterator.piece->eol() || (iterator.piece->next == iterator.piece_table->end_piece));
|
||||
}
|
||||
|
||||
PieceTable::Piece * PieceTable::Cursor::prev_line() const
|
||||
@@ -268,7 +274,7 @@ void PieceTable::Cursor::init_column()
|
||||
{
|
||||
uint32_t chr = *iterator;
|
||||
/* TODO: handle multi-column characters */
|
||||
column = (chr == 0xFFFFFFFFu) ? 0u : (chr == '\t') ? iterator.piece_table->tabstop : 1u;
|
||||
column = (chr == '\t') ? iterator.piece_table->tabstop - 1u : 0u;
|
||||
}
|
||||
|
||||
void PieceTable::Cursor::calculate_column()
|
||||
@@ -286,6 +292,8 @@ void PieceTable::Cursor::calculate_column()
|
||||
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))
|
||||
{
|
||||
int32_t new_diff = abs((int32_t)(c - column));
|
||||
|
||||
@@ -116,6 +116,10 @@ public:
|
||||
bool go_down(int n, uint32_t desired_column);
|
||||
bool go_left(int n);
|
||||
bool go_right(int n);
|
||||
bool operator==(const Cursor & c)
|
||||
{
|
||||
return (c.line == line) && (c.column == column);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool is_start_of_line();
|
||||
|
||||
Reference in new issue
Block a user