Skip to content

Commit

Permalink
Keep active group when using Goto commands (#1994)
Browse files Browse the repository at this point in the history
Fixes #1990
  • Loading branch information
jwortmann authored Jul 13, 2022
1 parent 418d993 commit e7ca542
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
10 changes: 7 additions & 3 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
// "command": "lsp_symbol_definition",
// "args": {
// "side_by_side": false,
// "force_group": true,
// "fallback": false
// },
// "keys": [
Expand All @@ -194,7 +195,8 @@
// {
// "command": "lsp_symbol_type_definition",
// "args": {
// "side_by_side": false
// "side_by_side": false,
// "force_group": true
// },
// "keys": [
// "UNBOUND"
Expand All @@ -216,7 +218,8 @@
// {
// "command": "lsp_symbol_declaration",
// "args": {
// "side_by_side": false
// "side_by_side": false,
// "force_group": true
// },
// "keys": [
// "UNBOUND"
Expand All @@ -238,7 +241,8 @@
// {
// "command": "lsp_symbol_implementation",
// "args": {
// "side_by_side": false
// "side_by_side": false,
// "force_group": true
// },
// "keys": [
// "UNBOUND"
Expand Down
7 changes: 4 additions & 3 deletions plugin/core/open.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ def open_file(
# to open as a separate view).
view = window.find_open_file(file)
if view:
opens_in_current_group = group == -1 or window.active_group() == group
opens_as_new_selection = (flags & (sublime.ADD_TO_SELECTION | sublime.REPLACE_MRU)) != 0
return_existing_view = opens_in_current_group and not opens_as_new_selection
opens_in_desired_group = not bool(flags & sublime.FORCE_GROUP) or \
window.get_view_index(view)[0] == window.active_group()
opens_in_side_by_side = bool(flags & (sublime.ADD_TO_SELECTION | sublime.REPLACE_MRU))
return_existing_view = opens_in_desired_group and not opens_in_side_by_side
if return_existing_view:
return Promise.resolve(view)

Expand Down
10 changes: 6 additions & 4 deletions plugin/goto.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def is_enabled(
event: Optional[dict] = None,
point: Optional[int] = None,
side_by_side: bool = False,
force_group: bool = True,
fallback: bool = False
) -> bool:
return fallback or super().is_enabled(event, point)
Expand All @@ -32,6 +33,7 @@ def run(
event: Optional[dict] = None,
point: Optional[int] = None,
side_by_side: bool = False,
force_group: bool = True,
fallback: bool = False
) -> None:
session = self.best_session(self.capability)
Expand All @@ -40,27 +42,27 @@ def run(
params = text_document_position_params(self.view, position)
request = Request(self.method, params, self.view, progress=True)
session.send_request(
request, functools.partial(self._handle_response_async, session, side_by_side, fallback)
)
request, functools.partial(self._handle_response_async, session, side_by_side, force_group, fallback))
else:
self._handle_no_results(fallback, side_by_side)

def _handle_response_async(
self,
session: Session,
side_by_side: bool,
force_group: bool,
fallback: bool,
response: Union[None, Location, List[Location], List[LocationLink]]
) -> None:
if isinstance(response, dict):
self.view.run_command("add_jump_record", {"selection": [(r.a, r.b) for r in self.view.sel()]})
open_location_async(session, response, side_by_side)
open_location_async(session, response, side_by_side, force_group)
elif isinstance(response, list):
if len(response) == 0:
self._handle_no_results(fallback, side_by_side)
elif len(response) == 1:
self.view.run_command("add_jump_record", {"selection": [(r.a, r.b) for r in self.view.sel()]})
open_location_async(session, response[0], side_by_side)
open_location_async(session, response[0], side_by_side, force_group)
else:
self.view.run_command("add_jump_record", {"selection": [(r.a, r.b) for r in self.view.sel()]})
sublime.set_timeout(functools.partial(LocationPicker, self.view, session, response, side_by_side))
Expand Down
12 changes: 10 additions & 2 deletions plugin/locationpicker.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@
import weakref


def open_location_async(session: Session, location: Union[Location, LocationLink], side_by_side: bool) -> None:
def open_location_async(
session: Session,
location: Union[Location, LocationLink],
side_by_side: bool,
force_group: bool
) -> None:
flags = sublime.ENCODED_POSITION
if force_group:
flags |= sublime.FORCE_GROUP
if side_by_side:
flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT

Expand Down Expand Up @@ -80,7 +87,8 @@ def _select_entry(self, index: int) -> None:
if not self._side_by_side:
open_basic_file(session, uri, position, flags)
else:
sublime.set_timeout_async(functools.partial(open_location_async, session, location, self._side_by_side))
sublime.set_timeout_async(
functools.partial(open_location_async, session, location, self._side_by_side, True))
else:
self._window.focus_view(self._view)
# When in side-by-side mode close the current highlighted
Expand Down

0 comments on commit e7ca542

Please sign in to comment.