From cadd5bac3627305fa1fc803ddcb876d1a1a2db32 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 26 Dec 2016 08:56:36 -0500 Subject: [PATCH] Warp all cursors at/after the insert point when inserting a code point --- src/core/Buffer.cc | 8 ++++++++ src/core/Buffer.h | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/Buffer.cc b/src/core/Buffer.cc index 04a66e0..71228b8 100644 --- a/src/core/Buffer.cc +++ b/src/core/Buffer.cc @@ -169,6 +169,14 @@ void Buffer::insert_code_point(uint32_t code_point) uint8_t encoded[Encoding::MAX_CODE_POINT_SIZE]; uint8_t bytes = Encoding::encode(code_point, m_encoding, encoded); m_gap_buffer->insert(m_insert_position, encoded, bytes); + ssize_t lines = (code_point == '\n') ? 1 : 0; + for (auto iterator : m_iterators) + { + if (iterator->offset() >= m_insert_position) + { + iterator->warp(bytes, lines); + } + } m_insert_position += bytes; } } diff --git a/src/core/Buffer.h b/src/core/Buffer.h index a1f3720..f93e716 100644 --- a/src/core/Buffer.h +++ b/src/core/Buffer.h @@ -93,7 +93,9 @@ public: std::shared_ptr add_iterator() { - return std::make_shared(this); + std::shared_ptr iterator = std::make_shared(this); + m_iterators.push_back(iterator); + return iterator; } auto get_string() { return m_gap_buffer->get_string(); } size_t size() const { return m_gap_buffer->size(); } @@ -113,6 +115,7 @@ protected: uint8_t m_tabstop; bool m_insert_mode; size_t m_insert_position; + std::list> m_iterators; void common_initialization(); bool load_from_file(const char * filename);