diff --git a/src/core/GapBuffer.cc b/src/core/GapBuffer.cc index 267d98c..5a13cec 100644 --- a/src/core/GapBuffer.cc +++ b/src/core/GapBuffer.cc @@ -103,12 +103,40 @@ bool GapBuffer::Cursor::is_start_of_line() bool GapBuffer::Cursor::go_start_of_line() { - /* TODO */ + bool moved = false; + Iterator i2 = m_iterator; + for (;;) + { + i2.back(); + if (i2.valid() && (*i2 != '\n')) + { + moved = true; + m_iterator = i2; + } + else + { + break; + } + } + if (moved) + { + init_column(); + } + return moved; } bool GapBuffer::Cursor::go_end_of_line() { - /* TODO */ + bool moved = false; + if (go_right()) + { + moved = true; + } + while (go_right()) + { + ; + } + return moved; } bool GapBuffer::Cursor::go_left() @@ -156,6 +184,18 @@ bool GapBuffer::Cursor::go_right() return false; } +void GapBuffer::Cursor::init_column() +{ + if (*m_iterator == '\t') + { + m_column = m_iterator.gap_buffer()->tabstop - 1u; + } + else + { + m_column = 0u; + } +} + void GapBuffer::Cursor::calculate_column() { Cursor tmp_cursor = *this; diff --git a/src/core/GapBuffer.h b/src/core/GapBuffer.h index 0a2347d..1926d75 100644 --- a/src/core/GapBuffer.h +++ b/src/core/GapBuffer.h @@ -59,7 +59,7 @@ public: : m_iterator(gap_buffer) { m_line = 0u; - m_column = 0u; + init_column(); } bool is_start_of_line(); bool is_end_of_line() @@ -80,6 +80,7 @@ public: size_t m_line; size_t m_column; + void init_column(); void calculate_column(); };