diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-09-24 18:52:54 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-10-01 13:45:00 +0100 |
| commit | 28cfd0bb61f5c60279358a7e58d5b6f68a1255f1 (patch) | |
| tree | 2b7e1c91f2d061420f55a4db61cf72e1286a7d87 /src/buffer_utils.cc | |
| parent | 35559b65ddf107fea2a4dda92fcbd664986976d9 (diff) | |
Fix get_column function and add some unit tests for fullwidth text
Diffstat (limited to 'src/buffer_utils.cc')
| -rw-r--r-- | src/buffer_utils.cc | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc index 20d24118..ff018096 100644 --- a/src/buffer_utils.cc +++ b/src/buffer_utils.cc @@ -18,13 +18,15 @@ ColumnCount get_column(const Buffer& buffer, auto line = buffer[coord.line]; auto col = 0_col; for (auto it = line.begin(); - it != line.end() and coord.column > (int)(it - line.begin()); - it = utf8::next(it, line.end())) + it != line.end() and coord.column > (int)(it - line.begin()); ) { if (*it == '\t') + { col = (col / tabstop + 1) * tabstop; + ++it; + } else - ++col; + col += get_width(utf8::read_codepoint(it, line.end())); } return col; } @@ -41,10 +43,16 @@ ByteCount get_byte_to_column(const Buffer& buffer, ColumnCount tabstop, DisplayC col = (col / tabstop + 1) * tabstop; if (col > coord.column) // the target column was in the tab break; + ++it; } else - ++col; - it = utf8::next(it, line.end()); + { + auto next = it; + col += get_width(utf8::read_codepoint(next, line.end())); + if (col > coord.column) // the target column was in the char + break; + it = next; + } } return (int)(it - line.begin()); } |
