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

Keep tab selection and focus when applying WorkspaceEdit #2431

Merged
merged 5 commits into from
Mar 12, 2024
Merged
Changes from 2 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
14 changes: 13 additions & 1 deletion plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1771,12 +1771,16 @@ def apply_workspace_edit_async(self, edit: WorkspaceEdit) -> Promise[None]:
return self.apply_parsed_workspace_edits(parse_workspace_edit(edit))

def apply_parsed_workspace_edits(self, changes: WorkspaceChanges) -> Promise[None]:
active_sheet = self.window.active_sheet()
selected_sheets = self.window.selected_sheets()
promises = [] # type: List[Promise[None]]
for uri, (edits, view_version) in changes.items():
promises.append(
self.open_uri_async(uri).then(functools.partial(self._apply_text_edits, edits, view_version, uri))
)
return Promise.all(promises).then(lambda _: None)
return Promise.all(promises).then(
lambda _: self._check_select_sheets(selected_sheets)).then(
lambda _: self._check_focus_sheet(active_sheet))
rchl marked this conversation as resolved.
Show resolved Hide resolved

def _apply_text_edits(
self, edits: List[TextEdit], view_version: Optional[int], uri: str, view: Optional[sublime.View]
Expand All @@ -1786,6 +1790,14 @@ def _apply_text_edits(
return
apply_text_edits(view, edits, required_view_version=view_version)

def _check_select_sheets(self, sheets: List[sublime.Sheet]) -> None:
if len(sheets) > 1 == len(self.window.selected_sheets()):
rchl marked this conversation as resolved.
Show resolved Hide resolved
self.window.select_sheets(sheets)

def _check_focus_sheet(self, sheet: Optional[sublime.Sheet]) -> None:
if sheet and sheet != self.window.active_sheet():
self.window.focus_sheet(sheet)
rchl marked this conversation as resolved.
Show resolved Hide resolved

def decode_semantic_token(
self, token_type_encoded: int, token_modifiers_encoded: int) -> Tuple[str, List[str], Optional[str]]:
types_legend = tuple(cast(List[str], self.get_capability('semanticTokensProvider.legend.tokenTypes')))
Expand Down