Skip to content

Commit e7ca542

Browse files
authored
Keep active group when using Goto commands (#1994)
Fixes #1990
1 parent 418d993 commit e7ca542

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

Default.sublime-keymap

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
// "command": "lsp_symbol_definition",
173173
// "args": {
174174
// "side_by_side": false,
175+
// "force_group": true,
175176
// "fallback": false
176177
// },
177178
// "keys": [
@@ -194,7 +195,8 @@
194195
// {
195196
// "command": "lsp_symbol_type_definition",
196197
// "args": {
197-
// "side_by_side": false
198+
// "side_by_side": false,
199+
// "force_group": true
198200
// },
199201
// "keys": [
200202
// "UNBOUND"
@@ -216,7 +218,8 @@
216218
// {
217219
// "command": "lsp_symbol_declaration",
218220
// "args": {
219-
// "side_by_side": false
221+
// "side_by_side": false,
222+
// "force_group": true
220223
// },
221224
// "keys": [
222225
// "UNBOUND"
@@ -238,7 +241,8 @@
238241
// {
239242
// "command": "lsp_symbol_implementation",
240243
// "args": {
241-
// "side_by_side": false
244+
// "side_by_side": false,
245+
// "force_group": true
242246
// },
243247
// "keys": [
244248
// "UNBOUND"

plugin/core/open.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ def open_file(
2828
# to open as a separate view).
2929
view = window.find_open_file(file)
3030
if view:
31-
opens_in_current_group = group == -1 or window.active_group() == group
32-
opens_as_new_selection = (flags & (sublime.ADD_TO_SELECTION | sublime.REPLACE_MRU)) != 0
33-
return_existing_view = opens_in_current_group and not opens_as_new_selection
31+
opens_in_desired_group = not bool(flags & sublime.FORCE_GROUP) or \
32+
window.get_view_index(view)[0] == window.active_group()
33+
opens_in_side_by_side = bool(flags & (sublime.ADD_TO_SELECTION | sublime.REPLACE_MRU))
34+
return_existing_view = opens_in_desired_group and not opens_in_side_by_side
3435
if return_existing_view:
3536
return Promise.resolve(view)
3637

plugin/goto.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def is_enabled(
2222
event: Optional[dict] = None,
2323
point: Optional[int] = None,
2424
side_by_side: bool = False,
25+
force_group: bool = True,
2526
fallback: bool = False
2627
) -> bool:
2728
return fallback or super().is_enabled(event, point)
@@ -32,6 +33,7 @@ def run(
3233
event: Optional[dict] = None,
3334
point: Optional[int] = None,
3435
side_by_side: bool = False,
36+
force_group: bool = True,
3537
fallback: bool = False
3638
) -> None:
3739
session = self.best_session(self.capability)
@@ -40,27 +42,27 @@ def run(
4042
params = text_document_position_params(self.view, position)
4143
request = Request(self.method, params, self.view, progress=True)
4244
session.send_request(
43-
request, functools.partial(self._handle_response_async, session, side_by_side, fallback)
44-
)
45+
request, functools.partial(self._handle_response_async, session, side_by_side, force_group, fallback))
4546
else:
4647
self._handle_no_results(fallback, side_by_side)
4748

4849
def _handle_response_async(
4950
self,
5051
session: Session,
5152
side_by_side: bool,
53+
force_group: bool,
5254
fallback: bool,
5355
response: Union[None, Location, List[Location], List[LocationLink]]
5456
) -> None:
5557
if isinstance(response, dict):
5658
self.view.run_command("add_jump_record", {"selection": [(r.a, r.b) for r in self.view.sel()]})
57-
open_location_async(session, response, side_by_side)
59+
open_location_async(session, response, side_by_side, force_group)
5860
elif isinstance(response, list):
5961
if len(response) == 0:
6062
self._handle_no_results(fallback, side_by_side)
6163
elif len(response) == 1:
6264
self.view.run_command("add_jump_record", {"selection": [(r.a, r.b) for r in self.view.sel()]})
63-
open_location_async(session, response[0], side_by_side)
65+
open_location_async(session, response[0], side_by_side, force_group)
6466
else:
6567
self.view.run_command("add_jump_record", {"selection": [(r.a, r.b) for r in self.view.sel()]})
6668
sublime.set_timeout(functools.partial(LocationPicker, self.view, session, response, side_by_side))

plugin/locationpicker.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@
1111
import weakref
1212

1313

14-
def open_location_async(session: Session, location: Union[Location, LocationLink], side_by_side: bool) -> None:
14+
def open_location_async(
15+
session: Session,
16+
location: Union[Location, LocationLink],
17+
side_by_side: bool,
18+
force_group: bool
19+
) -> None:
1520
flags = sublime.ENCODED_POSITION
21+
if force_group:
22+
flags |= sublime.FORCE_GROUP
1623
if side_by_side:
1724
flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT
1825

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

0 commit comments

Comments
 (0)