Fix align support with aligntab = true

This commit is contained in:
Maxime Coste 2016-10-28 09:49:32 +01:00
parent 79b193d2be
commit 965cd8e0c3
5 changed files with 15 additions and 7 deletions

View File

@ -1262,17 +1262,18 @@ void align(Context& context, NormalParams)
for (auto& sel : col) for (auto& sel : col)
{ {
auto insert_coord = sel->min(); auto insert_coord = sel->min();
auto lastcol = get_column(buffer, tabstop, sel->cursor()); ColumnCount lastcol = get_column(buffer, tabstop, sel->cursor());
ColumnCount inscount = maxcol - lastcol;
String padstr; String padstr;
if (not use_tabs) if (not use_tabs)
padstr = String{ ' ', maxcol - lastcol }; padstr = String{ ' ', inscount };
else else
{ {
auto inscol = get_column(buffer, tabstop, insert_coord); ColumnCount inscol = get_column(buffer, tabstop, insert_coord);
auto targetcol = maxcol - (lastcol - inscol); ColumnCount targetcol = inscol + inscount;
auto tabcol = inscol - (inscol % tabstop); ColumnCount tabcol = inscol - (inscol % tabstop);
auto tabs = (targetcol - tabcol) / tabstop; CharCount tabs = (int)((targetcol - tabcol) / tabstop);
auto spaces = targetcol - (tabs ? (tabcol + tabs * tabstop) : inscol); CharCount spaces = (int)(targetcol - (tabs ? (tabcol + (int)tabs * tabstop) : inscol));
padstr = String{ '\t', tabs } + String{ ' ', spaces }; padstr = String{ '\t', tabs } + String{ ' ', spaces };
} }
buffer.insert(insert_coord, std::move(padstr)); buffer.insert(insert_coord, std::move(padstr));

1
test/unit/align-tab/cmd Normal file
View File

@ -0,0 +1 @@
&

2
test/unit/align-tab/in Normal file
View File

@ -0,0 +1,2 @@
if (%(v)alid)
%(x)

2
test/unit/align-tab/out Normal file
View File

@ -0,0 +1,2 @@
if (valid)
x

2
test/unit/align-tab/rc Normal file
View File

@ -0,0 +1,2 @@
set buffer tabstop 4
set buffer aligntab true