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

Show previews in side view for Goto commands with side_by_side #1982

Merged
merged 3 commits into from
Jul 3, 2022
Merged
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
28 changes: 22 additions & 6 deletions plugin/locationpicker.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ def open_basic_file(
position: Position,
flags: int = 0,
group: Optional[int] = None
) -> None:
) -> sublime.View:
filename = session.config.map_server_uri_to_client_path(uri)
if group is None:
group = session.window.active_group()
session.window.open_file(to_encoded_filename(filename, position), flags=flags, group=group)
return session.window.open_file(to_encoded_filename(filename, position), flags=flags, group=group)


class LocationPicker:
Expand All @@ -53,6 +53,7 @@ def __init__(
self._weaksession = weakref.ref(session)
self._side_by_side = side_by_side
self._items = locations
self._highlighted_view = None # type: Optional[sublime.View]
manager = session.manager()
base_dir = manager.get_project_path(view.file_name() or "") if manager else None
self._window.show_quick_panel(
Expand All @@ -76,20 +77,35 @@ def _select_entry(self, index: int) -> None:
# otherwise the bevior feels weird. It's the only reason why open_basic_file exists.
if uri.startswith("file:"):
flags = sublime.ENCODED_POSITION
if self._side_by_side:
flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT
open_basic_file(session, uri, position, flags)
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))
else:
self._window.focus_view(self._view)
# When in side-by-side mode close the current highlighted
# sheet upon canceling if the sheet is semi-transient
if self._side_by_side and self._highlighted_view:
sheet = self._highlighted_view.sheet()
if sheet and sheet.is_semi_transient():
self._highlighted_view.close()

def _highlight_entry(self, index: int) -> None:
session, _, uri, position = self._unpack(index)
if not session:
return
if uri.startswith("file:"):
open_basic_file(session, uri, position, sublime.TRANSIENT | sublime.ENCODED_POSITION)
flags = sublime.ENCODED_POSITION | sublime.FORCE_GROUP
if self._side_by_side:
if self._highlighted_view and self._highlighted_view.is_valid():
# Replacing the MRU is done relative to the current highlighted sheet
self._window.focus_view(self._highlighted_view)
flags |= sublime.REPLACE_MRU | sublime.SEMI_TRANSIENT
else:
flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT
else:
flags |= sublime.TRANSIENT
self._highlighted_view = open_basic_file(session, uri, position, flags, self._window.active_group())
else:
# TODO: Preview non-file uris?
debug("no preview for", uri)
3 changes: 3 additions & 0 deletions stubs/sublime.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,9 @@ class Sheet:
def view(self) -> 'Optional[View]':
...

def is_semi_transient(self) -> bool:
...

def is_transient(self) -> bool:
...

Expand Down