summaryrefslogtreecommitdiff
path: root/src/buffer.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-09-21 13:36:11 +0100
committerMaxime Coste <frrrwww@gmail.com>2016-09-21 13:36:11 +0100
commit12f2815159f52d37e4ed6adef2580d9fd240b350 (patch)
tree4a68a843883aed11328ed5acaad1356372ca60d0 /src/buffer.cc
parent4f874a3679eebc549d7f26382add098d5a6b6cdc (diff)
Tweak Buffer::offset_coord implementation
Diffstat (limited to 'src/buffer.cc')
-rw-r--r--src/buffer.cc5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index d89e29c6..8747ec94 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -177,9 +177,8 @@ ByteCoord Buffer::clamp(ByteCoord coord) const
ByteCoord Buffer::offset_coord(ByteCoord coord, CharCount offset)
{
StringView line = m_lines[coord.line];
- auto character = std::max(0_char, std::min(line.char_count_to(coord.column) + offset,
- line.char_length() - 1));
- return {coord.line, line.byte_count_to(character)};
+ auto target = utf8::advance(&line[coord.column], offset < 0 ? line.begin() : line.end()-1, offset);
+ return {coord.line, (int)(target - line.begin())};
}
ByteCoordAndTarget Buffer::offset_coord(ByteCoordAndTarget coord, LineCount offset)