Add a char_length(Buffer&, const ByteCoord&, const ByteCoord&) util

This commit is contained in:
Maxime Coste 2016-07-28 09:41:47 +01:00
parent 74c3f101cd
commit a7005ec74b
3 changed files with 10 additions and 7 deletions

View File

@ -31,6 +31,11 @@ inline CharCount char_length(const Buffer& buffer, const Selection& range)
buffer.iterator_at(buffer.char_next(range.max()))); buffer.iterator_at(buffer.char_next(range.max())));
} }
inline CharCount char_length(const Buffer& buffer, const ByteCoord& begin, const ByteCoord& end)
{
return utf8::distance(buffer.iterator_at(begin), buffer.iterator_at(end));
}
inline bool is_bol(ByteCoord coord) inline bool is_bol(ByteCoord coord)
{ {
return coord.column == 0; return coord.column == 0;

View File

@ -2,6 +2,7 @@
#include "assert.hh" #include "assert.hh"
#include "buffer.hh" #include "buffer.hh"
#include "buffer_utils.hh"
#include "utf8.hh" #include "utf8.hh"
#include "face_registry.hh" #include "face_registry.hh"
@ -62,8 +63,7 @@ CharCount DisplayAtom::length() const
switch (m_type) switch (m_type)
{ {
case BufferRange: case BufferRange:
return utf8::distance(m_buffer->iterator_at(m_range.begin), return char_length(*m_buffer, m_range.begin, m_range.end);
m_buffer->iterator_at(m_range.end));
case Text: case Text:
case ReplacedBufferRange: case ReplacedBufferRange:
return m_text.char_length(); return m_text.char_length();

View File

@ -200,9 +200,8 @@ static CharCount adapt_view_pos(const DisplayBuffer& display_buffer, CharCount o
if (atom.type() == DisplayAtom::BufferRange) if (atom.type() == DisplayAtom::BufferRange)
{ {
auto& buf = atom.buffer(); auto& buf = atom.buffer();
pos_beg = buffer_column pos_beg = buffer_column +
+ utf8::distance(buf.iterator_at(atom.begin()), char_length(buf, atom.begin(), pos);
buf.iterator_at(pos));
pos_end = pos_beg+1; pos_end = pos_beg+1;
} }
else else
@ -273,8 +272,7 @@ CharCount find_display_column(const DisplayLine& line, const Buffer& buffer,
coord >= atom.begin() and coord < atom.end()) coord >= atom.begin() and coord < atom.end())
{ {
if (atom.type() == DisplayAtom::BufferRange) if (atom.type() == DisplayAtom::BufferRange)
column += utf8::distance(buffer.iterator_at(atom.begin()), column += char_length(buffer, atom.begin(), coord);
buffer.iterator_at(coord));
return column; return column;
} }
column += atom.length(); column += atom.length();