Skip to content

Commit 190e33f

Browse files
authored
Don't call add_regions if there are no regions to highlight (#148)
Shouldn't make any difference in practice but helps when debugging ST API. :)
1 parent cc19be0 commit 190e33f

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

trailing_spaces.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# Highlight color as defined in settings. Plugin mutates that setting when disabled so
3232
# that has to be stored.
3333
INITIAL_HIGHLIGHT_COLOR = None
34+
HIGHLIGHT_REGION_KEY = 'TrailingSpacesHighlightedRegions'
3435
settings = None
3536

3637

@@ -198,12 +199,9 @@ def max_size_exceeded(view):
198199
#
199200
# Returns nothing.
200201
def highlight_trailing_spaces_regions(view, regions):
201-
view.erase_regions("TrailingSpacesHighlightedRegions")
202-
view.add_regions('TrailingSpacesHighlightedRegions',
203-
regions,
204-
current_highlight_color or "",
205-
"",
206-
sublime.HIDE_ON_MINIMAP)
202+
view.erase_regions(HIGHLIGHT_REGION_KEY)
203+
if regions:
204+
view.add_regions(HIGHLIGHT_REGION_KEY, regions, current_highlight_color or "", "", sublime.HIDE_ON_MINIMAP)
207205

208206

209207
# Private: Toggles highlighting of all trailing spaces in the view.
@@ -228,7 +226,7 @@ def toggle_highlighting(view):
228226

229227
scope = INITIAL_HIGHLIGHT_COLOR if current_highlight_color == "" else ""
230228
current_highlight_color = scope
231-
highlight_trailing_spaces_regions(view, view.get_regions('TrailingSpacesHighlightedRegions'))
229+
highlight_trailing_spaces_regions(view, view.get_regions(HIGHLIGHT_REGION_KEY))
232230
return "off" if current_highlight_color == "" else "on"
233231

234232

0 commit comments

Comments
 (0)