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:
BlackAngelTV committed 2026-11-06 08:41:18 +01:00
1 parent a12a05e666
commit 4fb1402d9e
4 files changed
+68 -160

No files matched your search

+11 -49
View File
@@ -180,37 +180,9 @@ func TestOpenWithSudoOption(t *testing.T) {
}
}
func TestEditorCommand(t *testing.T) {
t.Setenv("VISUAL", "")
t.Setenv("EDITOR", "")
if got := editor_cmd(NewConfig()); len(got) != 1 || got[0] != "vi" {
t.Fatalf("expected the vi fallback, got %#v", got)
}
t.Setenv("EDITOR", "nano")
if got := editor_cmd(NewConfig()); len(got) != 1 || got[0] != "nano" {
t.Fatalf("EDITOR must be used when the option is empty, got %#v", got)
}
t.Setenv("VISUAL", "code -w")
if got := editor_cmd(NewConfig()); len(got) != 2 || got[0] != "code" || got[1] != "-w" {
t.Fatalf("VISUAL must win over EDITOR, got %#v", got)
}
conf := NewConfig()
conf.Editor = "micro --wrap"
if got := editor_cmd(conf); len(got) != 2 || got[0] != "micro" || got[1] != "--wrap" {
t.Fatalf("the editor option must win over the environment, got %#v", got)
}
}
func TestOpenCmdline(t *testing.T) {
conf := NewConfig()
conf.Editor = "nano"
got := open_cmdline(conf, "/tmp/a.py")
if len(got) != 2 || got[0] != "nano" || got[1] != "/tmp/a.py" {
t.Fatalf("unexpected command line: %#v", got)
}
conf.Open_with_sudo = true
got = open_cmdline(conf, "/tmp/a.py")
want := []string{"sudo", "--", "nano", "/tmp/a.py"}
func TestEditArgs(t *testing.T) {
got := edit_args("/tmp/a.py")
want := []string{"edit-in-kitty", "--type=tab", "/tmp/a.py"}
if len(got) != len(want) {
t.Fatalf("expected %#v, got %#v", want, got)
}
@@ -222,32 +194,22 @@ func TestOpenCmdline(t *testing.T) {
}
func TestLoadConfigReadsOpenWithSudo(t *testing.T) {
// The option is ignored now, but old configuration files must keep loading.
dir := t.TempDir()
path := filepath.Join(dir, "file-manager.conf")
if err := os.WriteFile(path, []byte("open_with_sudo yes\n"), 0o644); err != nil {
if err := os.WriteFile(path, []byte("open_with_sudo yes\neditor nano\n"), 0o644); err != nil {
t.Fatal(err)
}
conf, err := load_config(&Options{Config: []string{path}})
if err != nil {
if _, err := load_config(&Options{Config: []string{path}}); err != nil {
t.Fatal(err)
}
if !conf.Open_with_sudo {
t.Fatal("open_with_sudo yes in file-manager.conf must enable sudo")
}
}
func TestResultPayloadCarriesSudoOnlyWhenOpening(t *testing.T) {
h := &Handler{conf: NewConfig(), result_action: "open", result_path: "/tmp/a.py"}
if _, ok := h.result_payload()["sudo"]; ok {
t.Fatal("sudo must not be requested when the option is disabled")
}
h.conf.Open_with_sudo = true
if got := h.result_payload()["sudo"]; got != "1" {
t.Fatalf("sudo must be requested when opening a file, got %q", got)
}
h.result_action = "cd"
if _, ok := h.result_payload()["sudo"]; ok {
t.Fatal("changing directory must never ask for sudo")
func TestResultPayload(t *testing.T) {
h := &Handler{result_action: "cd", result_path: "/tmp"}
got := h.result_payload()
if len(got) != 2 || got["action"] != "cd" || got["path"] != "/tmp" {
t.Fatalf("unexpected payload: %#v", got)
}
}