Skip to content

Commit

Permalink
Simplify indentation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
WGUNDERWOOD committed Oct 24, 2024
1 parent fb5e9bf commit 9f2e143
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/indent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ fn get_diff(line: &str, pattern: &Pattern) -> i8 {
fn get_back(line: &str, pattern: &Pattern) -> i8 {
let mut back: i8 = 0;

// other environments get single indents
if pattern.contains_env_end && line.contains(ENV_END) {
// documents get no global indentation
if line.contains(DOC_END) {
Expand All @@ -79,25 +78,23 @@ fn get_back(line: &str, pattern: &Pattern) -> i8 {
return 2;
};
}
back += 1;
// other environments get single indents
back = 1;
};

// Dedent delimiters
// Check first whether there are any closing delimiters
if CLOSES.iter().any(|c| line.contains(*c)) {
let mut cumul: i8 = back;
for c in line.chars() {
cumul -= i8::from(OPENS.contains(&c));
cumul += i8::from(CLOSES.contains(&c));
back = max(cumul, back);
}
}

// deindent items to make the rest of item environment appear indented
if pattern.contains_item && line.contains(ITEM) {
back += 1;
};

// Dedent delimiters
let mut cumul: i8 = back;
for c in line.chars() {
cumul -= i8::from(OPENS.contains(&c));
cumul += i8::from(CLOSES.contains(&c));
back = max(cumul, back);
}

back
}

Expand Down

0 comments on commit 9f2e143

Please sign in to comment.