Skip to content

Commit

Permalink
Fix modifications of settings & saving (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
FichteFoll authored Jun 4, 2023
1 parent c09a3f0 commit 5695f73
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions trailing_spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,28 @@
INITIAL_HIGHLIGHT_COLOR = None
HIGHLIGHT_REGION_KEY = 'TrailingSpacesHighlightedRegions'
settings = None
named_settings = None


def plugin_loaded():
global settings, current_highlight_color, INITIAL_HIGHLIGHT_COLOR
global settings, named_settings, current_highlight_color, INITIAL_HIGHLIGHT_COLOR

# A settings layer that handled settings that included `trailing_spaces_` prefix (now deprecated).
# A settings layer that handles settings with the `trailing_spaces_` prefix (now deprecated).
class DeprecatedSettingsDict(NamedSettingsDict):
def __getitem__(self, key):
return super().__getitem__('trailing_spaces_%s' % key)

deprecated_settings = DeprecatedSettingsDict(SETTINGS_FILENAME)
settings = ChainMap(deprecated_settings, NamedSettingsDict(SETTINGS_FILENAME), DEFAULT_SETTINGS)
named_settings = NamedSettingsDict(SETTINGS_FILENAME)
settings = ChainMap(deprecated_settings, named_settings, DEFAULT_SETTINGS)

current_highlight_color = settings['highlight_color']
INITIAL_HIGHLIGHT_COLOR = current_highlight_color

if not settings['enabled']:
current_highlight_color = ""
if settings['highlight_color'] != current_highlight_color:
settings[0].save()
named_settings.save()


# Private: Makes sure all timers are stopped.
Expand Down Expand Up @@ -376,8 +378,8 @@ def run(self):
return

state = toggle_highlighting(view)
settings['highlight_color'] = current_highlight_color
settings[0].save()
named_settings['highlight_color'] = current_highlight_color
named_settings.save()
sublime.status_message('Highlighting of trailing spaces is %s' % state)

def is_checked(self):
Expand All @@ -388,8 +390,8 @@ def is_checked(self):
class ToggleTrailingSpacesModifiedLinesOnlyCommand(sublime_plugin.WindowCommand):
def run(self):
was_on = settings['modified_lines_only']
settings['modified_lines_only'] = not was_on
settings[0].save()
named_settings['modified_lines_only'] = not was_on
named_settings.save()

message = "Let's trim trailing spaces everywhere" if was_on \
else "Let's trim trailing spaces only on modified lines"
Expand Down

0 comments on commit 5695f73

Please sign in to comment.