Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on_selection_modified is called when showing a popup through a TextCommand #3424

Closed
rwols opened this issue Jun 22, 2020 · 4 comments
Closed

Comments

@rwols
Copy link

rwols commented Jun 22, 2020

Description

When showing a popup with view.show_popup, one expects no on_selection_modified callbacks to be invoked for that view.

Steps to reproduce

  1. cd ~/.config/sublime-text-3/Packages
  2. mkdir Foo
  3. cd Foo
  4. echo 3.3 > .python-version
  5. Put the following into plugin.py:
import sublime
import sublime_plugin
import datetime


def show(view, point):
    view.show_popup(
        "hello",
        flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY,
        location=point,
        max_width=800)


class ShowHoverCommand(sublime_plugin.TextCommand):

    def run(self, _, point):
        show(self.view, point)


class Foo(sublime_plugin.ViewEventListener):

    def on_selection_modified(self):
        print(datetime.datetime.now(), "on_selection_modified")

    def on_hover(self, point, hover_zone):
        # --- BEGIN:TOGGLE ME ---
        self.view.run_command("show_hover", {"point": point})
        # show(self.view, point)
        # --- END: TOGGLE ME ---

Expected behavior

No prints to the console when hovering over a word in the buffer.

Actual behavior

The code above prints yyyy-mm-dd HH:MM:SS on_selection_modified to the console.

Environment

  • Build: 4074
  • Operating system and version: Ubuntu 20.04
  • Wayland

The bug has also been verified on macOS 10.15.

Additional Information

If you change the python file as follows:

    def on_hover(self, point, hover_zone):
        # --- BEGIN:TOGGLE ME ---
        # self.view.run_command("show_hover", {"point": point})
        show(self.view, point)
        # --- END: TOGGLE ME ---

(So, the popup is shown right in the on_hover callback), then no on_selection_modified callback is invoked, as expected.

Related on_selection_modified issues

#3398 (view.add_regions triggers it)
#2990 (too many callback invocations for clones)
#1254 (mouse-up event should not trigger it)

@rchl
Copy link

rchl commented Jun 22, 2020

I suppose it can be generalized to just creating a new region. With show() replaced like this it also reproduces:

def show(view, point):
    view.add_regions(str(datetime.datetime.now()), view.sel())

rwols added a commit to sublimelsp/LSP that referenced this issue Jun 22, 2020
- 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: sublimehq/sublime_text#3424
rwols added a commit to sublimelsp/LSP that referenced this issue Jun 22, 2020
- 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: sublimehq/sublime_text#3424
@deathaxe
Copy link
Collaborator

Confirm the bug on Windows 10.

Must exist for ages now. I can remember issues related to hovering events when using the Jedi Autocompletion plugin.

@wbond
Copy link
Member

wbond commented Jul 16, 2020

I believe this the same bug as #3398

@wbond
Copy link
Member

wbond commented Aug 19, 2020

This should be fixed in build 4083

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants