|
15 | 15 |
|
16 | 16 |
|
17 | 17 | class BlameInlineListener(BaseBlame, sublime_plugin.ViewEventListener):
|
| 18 | + |
| 19 | + pkg_setting_callback_added = False |
| 20 | + |
18 | 21 | @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 | + |
21 | 30 | return pkg_settings().get(PKG_SETTINGS_KEY_INLINE_BLAME_ENABLED)
|
22 | 31 |
|
| 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 | + |
23 | 55 | def __init__(self, view):
|
24 | 56 | super().__init__(view)
|
25 | 57 | self.phantom_set = sublime.PhantomSet(view, INLINE_BLAME_PHANTOM_SET_KEY)
|
26 | 58 | self.timer = None
|
27 | 59 | self.delay_seconds = (
|
28 | 60 | pkg_settings().get(PKG_SETTINGS_KEY_INLINE_BLAME_DELAY) / 1000
|
29 | 61 | )
|
| 62 | + # Show it immediately for the initially selected line. |
| 63 | + self.show_inline_blame() |
30 | 64 |
|
31 | 65 | def extra_cli_args(self, line_num):
|
32 | 66 | args = ["-L", "{0},{0}".format(line_num), "--date=relative"]
|
|
0 commit comments