@@ -2883,6 +2883,7 @@ impl BufferSnapshot {
2883
2883
while let Some ( mat) = matches. peek ( ) {
2884
2884
let mut start: Option < Point > = None ;
2885
2885
let mut end: Option < Point > = None ;
2886
+ let mut outdent: Option < Point > = None ;
2886
2887
2887
2888
let config = & indent_configs[ mat. grammar_index ] ;
2888
2889
for capture in mat. captures {
@@ -2894,11 +2895,19 @@ impl BufferSnapshot {
2894
2895
} else if Some ( capture. index ) == config. end_capture_ix {
2895
2896
end = Some ( Point :: from_ts_point ( capture. node . start_position ( ) ) ) ;
2896
2897
} else if Some ( capture. index ) == config. outdent_capture_ix {
2897
- outdent_positions. push ( Point :: from_ts_point ( capture. node . start_position ( ) ) ) ;
2898
+ let point = Point :: from_ts_point ( capture. node . start_position ( ) ) ;
2899
+ outdent. get_or_insert ( point) ;
2900
+ outdent_positions. push ( point) ;
2898
2901
}
2899
2902
}
2900
2903
2901
2904
matches. advance ( ) ;
2905
+ // in case of significant indentation expand end to outdent position
2906
+ let end = if significant_indentation {
2907
+ outdent. or ( end)
2908
+ } else {
2909
+ end
2910
+ } ;
2902
2911
if let Some ( ( start, end) ) = start. zip ( end) {
2903
2912
if start. row == end. row && !significant_indentation {
2904
2913
continue ;
@@ -2938,16 +2947,20 @@ impl BufferSnapshot {
2938
2947
matches. advance ( ) ;
2939
2948
}
2940
2949
2941
- outdent_positions. sort ( ) ;
2942
- for outdent_position in outdent_positions {
2943
- // find the innermost indent range containing this outdent_position
2944
- // set its end to the outdent position
2945
- if let Some ( range_to_truncate) = indent_ranges
2946
- . iter_mut ( )
2947
- . filter ( |indent_range| indent_range. contains ( & outdent_position) )
2948
- . next_back ( )
2949
- {
2950
- range_to_truncate. end = outdent_position;
2950
+ // we don't use outdent positions to truncate in case of significant indentation
2951
+ // rather we use them to expand (handled above)
2952
+ if !significant_indentation {
2953
+ outdent_positions. sort ( ) ;
2954
+ for outdent_position in outdent_positions {
2955
+ // find the innermost indent range containing this outdent_position
2956
+ // set its end to the outdent position
2957
+ if let Some ( range_to_truncate) = indent_ranges
2958
+ . iter_mut ( )
2959
+ . filter ( |indent_range| indent_range. contains ( & outdent_position) )
2960
+ . next_back ( )
2961
+ {
2962
+ range_to_truncate. end = outdent_position;
2963
+ }
2951
2964
}
2952
2965
}
2953
2966
@@ -3011,23 +3024,17 @@ impl BufferSnapshot {
3011
3024
}
3012
3025
3013
3026
for range in & indent_ranges {
3014
- if significant_indentation {
3015
- if range. start . row > row {
3016
- break ;
3017
- }
3018
- if range. start == row_start {
3019
- indent_from_prev_row = true ;
3020
- }
3021
- if range. end > prev_row_start && range. end <= row_start {
3022
- outdent_to_row = outdent_to_row. min ( range. start . row . saturating_sub ( 1 ) ) ;
3023
- }
3024
- } else {
3025
- if range. start . row >= row {
3026
- break ;
3027
- }
3028
- if range. start . row == prev_row && range. end > row_start {
3029
- indent_from_prev_row = true ;
3030
- }
3027
+ if range. start . row >= row {
3028
+ break ;
3029
+ }
3030
+ if range. start . row == prev_row && range. end > row_start {
3031
+ indent_from_prev_row = true ;
3032
+ }
3033
+ if significant_indentation && self . is_line_blank ( row) && range. start . row == prev_row
3034
+ {
3035
+ indent_from_prev_row = true ;
3036
+ }
3037
+ if !significant_indentation || !self . is_line_blank ( row) {
3031
3038
if range. end > prev_row_start && range. end <= row_start {
3032
3039
outdent_to_row = outdent_to_row. min ( range. start . row ) ;
3033
3040
}
@@ -3038,8 +3045,8 @@ impl BufferSnapshot {
3038
3045
. iter ( )
3039
3046
. any ( |e| e. start . row < row && e. end > row_start) ;
3040
3047
3041
- let suggestion = if !significant_indentation
3042
- && ( outdent_to_row == prev_row || ( outdent_from_prev_row && indent_from_prev_row) )
3048
+ let suggestion = if outdent_to_row == prev_row
3049
+ || ( outdent_from_prev_row && indent_from_prev_row)
3043
3050
{
3044
3051
Some ( IndentSuggestion {
3045
3052
basis_row : prev_row,
0 commit comments