diff --git a/src/normal.cc b/src/normal.cc index 43c84c38..921bb000 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -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)); diff --git a/test/unit/align-tab/cmd b/test/unit/align-tab/cmd new file mode 100644 index 00000000..4bd7e7a4 --- /dev/null +++ b/test/unit/align-tab/cmd @@ -0,0 +1 @@ +& diff --git a/test/unit/align-tab/in b/test/unit/align-tab/in new file mode 100644 index 00000000..ea03b5e9 --- /dev/null +++ b/test/unit/align-tab/in @@ -0,0 +1,2 @@ + if (%(v)alid) + %(x) diff --git a/test/unit/align-tab/out b/test/unit/align-tab/out new file mode 100644 index 00000000..907c682e --- /dev/null +++ b/test/unit/align-tab/out @@ -0,0 +1,2 @@ + if (valid) + x diff --git a/test/unit/align-tab/rc b/test/unit/align-tab/rc new file mode 100644 index 00000000..6ee193bb --- /dev/null +++ b/test/unit/align-tab/rc @@ -0,0 +1,2 @@ +set buffer tabstop 4 +set buffer aligntab true