Skip to content

Commit 54adfa1

Browse files
authored
Merge pull request #24 from Koihik/fix-indent-use-tab
fix: incorrect indent when use tab
2 parents c068f4c + 2b75fe0 commit 54adfa1

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/Config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Config::Config() {
1212
map_["column_limit"] = "80";
1313
map_["indent_width"] = "4";
1414
map_["use_tab"] = "false";
15+
map_["tab_width"] = "4";
1516
map_["continuation_indent_width"] = "4";
1617

1718
map_["keep_simple_block_one_line"] = "true";

src/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Config {
2626
BIND_INT(column_limit);
2727
BIND_INT(indent_width);
2828
BIND_BOOL(use_tab);
29+
BIND_INT(tab_width);
2930
BIND_INT(continuation_indent_width);
3031

3132
BIND_BOOL(keep_simple_block_one_line);

src/FormatVisitor.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,10 +1616,16 @@ string FormatVisitor::indent() {
16161616

16171617
string FormatVisitor::indentWithAlign() {
16181618
stringstream ss;
1619-
for (int i = 0; i < indent_ + indentForAlign_; i++) {
1620-
if (config_.use_tab()) {
1619+
if (config_.use_tab()) {
1620+
int indent = indent_;
1621+
int tabWidth = config_.tab_width();
1622+
indent += indentForAlign_ / tabWidth;
1623+
if (indentForAlign_ % tabWidth) indent++;
1624+
for (int i = 0; i < indent; i++) {
16211625
ss << "\t";
1622-
} else {
1626+
}
1627+
} else {
1628+
for (int i = 0; i < indent_ + indentForAlign_; i++) {
16231629
ss << " ";
16241630
}
16251631
}

0 commit comments

Comments
 (0)