14
14
INLINE_BLAME_PHANTOM_SET_KEY = "git-blame-inline"
15
15
16
16
17
- class ToggleInlineGitBlame (sublime_plugin .TextCommand ):
18
- # Overrides begin ------------------------------------------------------------------
19
-
20
- def run (self , edit ):
21
- settings = pkg_settings ()
22
- settings .set (
23
- PKG_SETTINGS_KEY_INLINE_BLAME_ENABLED ,
24
- not settings .get (PKG_SETTINGS_KEY_INLINE_BLAME_ENABLED ),
25
- )
26
-
27
- # Overrides end --------------------------------------------------------------------
28
-
29
-
30
17
class BlameInlineListener (BaseBlame , sublime_plugin .ViewEventListener ):
31
18
32
19
pkg_setting_callback_added = False
@@ -40,7 +27,16 @@ def is_applicable(cls, view_settings):
40
27
)
41
28
cls .pkg_setting_callback_added = True
42
29
43
- return pkg_settings ().get (PKG_SETTINGS_KEY_INLINE_BLAME_ENABLED )
30
+ return cls .determine_enablement (view_settings )
31
+
32
+ @classmethod
33
+ def determine_enablement (cls , view_settings ):
34
+ enabled = view_settings .get (
35
+ ToggleInlineGitBlame .VIEW_SETTINGS_KEY_INLINE_BLAME_ENABLED
36
+ )
37
+ if enabled is None :
38
+ enabled = pkg_settings ().get (PKG_SETTINGS_KEY_INLINE_BLAME_ENABLED )
39
+ return enabled
44
40
45
41
@classmethod
46
42
def on_pkg_setting_changed (cls ):
@@ -57,9 +53,9 @@ def on_pkg_setting_changed(cls):
57
53
for view in window .views ()
58
54
if view_is_editor (view )
59
55
]
60
- inline_blame_enabled = pkg_settings ().get (PKG_SETTINGS_KEY_INLINE_BLAME_ENABLED )
61
56
for view in all_editor_views :
62
- if not inline_blame_enabled :
57
+ ToggleInlineGitBlame .erase_customization (view )
58
+ if not pkg_settings ().get (PKG_SETTINGS_KEY_INLINE_BLAME_ENABLED ):
63
59
view .erase_phantoms (INLINE_BLAME_PHANTOM_SET_KEY )
64
60
# Do a dummy modification to the view's settings to induce the ViewEventListener applicability check to happen again.
65
61
view .settings ().set (cls .__name__ , "" )
@@ -163,3 +159,23 @@ def on_post_save_async(self):
163
159
# Redisplay the blame after the file is saved, because there will be
164
160
# no call to on_selection_modified_async after save.
165
161
self .show_inline_blame_handler ()
162
+
163
+
164
+ class ToggleInlineGitBlame (sublime_plugin .TextCommand ):
165
+
166
+ # Might as well reuse the same settings key, but at the view-level.
167
+ VIEW_SETTINGS_KEY_INLINE_BLAME_ENABLED = PKG_SETTINGS_KEY_INLINE_BLAME_ENABLED
168
+
169
+ # Overrides begin ------------------------------------------------------------------
170
+
171
+ def run (self , edit ):
172
+ enabled = not BlameInlineListener .determine_enablement (self .view .settings ())
173
+ if not enabled :
174
+ self .view .erase_phantoms (INLINE_BLAME_PHANTOM_SET_KEY )
175
+ self .view .settings ().set (self .VIEW_SETTINGS_KEY_INLINE_BLAME_ENABLED , enabled )
176
+
177
+ # Overrides end --------------------------------------------------------------------
178
+
179
+ @classmethod
180
+ def erase_customization (cls , view ):
181
+ view .settings ().erase (cls .VIEW_SETTINGS_KEY_INLINE_BLAME_ENABLED )
0 commit comments