Skip to content

Commit 192c988

Browse files
committed
Make Inline-Blame reactive to "inline_blame_enabled" being edited in the "Git blame.sublime-settings" file
Fixes #69
1 parent 25e6e74 commit 192c988

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/blame_inline.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,52 @@
1515

1616

1717
class BlameInlineListener(BaseBlame, sublime_plugin.ViewEventListener):
18+
19+
pkg_setting_callback_added = False
20+
1821
@classmethod
19-
def is_applicable(cls, settings):
20-
# @todo Fix inline blame (sometimes?) remaining enabled when the user setting for it is edited from true -> false
22+
def is_applicable(cls, view_settings):
23+
if not cls.pkg_setting_callback_added:
24+
pkg_settings().add_on_change(
25+
PKG_SETTINGS_KEY_INLINE_BLAME_ENABLED,
26+
cls.on_pkg_setting_changed,
27+
)
28+
cls.pkg_setting_callback_added = True
29+
2130
return pkg_settings().get(PKG_SETTINGS_KEY_INLINE_BLAME_ENABLED)
2231

32+
@classmethod
33+
def on_pkg_setting_changed(cls):
34+
# This variable can be elimited once targeting ST4+ only, and the latter lambda body inlined.
35+
view_is_editor = (
36+
# REF: https://github.com/sublimehq/sublime_text/issues/3167
37+
lambda view: not view.settings().get("is_widget")
38+
if sublime.version().startswith("3")
39+
else lambda view: view.element() is None
40+
)
41+
all_editor_views = [
42+
view
43+
for window in sublime.windows()
44+
for view in window.views()
45+
if view_is_editor(view)
46+
]
47+
inline_blame_enabled = pkg_settings().get(PKG_SETTINGS_KEY_INLINE_BLAME_ENABLED)
48+
for view in all_editor_views:
49+
if not inline_blame_enabled:
50+
view.erase_phantoms(INLINE_BLAME_PHANTOM_SET_KEY)
51+
# Do a dummy modification to the view's settings to induce the ViewEventListener applicability check to happen again.
52+
view.settings().set(cls.__name__, "")
53+
view.settings().erase(cls.__name__)
54+
2355
def __init__(self, view):
2456
super().__init__(view)
2557
self.phantom_set = sublime.PhantomSet(view, INLINE_BLAME_PHANTOM_SET_KEY)
2658
self.timer = None
2759
self.delay_seconds = (
2860
pkg_settings().get(PKG_SETTINGS_KEY_INLINE_BLAME_DELAY) / 1000
2961
)
62+
# Show it immediately for the initially selected line.
63+
self.show_inline_blame()
3064

3165
def extra_cli_args(self, line_num):
3266
args = ["-L", "{0},{0}".format(line_num), "--date=relative"]

0 commit comments

Comments
 (0)