Skip to content

Commit a6f503a

Browse files
committed
Create a per-class PhantomSet key automatically
1 parent 9097b85 commit a6f503a

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ def communicate_error(self, e, modal=True):
146146
# persisted in the console too.
147147
print(user_msg) # noqa: T001
148148

149+
@classmethod
150+
def phantom_set_key(cls):
151+
return "git-blame" + cls.__name__
152+
149153
# ------------------------------------------------------------
150154

151155
@abstractmethod

src/blame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Blame(BaseBlame, sublime_plugin.TextCommand):
1616

1717
def __init__(self, view):
1818
super().__init__(view)
19-
self.phantom_set = sublime.PhantomSet(view, "git-blame")
19+
self.phantom_set = sublime.PhantomSet(view, self.phantom_set_key())
2020

2121
def run(self, edit, prevving=False, fixed_row_num=None, sha_skip_list=[]):
2222
if not self.has_suitable_view():

src/blame_all.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
from .base import BaseBlame
55
from .templates import blame_all_phantom_css, blame_all_phantom_html_template
66

7-
PHANTOM_KEY_ALL = "git-blame-all"
8-
97
VIEW_SETTING_PHANTOM_ALL_DISPLAYED = "git-blame-all-displayed"
108

119
VIEW_SETTING_RULERS = "rulers"
@@ -20,15 +18,15 @@ class BlameShowAll(BaseBlame, sublime_plugin.TextCommand):
2018

2119
def __init__(self, view):
2220
super().__init__(view)
23-
self.phantom_set = sublime.PhantomSet(self.view, PHANTOM_KEY_ALL)
21+
self.phantom_set = sublime.PhantomSet(self.view, self.phantom_set_key())
2422
self.pattern = None
2523

2624
def run(self, edit):
2725
if not self.has_suitable_view():
2826
self.tell_user_to_save()
2927
return
3028

31-
self.view.erase_phantoms(PHANTOM_KEY_ALL)
29+
self.view.erase_phantoms(self.phantom_set_key())
3230
phantoms = [] # type: list[sublime.Phantom] # type: ignore[misc]
3331

3432
# If they are currently shown, toggle them off and return.
@@ -125,7 +123,7 @@ class BlameEraseAll(sublime_plugin.TextCommand):
125123

126124
def run(self, edit):
127125
sublime.status_message("The git blame result is cleared.")
128-
self.view.erase_phantoms(PHANTOM_KEY_ALL)
126+
self.view.erase_phantoms(BlameShowAll.phantom_set_key())
129127
self.view.settings().erase(VIEW_SETTING_PHANTOM_ALL_DISPLAYED)
130128
self.view.run_command("blame_restore_rulers")
131129

src/blame_inline.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
)
1212
from .templates import blame_inline_phantom_css, blame_inline_phantom_html_template
1313

14-
INLINE_BLAME_PHANTOM_SET_KEY = "git-blame-inline"
15-
1614

1715
class BlameInlineListener(BaseBlame, sublime_plugin.ViewEventListener):
1816

@@ -22,7 +20,7 @@ class BlameInlineListener(BaseBlame, sublime_plugin.ViewEventListener):
2220

2321
def __init__(self, view):
2422
super().__init__(view)
25-
self.phantom_set = sublime.PhantomSet(view, INLINE_BLAME_PHANTOM_SET_KEY)
23+
self.phantom_set = sublime.PhantomSet(view, self.phantom_set_key())
2624
self.timer = None
2725
self.delay_seconds = (
2826
pkg_settings().get(PKG_SETTINGS_KEY_INLINE_BLAME_DELAY) / 1000
@@ -61,7 +59,7 @@ def _view(self):
6159
return self.view
6260

6361
def close_by_user_request(self):
64-
self.view.erase_phantoms(INLINE_BLAME_PHANTOM_SET_KEY)
62+
self.view.erase_phantoms(self.phantom_set_key())
6563

6664
def rerun(self, **kwargs):
6765
if self.timer:
@@ -98,7 +96,7 @@ def on_pkg_setting_changed(cls):
9896
for view in all_editor_views:
9997
ToggleInlineGitBlame.erase_viewlevel_customization(view)
10098
if not pkg_settings().get(PKG_SETTINGS_KEY_INLINE_BLAME_ENABLED):
101-
view.erase_phantoms(INLINE_BLAME_PHANTOM_SET_KEY)
99+
view.erase_phantoms(cls.phantom_set_key())
102100
# Do a dummy modification to the view's settings to induce the ViewEventListener applicability check to happen again.
103101
view.settings().set(cls.__name__, "")
104102
view.settings().erase(cls.__name__)
@@ -176,7 +174,7 @@ class ToggleInlineGitBlame(sublime_plugin.TextCommand):
176174
def run(self, edit):
177175
enabled = not BlameInlineListener.determine_enablement(self.view.settings())
178176
if not enabled:
179-
self.view.erase_phantoms(INLINE_BLAME_PHANTOM_SET_KEY)
177+
self.view.erase_phantoms(BlameInlineListener.phantom_set_key())
180178
self.view.settings().set(self.VIEW_SETTINGS_KEY_INLINE_BLAME_ENABLED, enabled)
181179

182180
# Overrides end --------------------------------------------------------------------

0 commit comments

Comments
 (0)