Add Buffer::Iterator functions to move forward/backward on/up to characters in a line
This commit is contained in:
1 parent
32b272b75c
commit
3c6b3bc49e
3 files changed
+113
No files matched your search
@@ -202,6 +202,80 @@ void Buffer::Iterator::warp_to_offset(size_t offset)
|
||||
}
|
||||
}
|
||||
|
||||
bool Buffer::Iterator::go_forward_in_line_up_to_char(uint32_t c)
|
||||
{
|
||||
size_t last_offset = m_offset;
|
||||
Buffer::Iterator it = *this;
|
||||
while (it.go_right_in_line(false))
|
||||
{
|
||||
if (*it == c)
|
||||
{
|
||||
if (last_offset != m_offset)
|
||||
{
|
||||
m_offset = last_offset;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
last_offset = it.m_offset;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Buffer::Iterator::go_forward_in_line_on_to_char(uint32_t c)
|
||||
{
|
||||
Buffer::Iterator it = *this;
|
||||
while (it.go_right_in_line(false))
|
||||
{
|
||||
if (*it == c)
|
||||
{
|
||||
m_offset = it.m_offset;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Buffer::Iterator::go_backward_in_line_up_to_char(uint32_t c)
|
||||
{
|
||||
size_t last_offset = m_offset;
|
||||
Buffer::Iterator it = *this;
|
||||
while (it.go_left_in_line())
|
||||
{
|
||||
if (*it == c)
|
||||
{
|
||||
if (last_offset != m_offset)
|
||||
{
|
||||
m_offset = last_offset;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
last_offset = it.m_offset;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Buffer::Iterator::go_backward_in_line_on_to_char(uint32_t c)
|
||||
{
|
||||
Buffer::Iterator it = *this;
|
||||
while (it.go_left_in_line())
|
||||
{
|
||||
if (*it == c)
|
||||
{
|
||||
m_offset = it.m_offset;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Buffer::Iterator Buffer::Iterator::prev()
|
||||
{
|
||||
Iterator i = *this;
|
||||
|
||||
@@ -49,6 +49,10 @@ public:
|
||||
bool go_right_in_line(bool allow_eol);
|
||||
bool go_previous_line();
|
||||
bool go_next_line();
|
||||
bool go_forward_in_line_up_to_char(uint32_t c);
|
||||
bool go_forward_in_line_on_to_char(uint32_t c);
|
||||
bool go_backward_in_line_up_to_char(uint32_t c);
|
||||
bool go_backward_in_line_on_to_char(uint32_t c);
|
||||
Iterator prev();
|
||||
Iterator next();
|
||||
void warp(ssize_t offset_offset, ssize_t line_offset)
|
||||
|
||||
Reference in new issue
Block a user