summaryrefslogtreecommitdiff
path: root/src/display_buffer.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-06-28 00:03:11 +0200
committerMaxime Coste <frrrwww@gmail.com>2013-06-28 00:03:11 +0200
commite510bf8b9655da59171899604c3d10955144ac0d (patch)
tree9b431687aa7cb910ba9bfa14714a7a70f58bac91 /src/display_buffer.cc
parent5b4ef23b9d8fcc516b90690a12e8403a17364ccc (diff)
Fix horizontal scrolling support with replaced buffer ranges
tab character were not properly handled when scrolling horizontally
Diffstat (limited to 'src/display_buffer.cc')
-rw-r--r--src/display_buffer.cc49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/display_buffer.cc b/src/display_buffer.cc
index c656410c..7e42c2b0 100644
--- a/src/display_buffer.cc
+++ b/src/display_buffer.cc
@@ -5,6 +5,24 @@
namespace Kakoune
{
+void AtomContent::trim_begin(CharCount count)
+{
+ if (m_type == BufferRange)
+ m_begin = utf8::advance(m_buffer->iterator_at(m_begin),
+ m_buffer->iterator_at(m_end), count).coord();
+ else
+ m_text = m_text.substr(count);
+}
+
+void AtomContent::trim_end(CharCount count)
+{
+ if (m_type == BufferRange)
+ m_end = utf8::advance(m_buffer->iterator_at(m_end),
+ m_buffer->iterator_at(m_begin), -count).coord();
+ else
+ m_text = m_text.substr(0, m_text.char_length() - count);
+}
+
DisplayLine::iterator DisplayLine::split(iterator it, BufferCoord pos)
{
kak_assert(it->content.type() == AtomContent::BufferRange);
@@ -65,6 +83,37 @@ CharCount DisplayLine::length() const
return len;
}
+void DisplayLine::trim(CharCount first_char, CharCount char_count)
+{
+ for (auto it = begin(); first_char > 0 and it != end(); )
+ {
+ if (not it->content.has_buffer_range())
+ {
+ ++it;
+ continue;
+ }
+
+ auto len = it->content.length();
+ if (len <= first_char)
+ {
+ m_atoms.erase(it);
+ first_char -= len;
+ }
+ else
+ {
+ it->content.trim_begin(first_char);
+ first_char = 0;
+ }
+ }
+ auto it = begin();
+ for (; it != end() and char_count > 0; ++it)
+ char_count -= it->content.length();
+
+ if (char_count < 0)
+ (it-1)->content.trim_end(-char_count);
+ m_atoms.erase(it, end());
+}
+
void DisplayBuffer::compute_range()
{
m_range.first = {INT_MAX,INT_MAX};