15
15
'punctuation.section.group.end.cfml'
16
16
]
17
17
18
- non_indent_regions = [
19
- 'embedding.cfml -source.cfml.script' ,
18
+ non_script_selector = 'embedding.cfml -source.cfml.script'
19
+
20
+ non_indent_selector = [
20
21
'comment.block.cfml -punctuation.definition.comment.cfml' ,
21
22
'meta.string -punctuation.definition.string.begin'
22
23
]
@@ -29,11 +30,18 @@ def indent_region(cfml_format):
29
30
end_indent_selector = ',' .join (end_indent_selectors )
30
31
accessor_selector = 'punctuation.accessor.cfml'
31
32
32
- non_cfscript_regions = cfml_format .view .find_by_selector (',' .join (non_indent_regions ))
33
- non_cfscript_lines = []
33
+ non_cfscript_regions = cfml_format .view .find_by_selector (non_script_selector )
34
+ non_indent_regions = cfml_format .view .find_by_selector (',' .join (non_indent_selector ))
35
+ non_cfscript_line_starts = set ()
36
+ non_indent_line_starts = set ()
37
+
34
38
for r in non_cfscript_regions :
35
- non_cfscript_lines .extend (cfml_format .view .split_by_newlines (r ))
36
- non_cfscript_line_starts = [r .begin () for r in non_cfscript_lines ]
39
+ for l in cfml_format .view .split_by_newlines (r ):
40
+ non_cfscript_line_starts .add (l .begin ())
41
+
42
+ for r in non_indent_regions :
43
+ for l in cfml_format .view .split_by_newlines (r ):
44
+ non_indent_line_starts .add (l .begin ())
37
45
38
46
lines = cfml_format .view .lines (cfml_format .region_to_format )
39
47
base_indent_column = cfml_format .line_indent_column (lines [0 ].begin ())
@@ -52,13 +60,19 @@ def indent_region(cfml_format):
52
60
indent_level += 1
53
61
lines = lines [1 :]
54
62
55
- if lines [- 1 ].end () > cfml_format .region_to_format .end ():
63
+ if len ( lines ) > 0 and lines [- 1 ].end () > cfml_format .region_to_format .end ():
56
64
lines = lines [:- 1 ]
57
65
66
+ if len (lines ) == 0 :
67
+ return []
68
+
58
69
for l in lines :
59
70
full_line_str = cfml_format .view .substr (l )
60
71
stripped_line_str = full_line_str .strip ()
61
72
73
+ if l .begin () in non_cfscript_line_starts :
74
+ base_indent_column = cfml_format .line_indent_column (l .begin ())
75
+
62
76
if len (stripped_line_str ) == 0 :
63
77
replacements .append (stripped_line_str )
64
78
continue
@@ -103,7 +117,7 @@ def indent_region(cfml_format):
103
117
104
118
indented_line = cfml_format .indent_to_column (indent_columns ) + stripped_line_str
105
119
106
- if l .begin () in non_cfscript_line_starts :
120
+ if l .begin () in non_cfscript_line_starts or l . begin () in non_indent_line_starts :
107
121
replacements .append (full_line_str )
108
122
else :
109
123
replacements .append (indented_line )
0 commit comments