From a268c673fa06362bcae5098768f0f812f320d9ed Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 29 Oct 2016 15:05:43 -0400 Subject: [PATCH] re-calculate cursor column for all cursors on any insertion --- src/core/PieceTable.cc | 5 +++++ src/core/PieceTable.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/core/PieceTable.cc b/src/core/PieceTable.cc index 8567566..d2fddc9 100644 --- a/src/core/PieceTable.cc +++ b/src/core/PieceTable.cc @@ -497,6 +497,11 @@ void PieceTable::insert_code_point(uint32_t code_point) uint8_t bytes = Encoding::encode(code_point, encoding, &m_append_buffer[m_append_buffer_index]); m_inserting_piece->length += bytes; m_append_buffer_index += bytes; + + for (auto cursor : m_cursors) + { + cursor->calculate_column(); + } } } diff --git a/src/core/PieceTable.h b/src/core/PieceTable.h index 4c847cf..9b4618d 100644 --- a/src/core/PieceTable.h +++ b/src/core/PieceTable.h @@ -135,6 +135,7 @@ public: } void warp_to_inserted_piece(Piece * piece); void warp_to_beginning_of_piece(Piece * piece); + void calculate_column(); protected: bool is_start_of_line(); @@ -142,7 +143,6 @@ public: Piece * prev_line() const; Piece * next_line() const; void init_column(); - void calculate_column(); void forward_to_column(uint32_t c); };