27
27
startup_queue = []
28
28
on_disk = None
29
29
30
+ # NOTE: these are for trailing_spaces_unhilight_editing_line
31
+ currently_modifying = {}
32
+ last_modified_selection = {}
30
33
31
34
# Private: Loads settings and sets whether the plugin (live matching) is enabled.
32
35
#
@@ -87,18 +90,26 @@ def find_trailing_spaces(view):
87
90
DEFAULT_IS_ENABLED ))
88
91
include_current_line = bool (ts_settings .get ("trailing_spaces_include_current_line" ,
89
92
DEFAULT_IS_ENABLED ))
93
+ unhilight_editing_line = bool (ts_settings .get ("trailing_spaces_unhilight_editing_line" ,
94
+ False ))
95
+
90
96
regexp = ts_settings .get ("trailing_spaces_regexp" ) + "$"
91
97
no_empty_lines_regexp = "(?<=\S)%s$" % regexp
92
98
93
99
offending_lines = view .find_all (regexp if include_empty_lines else no_empty_lines_regexp )
100
+ highlightable = offending_lines
94
101
95
- if include_current_line :
96
- return [offending_lines , offending_lines ]
97
- else :
102
+ if include_current_line and unhilight_editing_line :
103
+ # remove current line(s) from hilightings if editing
104
+ highlightable = [region for region in highlightable if
105
+ view .rowcol (region .a )[0 ] not in currently_modifying [view .buffer_id ()]]
106
+
107
+ elif not include_current_line :
98
108
current_offender = view .find (regexp if include_empty_lines else no_empty_lines_regexp , line .a )
99
109
removal = False if current_offender == None else line .intersects (current_offender )
100
110
highlightable = [i for i in offending_lines if i != current_offender ] if removal else offending_lines
101
- return [offending_lines , highlightable ]
111
+
112
+ return [offending_lines , highlightable ]
102
113
103
114
104
115
# Private: Find the fraking trailing spaces in the view and flags them as such!
@@ -380,6 +391,9 @@ def is_checked(self):
380
391
# current settings.
381
392
class TrailingSpacesListener (sublime_plugin .EventListener ):
382
393
def on_modified (self , view ):
394
+ last_modified_selection [view .buffer_id ()] = [s for s in view .sel ()]
395
+ currently_modifying [view .buffer_id ()] = [view .rowcol (pos .a )[0 ] for pos in view .sel ()]
396
+
383
397
if trailing_spaces_live_matching :
384
398
match_trailing_spaces (view )
385
399
@@ -388,10 +402,17 @@ def on_activated(self, view):
388
402
match_trailing_spaces (view )
389
403
390
404
def on_selection_modified (self , view ):
405
+ # reset currently modifying lines if cursor changed place ("exit edit mode")
406
+ if [s for s in view .sel ()] != last_modified_selection [view .buffer_id ()]:
407
+ currently_modifying [view .buffer_id ()] = set ()
391
408
if trailing_spaces_live_matching :
392
409
match_trailing_spaces (view )
393
410
394
411
def on_activated (self , view ):
412
+ # initialize current buffer's important sets
413
+ currently_modifying [view .buffer_id ()] = set ()
414
+ last_modified_selection [view .buffer_id ()] = set ()
415
+
395
416
self .freeze_last_version (view )
396
417
if trailing_spaces_live_matching :
397
418
match_trailing_spaces (view )
0 commit comments