Make optional whether go_right() allows going to EOL

This commit is contained in:
josh committed 2016-11-06 14:39:34 -05:00
1 parent 8d19b23597
commit 07eca3268c
2 files changed
+26 -11

No files matched your search

+24 -6
View File
@@ -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)
+2 -5
View File
@@ -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)