diff options
Diffstat (limited to 'src/display_buffer.cc')
| -rw-r--r-- | src/display_buffer.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/display_buffer.cc b/src/display_buffer.cc index af8d15e4..a56fe612 100644 --- a/src/display_buffer.cc +++ b/src/display_buffer.cc @@ -1,10 +1,48 @@ #include "display_buffer.hh" #include "assert.hh" +#include "buffer.hh" +#include "utf8.hh" namespace Kakoune { +StringView DisplayAtom::content() const +{ + switch (m_type) + { + case BufferRange: + { + auto line = (*m_buffer)[m_begin.line]; + if (m_begin.line == m_end.line) + return line.substr(m_begin.column, m_end.column - m_begin.column); + else if (m_begin.line+1 == m_end.line and m_end.column == 0) + return line.substr(m_begin.column); + break; + } + case Text: + case ReplacedBufferRange: + return m_text; + } + kak_assert(false); + return {}; +} + +CharCount DisplayAtom::length() const +{ + switch (m_type) + { + case BufferRange: + return utf8::distance(m_buffer->iterator_at(m_begin), + m_buffer->iterator_at(m_end)); + case Text: + case ReplacedBufferRange: + return m_text.char_length(); + } + kak_assert(false); + return 0; +} + void DisplayAtom::trim_begin(CharCount count) { if (m_type == BufferRange) |
