1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-15 09:17:22 +03:00

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)
{
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;
if (not use_tabs)
padstr = String{ ' ', maxcol - lastcol };
padstr = String{ ' ', inscount };
else
{
auto inscol = get_column(buffer, tabstop, insert_coord);
auto targetcol = maxcol - (lastcol - inscol);
auto tabcol = inscol - (inscol % tabstop);
auto tabs = (targetcol - tabcol) / tabstop;
auto spaces = targetcol - (tabs ? (tabcol + tabs * tabstop) : inscol);
ColumnCount inscol = get_column(buffer, tabstop, insert_coord);
ColumnCount targetcol = inscol + inscount;
ColumnCount tabcol = inscol - (inscol % tabstop);
CharCount tabs = (int)((targetcol - tabcol) / tabstop);
CharCount spaces = (int)(targetcol - (tabs ? (tabcol + (int)tabs * tabstop) : inscol));
padstr = String{ '\t', tabs } + String{ ' ', spaces };
}
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