From 4ad5615dffd1d0bda40bbd61742d7794267dcf2d Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 21 Dec 2016 22:10:58 -0500 Subject: [PATCH] fix Buffer::Iterator::go_previous_line() and go_next_line() --- src/core/Buffer-Iterator.cc | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/core/Buffer-Iterator.cc b/src/core/Buffer-Iterator.cc index bb5fee7..23ff99f 100644 --- a/src/core/Buffer-Iterator.cc +++ b/src/core/Buffer-Iterator.cc @@ -152,18 +152,18 @@ bool Buffer::Iterator::go_right_in_line(bool allow_eol) bool Buffer::Iterator::go_previous_line() { - uint_fast8_t eol_count = 0u; Iterator i2 = *this; i2.go_back(); - size_t new_offset = 0u; - while (i2.valid() && ((*i2 != '\n') || (++eol_count < 2u))) + while (i2.valid() && (*i2 != '\n')) { - new_offset = i2.m_offset; i2.go_back(); } - if (eol_count == 2u) + i2.go_back(); + if (i2.valid()) { - m_offset = new_offset; + m_line--; + m_offset = i2.m_offset; + go_start_of_line(); return true; } return false; @@ -172,14 +172,12 @@ bool Buffer::Iterator::go_previous_line() bool Buffer::Iterator::go_next_line() { Iterator i2 = *this; - while (i2.valid() && (*i2 != '\n')) - { - i2.go_forward(); - } + i2.go_end_of_line(true); i2.go_forward(); if (i2.valid()) { - *this = i2; + m_line++; + m_offset = i2.m_offset; return true; } return false;