diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-09-21 13:36:11 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-09-21 13:36:11 +0100 |
| commit | 12f2815159f52d37e4ed6adef2580d9fd240b350 (patch) | |
| tree | 4a68a843883aed11328ed5acaad1356372ca60d0 /src/buffer.cc | |
| parent | 4f874a3679eebc549d7f26382add098d5a6b6cdc (diff) | |
Tweak Buffer::offset_coord implementation
Diffstat (limited to 'src/buffer.cc')
| -rw-r--r-- | src/buffer.cc | 5 |
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) |
