From 5f3499679f106d39f171104df017fa1d5e9badf3 Mon Sep 17 00:00:00 2001 From: Raoul Wols Date: Mon, 22 Jun 2020 23:14:12 +0200 Subject: [PATCH] Fixup hover popup behavior - We used show_popup two times, but it's a smoother experience to use show_popup and then update_popup. - There's a bug in ST where it thinks the view is modified when doing a show_popup or an add_regions call with an edit token. Workaround this by running sublime.set_timeout. See: https://github.com/sublimehq/sublime_text/issues/3424 --- plugin/hover.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/plugin/hover.py b/plugin/hover.py index 5e43468be..32196fc86 100644 --- a/plugin/hover.py +++ b/plugin/hover.py @@ -109,11 +109,11 @@ def request_symbol_hover(self, point: int) -> None: def handle_code_actions(self, responses: Dict[str, List[CodeActionOrCommand]], point: int) -> None: self._actions_by_config = responses - sublime.set_timeout(lambda: self.show_hover(point)) + self.show_hover(point) def handle_response(self, response: Optional[Any], point: int) -> None: self._hover = response - sublime.set_timeout(lambda: self.show_hover(point)) + self.show_hover(point) def symbol_actions_content(self) -> str: actions = [] @@ -175,6 +175,9 @@ def hover_content(self) -> str: return minihtml(self.view, content, allowed_formats=FORMAT_MARKED_STRING | FORMAT_MARKUP_CONTENT) def show_hover(self, point: int) -> None: + sublime.set_timeout(lambda: self._show_hover(point)) + + def _show_hover(self, point: int) -> None: contents = self.diagnostics_content() + self.hover_content() if contents and settings.show_symbol_action_links: contents += self.symbol_actions_content() @@ -183,16 +186,24 @@ def show_hover(self, point: int) -> None: _test_contents.append(contents) # for testing only if contents: - mdpopups.show_popup( - self.view, - contents, - css=popups.stylesheet, - md=False, - flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY, - location=point, - wrapper_class=popups.classname, - max_width=800, - on_navigate=lambda href: self.on_hover_navigate(href, point)) + if self.view.is_popup_visible(): + mdpopups.update_popup( + self.view, + contents, + css=popups.stylesheet, + md=False, + wrapper_class=popups.classname) + else: + mdpopups.show_popup( + self.view, + contents, + css=popups.stylesheet, + md=False, + flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY, + location=point, + wrapper_class=popups.classname, + max_width=800, + on_navigate=lambda href: self.on_hover_navigate(href, point)) def on_hover_navigate(self, href: str, point: int) -> None: for goto_kind in goto_kinds: