summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-06-15 18:12:21 +0100
committerMaxime Coste <mawww@kakoune.org>2017-06-15 18:12:21 +0100
commit4ed790632d3a8a0901145df99bac5e0a9afa22d4 (patch)
treea8b7340915aadcadd46084d46c1a7fce42843b21 /src
parentfa4b88c2f8556ad736dab3af3629715ba41cf3bc (diff)
Fix some other uses of invalid buffer coordinates in display code
Diffstat (limited to 'src')
-rw-r--r--src/display_buffer.cc19
-rw-r--r--src/display_buffer.hh4
-rw-r--r--src/highlighters.cc9
3 files changed, 18 insertions, 14 deletions
diff --git a/src/display_buffer.cc b/src/display_buffer.cc
index 4b025fc9..d9771327 100644
--- a/src/display_buffer.cc
+++ b/src/display_buffer.cc
@@ -10,6 +10,14 @@
namespace Kakoune
{
+BufferIterator get_iterator(const Buffer& buffer, BufferCoord coord)
+{
+ // Correct one past the end of line as next line
+ if (not buffer.is_end(coord) and coord.column == buffer[coord.line].length())
+ coord = coord.line+1;
+ return buffer.iterator_at(coord);
+}
+
StringView DisplayAtom::content() const
{
switch (m_type)
@@ -36,7 +44,8 @@ ColumnCount DisplayAtom::length() const
switch (m_type)
{
case Range:
- return column_length(*m_buffer, m_range.begin, m_range.end);
+ return utf8::column_distance(get_iterator(*m_buffer, m_range.begin),
+ get_iterator(*m_buffer, m_range.end));
case Text:
case ReplacedRange:
return m_text.column_length();
@@ -48,8 +57,8 @@ ColumnCount DisplayAtom::length() const
void DisplayAtom::trim_begin(ColumnCount count)
{
if (m_type == Range)
- m_range.begin = utf8::advance(m_buffer->iterator_at(m_range.begin),
- m_buffer->iterator_at(m_range.end),
+ m_range.begin = utf8::advance(get_iterator(*m_buffer, m_range.begin),
+ get_iterator(*m_buffer, m_range.end),
count).coord();
else
m_text = m_text.substr(count).str();
@@ -58,8 +67,8 @@ void DisplayAtom::trim_begin(ColumnCount count)
void DisplayAtom::trim_end(ColumnCount count)
{
if (m_type == Range)
- m_range.end = utf8::advance(m_buffer->iterator_at(m_range.end),
- m_buffer->iterator_at(m_range.begin),
+ m_range.end = utf8::advance(get_iterator(*m_buffer, m_range.end),
+ get_iterator(*m_buffer, m_range.begin),
-count).coord();
else
m_text = m_text.substr(0, m_text.column_length() - count).str();
diff --git a/src/display_buffer.hh b/src/display_buffer.hh
index e3c58516..1215d76d 100644
--- a/src/display_buffer.hh
+++ b/src/display_buffer.hh
@@ -25,6 +25,10 @@ size_t hash_value(const BufferRange& range)
return hash_values(range.begin, range.end);
}
+class BufferIterator;
+// Return a buffer iterator to the coord, tolerating one past end of line coords
+BufferIterator get_iterator(const Buffer& buffer, BufferCoord coord);
+
struct DisplayAtom : public UseMemoryDomain<MemoryDomain::Display>
{
public:
diff --git a/src/highlighters.cc b/src/highlighters.cc
index 9a72e71a..6e5859fd 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -25,15 +25,6 @@
namespace Kakoune
{
-BufferIterator get_iterator(const Buffer& buffer, BufferCoord coord)
-{
- // Correct one past the end of line as next line
- if (not buffer.is_end(coord) and coord.column == buffer[coord.line].length())
- coord = coord.line+1;
- return buffer.iterator_at(coord);
-}
-
-
template<typename Func>
std::unique_ptr<Highlighter> make_highlighter(Func func, HighlightPass pass = HighlightPass::Colorize)
{