summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-09-24 18:52:54 +0100
committerMaxime Coste <frrrwww@gmail.com>2016-10-01 13:45:00 +0100
commit28cfd0bb61f5c60279358a7e58d5b6f68a1255f1 (patch)
tree2b7e1c91f2d061420f55a4db61cf72e1286a7d87 /src
parent35559b65ddf107fea2a4dda92fcbd664986976d9 (diff)
Fix get_column function and add some unit tests for fullwidth text
Diffstat (limited to 'src')
-rw-r--r--src/buffer_utils.cc18
-rw-r--r--src/highlighters.cc6
2 files changed, 16 insertions, 8 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());
}
diff --git a/src/highlighters.cc b/src/highlighters.cc
index 2ee019a4..13bbbdc5 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -648,7 +648,7 @@ HighlighterAndId create_column_highlighter(HighlighterParameters params)
void expand_tabulations(const Context& context, HighlightFlags flags, DisplayBuffer& display_buffer, BufferRange)
{
- const int tabstop = context.options()["tabstop"].get<int>();
+ const ColumnCount tabstop = context.options()["tabstop"].get<int>();
auto& buffer = context.buffer();
for (auto& line : display_buffer.lines())
{
@@ -668,8 +668,8 @@ void expand_tabulations(const Context& context, HighlightFlags flags, DisplayBuf
if (it+1 != end)
atom_it = line.split(atom_it, (it+1).coord());
- int column = (int)get_column(buffer, tabstop, it.coord());
- int count = tabstop - (column % tabstop);
+ ColumnCount column = get_column(buffer, tabstop, it.coord());
+ ColumnCount count = tabstop - (column % tabstop);
String padding;
for (int i = 0; i < count; ++i)
padding += ' ';