Fix adapt_view_pos when the cursor is not on a display atom by itself

This commit is contained in:
Maxime Coste 2014-01-21 18:52:51 +00:00
parent 2cbb0bb27f
commit 4f4a626754
2 changed files with 21 additions and 5 deletions

View File

@ -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);

View File

@ -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();
}