Skip to content

Commit 3fc81f6

Browse files
committed
Change Inline-Blame toggling to work at the individual view level
Editing the "inline_blame_enabled" value in the package settings file erases any view-level customisation
1 parent d1df455 commit 3fc81f6

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

Commands/Default.sublime-commands

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
[
2+
{
3+
"caption": "Git Blame: Toggle Inline Blame",
4+
"command": "toggle_inline_git_blame"
5+
},
26
{
37
"caption": "Git Blame: Show",
48
"command": "blame"

src/blame_inline.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,6 @@
1414
INLINE_BLAME_PHANTOM_SET_KEY = "git-blame-inline"
1515

1616

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-
3017
class BlameInlineListener(BaseBlame, sublime_plugin.ViewEventListener):
3118

3219
pkg_setting_callback_added = False
@@ -40,7 +27,16 @@ def is_applicable(cls, view_settings):
4027
)
4128
cls.pkg_setting_callback_added = True
4229

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
4440

4541
@classmethod
4642
def on_pkg_setting_changed(cls):
@@ -57,9 +53,9 @@ def on_pkg_setting_changed(cls):
5753
for view in window.views()
5854
if view_is_editor(view)
5955
]
60-
inline_blame_enabled = pkg_settings().get(PKG_SETTINGS_KEY_INLINE_BLAME_ENABLED)
6156
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):
6359
view.erase_phantoms(INLINE_BLAME_PHANTOM_SET_KEY)
6460
# Do a dummy modification to the view's settings to induce the ViewEventListener applicability check to happen again.
6561
view.settings().set(cls.__name__, "")
@@ -163,3 +159,23 @@ def on_post_save_async(self):
163159
# Redisplay the blame after the file is saved, because there will be
164160
# no call to on_selection_modified_async after save.
165161
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

Comments
 (0)