From 12f2815159f52d37e4ed6adef2580d9fd240b350 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 21 Sep 2016 13:36:11 +0100 Subject: [PATCH] Tweak Buffer::offset_coord implementation --- src/buffer.cc | 5 ++--- 1 file 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)