Skip to content

Commit 77ba5e8

Browse files
committed
Fix crash on trying to index selection when there is no regions
In some cases view.sel() is an empty list so don't try to blindly access first region set. Resolves #123
1 parent e9a3b1d commit 77ba5e8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

trailing_spaces.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ def is_find_results(view):
8585
# Returns both the list of regions which map to trailing spaces and the list of
8686
# regions which are to be highlighted, as a list [matched, highlightable].
8787
def find_trailing_spaces(view):
88-
sel = view.sel()[0]
89-
line = view.line(sel.b)
9088
include_empty_lines = bool(ts_settings.get("trailing_spaces_include_empty_lines",
9189
DEFAULT_IS_ENABLED))
9290
include_current_line = bool(ts_settings.get("trailing_spaces_include_current_line",
@@ -96,7 +94,10 @@ def find_trailing_spaces(view):
9694

9795
offending_lines = view.find_all(regexp if include_empty_lines else no_empty_lines_regexp)
9896

99-
if include_current_line:
97+
sel = view.sel()
98+
line = len(sel) and view.line(sel[0].b)
99+
100+
if include_current_line or not line:
100101
return [offending_lines, offending_lines]
101102
else:
102103
current_offender = view.find(regexp if include_empty_lines else no_empty_lines_regexp, line.a)

0 commit comments

Comments
 (0)