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

Disable workaround for on_post_move_async listener not triggering #2582

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .plugin.configuration import LspDisableLanguageServerInProjectCommand
from .plugin.configuration import LspEnableLanguageServerGloballyCommand
from .plugin.configuration import LspEnableLanguageServerInProjectCommand
from .plugin.core.constants import ST_VERSION
from .plugin.core.css import load as load_css
from .plugin.core.open import opening_files
from .plugin.core.panels import PanelName
Expand Down Expand Up @@ -226,18 +227,18 @@ def on_new_window_async(self, w: sublime.Window) -> None:
def on_pre_close_window(self, w: sublime.Window) -> None:
windows.discard(w)

# Note: EventListener.on_post_move_async does not fire when a tab is moved out of the current window in such a way
# that a new window is created: https://github.com/sublimehq/sublime_text/issues/4630
# Hence, as a workaround we use on_pre_move, which still works in that case.
def on_pre_move(self, view: sublime.View) -> None:
listeners = sublime_plugin.view_event_listeners.get(view.id())
if not isinstance(listeners, list):
return
for listener in listeners:
if isinstance(listener, DocumentSyncListener):
# we need a small delay here, so that the DocumentSyncListener will recognize a possible new window
sublime.set_timeout_async(listener.on_post_move_window_async, 1)
if ST_VERSION < 4184: # https://github.com/sublimehq/sublime_text/issues/4630#issuecomment-2502781628
# Workaround for ViewEventListener.on_post_move_async not being triggered when air-dropping a tab:
# https://github.com/sublimehq/sublime_text/issues/4630
listeners = sublime_plugin.view_event_listeners.get(view.id())
if not isinstance(listeners, list):
return
for listener in listeners:
if isinstance(listener, DocumentSyncListener):
# we need a small delay here, so that the DocumentSyncListener will recognize a possible new window
sublime.set_timeout_async(listener.on_post_move_window_async, 1)
return

def on_load(self, view: sublime.View) -> None:
file_name = view.file_name()
Expand Down
5 changes: 5 additions & 0 deletions plugin/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,11 @@ def on_load_async(self) -> None:
partial(self._on_initial_folding_ranges, initially_folded_kinds))
self.on_activated_async()

def on_post_move_async(self) -> None:
if ST_VERSION < 4184: # Already handled in boot.Listener.on_pre_move
return
self.on_post_move_window_async()

def on_activated_async(self) -> None:
if self.view.is_loading() or not is_regular_view(self.view):
return
Expand Down
Loading