Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use 'tab_spaces' for size of hard tabs instead of hardcoded 4 #143

Merged
merged 4 commits into from
Sep 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions printer/src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,18 +358,20 @@ impl Printer {
}

fn print_indent(&mut self) {
if !self.settings.hard_tabs {
self.out.reserve(self.pending_indentation);
let (tabs, spaces) = if self.settings.hard_tabs {
// Note: we have to print the remainder in spaces, as pending_indentation represents the space of _any_ breakable token
// including break tokens with never_break set to 'true', meaning that indentation (e.g. a single space) can be printed in the middle of a line as well.
// see `print_break` for implementation details
let tabs = self.pending_indentation / self.settings.tab_spaces as usize;
let remainder = self.pending_indentation % self.settings.tab_spaces as usize;
(tabs, remainder)
} else {
let tabs = self.pending_indentation / 4;
let remaining_spaces = self.pending_indentation % 4;
self.out.reserve(tabs + remaining_spaces);
self.out.extend(iter::repeat('\t').take(tabs));
self.pending_indentation = remaining_spaces
}
(0, self.pending_indentation)
};

self.out
.extend(iter::repeat(' ').take(self.pending_indentation));
self.out.reserve(tabs + spaces);
self.out.extend(iter::repeat('\t').take(tabs));
self.out.extend(iter::repeat(' ').take(spaces));
self.pending_indentation = 0;
}
}
Loading