From 99c4cd4806ec5eabedf8d86bf4b7535e0ca63648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ch=C5=82odnicki?= Date: Wed, 24 Feb 2021 21:40:36 +0100 Subject: [PATCH] Don't call add_regions if there are no regions to highlight Shouldn't make any difference in practice but helps when debugging ST API. :) --- trailing_spaces.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/trailing_spaces.py b/trailing_spaces.py index 1bd35b3..f3013d8 100644 --- a/trailing_spaces.py +++ b/trailing_spaces.py @@ -31,6 +31,7 @@ # Highlight color as defined in settings. Plugin mutates that setting when disabled so # that has to be stored. INITIAL_HIGHLIGHT_COLOR = None +HIGHLIGHT_REGION_KEY = 'TrailingSpacesHighlightedRegions' settings = None @@ -198,12 +199,9 @@ def max_size_exceeded(view): # # Returns nothing. def highlight_trailing_spaces_regions(view, regions): - view.erase_regions("TrailingSpacesHighlightedRegions") - view.add_regions('TrailingSpacesHighlightedRegions', - regions, - current_highlight_color or "", - "", - sublime.HIDE_ON_MINIMAP) + view.erase_regions(HIGHLIGHT_REGION_KEY) + if regions: + view.add_regions(HIGHLIGHT_REGION_KEY, regions, current_highlight_color or "", "", sublime.HIDE_ON_MINIMAP) # Private: Toggles highlighting of all trailing spaces in the view. @@ -228,7 +226,7 @@ def toggle_highlighting(view): scope = INITIAL_HIGHLIGHT_COLOR if current_highlight_color == "" else "" current_highlight_color = scope - highlight_trailing_spaces_regions(view, view.get_regions('TrailingSpacesHighlightedRegions')) + highlight_trailing_spaces_regions(view, view.get_regions(HIGHLIGHT_REGION_KEY)) return "off" if current_highlight_color == "" else "on"