diff --git a/src/core/PieceTable.cc b/src/core/PieceTable.cc index 68b3108..8567566 100644 --- a/src/core/PieceTable.cc +++ b/src/core/PieceTable.cc @@ -333,6 +333,13 @@ void PieceTable::Cursor::warp_to_inserted_piece(Piece * piece) calculate_column(); } +void PieceTable::Cursor::warp_to_beginning_of_piece(Piece * piece) +{ + iterator.piece = piece; + iterator.offset = 0u; + calculate_column(); +} + bool PieceTable::Cursor::is_start_of_line() { if (!iterator.valid() || (iterator.offset > 0u)) @@ -418,7 +425,7 @@ void PieceTable::Cursor::forward_to_column(uint32_t c) } } -void PieceTable::begin_insert(const Cursor & cursor, bool before) +void PieceTable::begin_insert(Cursor & cursor, bool before) { Piece * piece = cursor.iterator.piece; uint32_t offset = cursor.iterator.offset; @@ -479,6 +486,7 @@ void PieceTable::begin_insert(const Cursor & cursor, bool before) change->chains[1][1] = nullptr; apply_change(change, 1u); + cursor.warp_to_beginning_of_piece(change->after); } void PieceTable::insert_code_point(uint32_t code_point) diff --git a/src/core/PieceTable.h b/src/core/PieceTable.h index e343049..4c847cf 100644 --- a/src/core/PieceTable.h +++ b/src/core/PieceTable.h @@ -134,6 +134,7 @@ public: return !(*this == c); } void warp_to_inserted_piece(Piece * piece); + void warp_to_beginning_of_piece(Piece * piece); protected: bool is_start_of_line(); @@ -165,7 +166,7 @@ public: std::shared_ptr add_cursor(); - void begin_insert(const Cursor & cursor, bool before); + void begin_insert(Cursor & cursor, bool before); void insert_code_point(uint32_t code_point); void end_insert(); void insertion_test(Cursor & c);