diff --git a/src/core/GapBuffer.cc b/src/core/GapBuffer.cc index dd229c0..f35cc12 100644 --- a/src/core/GapBuffer.cc +++ b/src/core/GapBuffer.cc @@ -101,6 +101,24 @@ bool GapBuffer::Cursor::is_start_of_line() return *i2 == '\n'; } +bool GapBuffer::Cursor::is_end_of_line(bool allow_eol) +{ + if (*m_iterator == '\n') + { + return true; + } + if (!allow_eol) + { + Iterator i2 = m_iterator; + i2.go_forward(); + if (*i2 == '\n') + { + return true; + } + } + return false; +} + bool GapBuffer::Cursor::go_start_of_line() { bool moved = false; @@ -128,11 +146,11 @@ bool GapBuffer::Cursor::go_start_of_line() bool GapBuffer::Cursor::go_end_of_line() { bool moved = false; - if (go_right()) + if (go_right(false)) { moved = true; } - while (go_right()) + while (go_right(false)) { ; } @@ -161,9 +179,9 @@ bool GapBuffer::Cursor::go_left() return false; } -bool GapBuffer::Cursor::go_right() +bool GapBuffer::Cursor::go_right(bool allow_eol) { - if (!is_end_of_line()) + if (!is_end_of_line(allow_eol)) { if (m_iterator.check_go_forward()) { @@ -231,7 +249,7 @@ void GapBuffer::Cursor::calculate_column() tmp_cursor.go_start_of_line(); while (tmp_cursor < *this) { - tmp_cursor.go_right(); + tmp_cursor.go_right(true); } m_column = tmp_cursor.m_column; } @@ -241,7 +259,7 @@ void GapBuffer::Cursor::forward_to_column(size_t target_column) int32_t diff = abs((int32_t)(target_column - m_column)); if (diff == 0) return; - while (go_right()) + while (go_right(false)) { int32_t new_diff = abs((int32_t)(target_column - m_column)); if (new_diff > diff) diff --git a/src/core/GapBuffer.h b/src/core/GapBuffer.h index 78c3699..1a8605f 100644 --- a/src/core/GapBuffer.h +++ b/src/core/GapBuffer.h @@ -62,14 +62,11 @@ public: init_column(); } bool is_start_of_line(); - bool is_end_of_line() - { - return *m_iterator == '\n'; - } + bool is_end_of_line(bool allow_eol); bool go_start_of_line(); bool go_end_of_line(); bool go_left(); - bool go_right(); + bool go_right(bool allow_eol); bool go_up(size_t target_column); bool go_down(size_t target_column); bool operator<(const Cursor & other)