Fix PieceTable::Cursor::prev_line and next_line to support empty pieces
This commit is contained in:
parent
878b9aaf34
commit
9756519f13
@ -351,35 +351,35 @@ bool PieceTable::Cursor::is_end_of_line()
|
|||||||
|
|
||||||
PieceTable::Piece * PieceTable::Cursor::prev_line() const
|
PieceTable::Piece * PieceTable::Cursor::prev_line() const
|
||||||
{
|
{
|
||||||
Piece * p = iterator.piece;
|
if (!iterator.valid())
|
||||||
while ((!p->prev->eol()) && (p->prev != iterator.piece_table->start_piece))
|
|
||||||
{
|
|
||||||
p = p->prev;
|
|
||||||
}
|
|
||||||
if (p->prev == iterator.piece_table->start_piece)
|
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
p = p->prev;
|
Cursor cursor2 = *this;
|
||||||
while ((!p->prev->eol()) && (p->prev != iterator.piece_table->start_piece))
|
cursor2.go_start_of_line();
|
||||||
|
cursor2.iterator.go_prev_position();
|
||||||
|
if (!cursor2.iterator.valid())
|
||||||
{
|
{
|
||||||
p = p->prev;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return p;
|
cursor2.go_start_of_line();
|
||||||
|
return cursor2.iterator.piece;
|
||||||
}
|
}
|
||||||
|
|
||||||
PieceTable::Piece * PieceTable::Cursor::next_line() const
|
PieceTable::Piece * PieceTable::Cursor::next_line() const
|
||||||
{
|
{
|
||||||
Piece * p = iterator.piece;
|
if (!iterator.valid())
|
||||||
while ((!p->eol()) && (p->next != iterator.piece_table->end_piece))
|
|
||||||
{
|
|
||||||
p = p->next;
|
|
||||||
}
|
|
||||||
if (p->next == iterator.piece_table->end_piece)
|
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return p->next;
|
Cursor cursor2 = *this;
|
||||||
|
cursor2.go_end_of_line(true);
|
||||||
|
cursor2.iterator.go_next_position();
|
||||||
|
if (!cursor2.iterator.valid())
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return cursor2.iterator.piece;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PieceTable::Cursor::init_column()
|
void PieceTable::Cursor::init_column()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user