diff --git a/src/core/Buffer.cc b/src/core/Buffer.cc index 9be4742..82d7d53 100644 --- a/src/core/Buffer.cc +++ b/src/core/Buffer.cc @@ -146,3 +146,18 @@ bool Buffer::write_to_file(const char * filename) return true; } + +void Buffer::enter_insert_mode(const Buffer::Iterator & position) +{ + m_insert_position = position.offset(); + if (m_insert_position > m_gap_buffer->size()) + { + m_insert_position = 0; + } + m_insert_mode = true; +} + +void Buffer::exit_insert_mode() +{ + m_insert_mode = false; +} diff --git a/src/core/Buffer.h b/src/core/Buffer.h index ab5cbee..d4e4f7b 100644 --- a/src/core/Buffer.h +++ b/src/core/Buffer.h @@ -78,6 +78,7 @@ public: return m_offset >= other.m_offset; } size_t line() const { return m_line; } + size_t offset() const { return m_offset; } protected: Buffer * m_buffer; @@ -99,6 +100,9 @@ public: uint8_t * address(size_t offset) const { return m_gap_buffer->address(offset); } Encoding::Type encoding() const { return m_encoding; } uint8_t tabstop() const { return m_tabstop; } + void enter_insert_mode(const Buffer::Iterator & position); + void exit_insert_mode(); + bool insert_mode() const { return m_insert_mode; } protected: bool m_eol_at_eof; @@ -106,6 +110,8 @@ protected: std::shared_ptr m_gap_buffer; Encoding::Type m_encoding; uint8_t m_tabstop; + bool m_insert_mode; + size_t m_insert_position; void common_initialization(); bool load_from_file(const char * filename);