@@ -64,7 +64,11 @@ fn get_diff(line: &str, pattern: &Pattern) -> i8 {
64
64
}
65
65
66
66
/// Calculate dedentation for the current line
67
- fn get_back ( line : & str , pattern : & Pattern ) -> i8 {
67
+ fn get_back ( line : & str , pattern : & Pattern , state : & State ) -> i8 {
68
+ // Only need to dedent if indentation is present
69
+ if state. indent . actual == 0 {
70
+ return 0 ;
71
+ }
68
72
let mut back: i8 = 0 ;
69
73
70
74
if pattern. contains_env_end && line. contains ( ENV_END ) {
@@ -80,10 +84,8 @@ fn get_back(line: &str, pattern: &Pattern) -> i8 {
80
84
}
81
85
// other environments get single indents
82
86
back = 1 ;
83
- } ;
84
-
85
- // deindent items to make the rest of item environment appear indented
86
- if pattern. contains_item && line. contains ( ITEM ) {
87
+ } else if pattern. contains_item && line. contains ( ITEM ) {
88
+ // deindent items to make the rest of item environment appear indented
87
89
back += 1 ;
88
90
} ;
89
91
@@ -99,9 +101,9 @@ fn get_back(line: &str, pattern: &Pattern) -> i8 {
99
101
}
100
102
101
103
/// Calculate indentation properties of the current line
102
- fn get_indent ( line : & str , prev_indent : & Indent , pattern : & Pattern ) -> Indent {
104
+ fn get_indent ( line : & str , prev_indent : & Indent , pattern : & Pattern , state : & State ) -> Indent {
103
105
let diff = get_diff ( line, pattern) ;
104
- let back = get_back ( line, pattern) ;
106
+ let back = get_back ( line, pattern, state ) ;
105
107
let actual = prev_indent. actual + diff;
106
108
let visual = prev_indent. actual - back;
107
109
Indent { actual, visual }
@@ -123,7 +125,7 @@ pub fn calculate_indent(
123
125
// (if there is one) to ignore diffs from characters in there.
124
126
let comment_index = find_comment_index ( line) ;
125
127
let line_strip = remove_comment ( line, comment_index) ;
126
- let mut indent = get_indent ( line_strip, & state. indent , pattern) ;
128
+ let mut indent = get_indent ( line_strip, & state. indent , pattern, state ) ;
127
129
128
130
// Record the indent to the logs.
129
131
if args. trace {
0 commit comments