diff --git a/src/display_buffer.hh b/src/display_buffer.hh index f366bda9..b992654a 100644 --- a/src/display_buffer.hh +++ b/src/display_buffer.hh @@ -96,6 +96,8 @@ public: return m_type == BufferRange or m_type == ReplacedBufferRange; } + const Buffer& buffer() const { kak_assert(m_buffer); return *m_buffer; } + Type type() const { return m_type; } void trim_begin(CharCount count); diff --git a/src/window.cc b/src/window.cc index 6cc1a4dd..9762f634 100644 --- a/src/window.cc +++ b/src/window.cc @@ -129,12 +129,26 @@ static CharCount adapt_view_pos(const DisplayBuffer& display_buffer, { if (atom.begin() <= pos and atom.end() > pos) { - if (buffer_column < view_pos) - return buffer_column; + CharCount pos_beg, pos_end; + if (atom.type() == DisplayAtom::BufferRange) + { + auto& buf = atom.buffer(); + pos_beg = buffer_column + + utf8::distance(buf.iterator_at(atom.begin()), + buf.iterator_at(pos)); + pos_end = pos_beg+1; + } + else + { + pos_beg = buffer_column; + pos_end = pos_beg + atom.length(); + } - auto last_column = buffer_column + atom.length(); - if (last_column >= view_pos + view_size - non_buffer_column) - return last_column - view_size + non_buffer_column; + if (pos_beg < view_pos) + return pos_beg; + + if (pos_end >= view_pos + view_size - non_buffer_column) + return pos_end - view_size + non_buffer_column; } buffer_column += atom.length(); }