Fix get_column function and add some unit tests for fullwidth text
This commit is contained in:
parent
35559b65dd
commit
28cfd0bb61
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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 += ' ';
|
||||
|
|
1
test/unit/codepoint-width/tab-width/cmd
Normal file
1
test/unit/codepoint-width/tab-width/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
j
|
2
test/unit/codepoint-width/tab-width/in
Normal file
2
test/unit/codepoint-width/tab-width/in
Normal file
|
@ -0,0 +1,2 @@
|
|||
一 %(二)
|
||||
1234567890
|
1
test/unit/codepoint-width/tab-width/selections
Normal file
1
test/unit/codepoint-width/tab-width/selections
Normal file
|
@ -0,0 +1 @@
|
|||
9
|
1
test/unit/codepoint-width/vertical-movement/cmd
Normal file
1
test/unit/codepoint-width/vertical-movement/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
k
|
2
test/unit/codepoint-width/vertical-movement/in
Normal file
2
test/unit/codepoint-width/vertical-movement/in
Normal file
|
@ -0,0 +1,2 @@
|
|||
123456789012
|
||||
一%(二)三%(四)五六
|
1
test/unit/codepoint-width/vertical-movement/selections
Normal file
1
test/unit/codepoint-width/vertical-movement/selections
Normal file
|
@ -0,0 +1 @@
|
|||
3:7
|
Loading…
Reference in New Issue
Block a user