feat(file-manager): open files in a full-window editor tab
Enter on a file handed the editor command to the shell, so the panel closed and had to be reopened, and a docked panel ran the editor squeezed into the dock. Delegate to kitty's edit protocol instead: the editor opens in a new tab with the whole window and the panel is redrawn with the same selection when it exits. The editor now comes from kitty's editor option. file-manager's editor, open_with_sudo and --open-here are kept but ignored so existing configs and mappings keep loading.
This commit is contained in:
4 files changed
+68
-160
No files matched your search
@@ -53,11 +53,10 @@ opt(
|
||||
'editor',
|
||||
'',
|
||||
long_text="""
|
||||
Command used to open a file when the panel opens it itself, that is when
|
||||
:code:`--open-here` is given. When empty, :envvar:`VISUAL` then
|
||||
:envvar:`EDITOR` are used, falling back to :code:`vi`. kitty's own :opt:`editor`
|
||||
option is not visible to a panel started with :code:`launch`, so set this option
|
||||
when the panel runs in a dock and the two differ.
|
||||
Deprecated and ignored. Files are opened through kitty's edit protocol, so the
|
||||
editor is the :opt:`editor` option of :file:`kitty.conf`, with :envvar:`VISUAL`
|
||||
then :envvar:`EDITOR` used when it is :code:`.` (the default). The option is
|
||||
still accepted so that existing configuration files keep loading.
|
||||
""",
|
||||
)
|
||||
|
||||
@@ -66,9 +65,9 @@ opt(
|
||||
'no',
|
||||
option_type='to_bool',
|
||||
long_text="""
|
||||
Prefix the editor command with :code:`sudo` when opening a file, so that files
|
||||
the user cannot write to, such as system configuration files, can still be
|
||||
edited. The password prompt, if any, appears in the shell that hosts the panel.
|
||||
Deprecated and ignored. kitty's edit protocol sends the file back when the
|
||||
editor exits and therefore needs a file the user can write to. Open privileged
|
||||
files with :code:`sudo -e` from the shell instead.
|
||||
""",
|
||||
)
|
||||
|
||||
@@ -95,11 +94,10 @@ map(
|
||||
'activate enter activate',
|
||||
long_text="""
|
||||
When the selection is a directory it becomes the working directory of the shell
|
||||
that launched the panel. When it is a file, the shell receives the command that
|
||||
opens it in the editor configured with the :opt:`editor` option,
|
||||
:envvar:`VISUAL` or :envvar:`EDITOR`. With :code:`--open-here` the panel runs the
|
||||
editor in its own window instead, which is what makes this action work in a
|
||||
docked panel.
|
||||
that launched the panel. When it is a file, the panel opens it in kitty's editor
|
||||
(:opt:`editor`, :envvar:`VISUAL` or :envvar:`EDITOR`) in a new tab, and is
|
||||
drawn again with the same selection once the editor exits. The new tab is what
|
||||
gives the file a whole window even when the panel runs in a dock.
|
||||
""",
|
||||
)
|
||||
map(
|
||||
@@ -154,9 +152,8 @@ Show hidden files when the panel opens.
|
||||
|
||||
--open-here
|
||||
type=bool-set
|
||||
Open files in the panel's own window instead of sending the editor command to
|
||||
the shell. Required in a window dock, where kitty never hands the result back to
|
||||
the shell.
|
||||
Deprecated and ignored. Files are always opened in a new tab, so this flag is
|
||||
only accepted so that existing mappings keep working.
|
||||
|
||||
|
||||
--config -c
|
||||
@@ -190,37 +187,18 @@ def change_directory(w: Any, path: str) -> None:
|
||||
w.paste_text(cmd)
|
||||
|
||||
|
||||
def open_file(w: Any, path: str, use_sudo: bool = False) -> None:
|
||||
# Run the editor in the shell that hosted the panel, like the cd action, so
|
||||
# the file opens where the user already is instead of in a new tab.
|
||||
from kitty.utils import get_editor
|
||||
|
||||
cmd = get_editor(path_to_edit=path)
|
||||
if use_sudo:
|
||||
# -- stops sudo from eating editor arguments that look like its own options.
|
||||
cmd = ['sudo', '--'] + cmd
|
||||
text = shlex.join(cmd)
|
||||
if w.at_prompt:
|
||||
w.write_to_child(text + '\r')
|
||||
else:
|
||||
w.paste_text(text)
|
||||
|
||||
|
||||
@result_handler(has_ready_notification=True)
|
||||
def handle_result(args: list[str], data: dict[str, Any], target_window_id: int, boss: BossType) -> None:
|
||||
if not data:
|
||||
return
|
||||
action, path = data.get('action'), data.get('path')
|
||||
if not action or not path:
|
||||
if action != 'cd' or not path:
|
||||
return
|
||||
w = boss.window_id_map.get(target_window_id)
|
||||
if w is None:
|
||||
boss.ring_bell_if_allowed()
|
||||
return
|
||||
if action == 'cd':
|
||||
change_directory(w, path)
|
||||
elif action == 'open':
|
||||
open_file(w, path, data.get('sudo') == '1')
|
||||
change_directory(w, path)
|
||||
|
||||
|
||||
help_text = 'Browse directories in a side panel and change the working directory of the shell without leaving it'
|
||||
|
||||
Reference in new issue
Block a user