fix Buffer::Iterator::go_previous_line() and go_next_line()

This commit is contained in:
Josh Holtrop 2016-12-21 22:10:58 -05:00
parent 8c834c9d7c
commit 4ad5615dff

View File

@ -152,18 +152,18 @@ bool Buffer::Iterator::go_right_in_line(bool allow_eol)
bool Buffer::Iterator::go_previous_line() bool Buffer::Iterator::go_previous_line()
{ {
uint_fast8_t eol_count = 0u;
Iterator i2 = *this; Iterator i2 = *this;
i2.go_back(); i2.go_back();
size_t new_offset = 0u; while (i2.valid() && (*i2 != '\n'))
while (i2.valid() && ((*i2 != '\n') || (++eol_count < 2u)))
{ {
new_offset = i2.m_offset;
i2.go_back(); 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 true;
} }
return false; return false;
@ -172,14 +172,12 @@ bool Buffer::Iterator::go_previous_line()
bool Buffer::Iterator::go_next_line() bool Buffer::Iterator::go_next_line()
{ {
Iterator i2 = *this; Iterator i2 = *this;
while (i2.valid() && (*i2 != '\n')) i2.go_end_of_line(true);
{
i2.go_forward();
}
i2.go_forward(); i2.go_forward();
if (i2.valid()) if (i2.valid())
{ {
*this = i2; m_line++;
m_offset = i2.m_offset;
return true; return true;
} }
return false; return false;