diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2014-01-21 18:52:51 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2014-01-21 18:52:51 +0000 |
| commit | 4f4a626754b3c3ed9a8f9989c8d43906f9efd7ab (patch) | |
| tree | ff402c8a7c39d006d88452924db610807caa330d /src | |
| parent | 2cbb0bb27f926701f2522c1a10e411e5c9181b4b (diff) | |
Fix adapt_view_pos when the cursor is not on a display atom by itself
Diffstat (limited to 'src')
| -rw-r--r-- | src/display_buffer.hh | 2 | ||||
| -rw-r--r-- | src/window.cc | 26 |
2 files changed, 22 insertions, 6 deletions
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; - - 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; + 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(); + } + + 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(); } |
