diff --git a/README.md b/README.md index 368f662..3bc74d7 100644 --- a/README.md +++ b/README.md @@ -302,7 +302,7 @@ _branch=feat/file-manager-panel ### Publication automatique `version`, à la racine, est la source de vérité des releases. Il suit la version -du fork FWS (`0.1.14`), pas la version amont de kitty embarquée dans le paquet : +du fork FWS (`0.1.15`), pas la version amont de kitty embarquée dans le paquet : c'est elle qui nomme le tag, la release et le paquet `fws-kitty--`. Il doit rester égal à `pkgver` dans `packaging/PKGBUILD` et à la version affichée par `fws-kitty` diff --git a/docs/changelog.rst b/docs/changelog.rst index 1ab3673..6fb8c0c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -263,6 +263,11 @@ Detailed list of changes :kbd:`kitty_mod+H` is pressed. The panel can also be started with :code:`kitty +kitten help`. +- The :doc:`file manager ` can now be browsed with the + mouse: the wheel scrolls the list, a double click opens the entry under the + pointer like :kbd:`Enter` and a right click opens the action palette on the + clicked row. + - The in-place scrollback search got a usable default shortcut: it was bound to :kbd:`kitty_mod+shift+f`, the same physical key as :ac:`move_window_forward` (which allows the shifted fallback), so the last definition won and the search diff --git a/docs/kittens/file-manager.rst b/docs/kittens/file-manager.rst index 03e8184..60e0ad1 100644 --- a/docs/kittens/file-manager.rst +++ b/docs/kittens/file-manager.rst @@ -161,6 +161,16 @@ pas soumise. synchronisation reste inerte. +Souris +------ + +Le panneau se pilote aussi à la souris. La molette parcourt la liste par pas de +trois lignes, sans transmettre l'événement au terminal qui héberge le dock. Un +double-clic ouvre l'entrée sous le pointeur, comme :kbd:`Entrée` : un répertoire +est parcouru, un fichier est confié à l'éditeur. Un clic droit ouvre la palette +d'actions sur la ligne cliquée, identique au raccourci :kbd:`:`. + + .. _file-manager-shortcuts: Raccourcis et configuration diff --git a/kittens/file_manager/main.go b/kittens/file_manager/main.go index e437cfe..76a47b8 100644 --- a/kittens/file_manager/main.go +++ b/kittens/file_manager/main.go @@ -228,6 +228,28 @@ func truncate_to_width(s string, max_width int) string { return string(runes) + "\u2026" } +// wheel_scroll_lines is the number of rows one wheel notch scrolls. It sits +// between a single line, which makes a long directory tedious, and the default +// kitty wheel_scroll_multiplier of five, which skips too much in a panel. +const wheel_scroll_lines = 3 + +// double_click_interval is the largest gap between two clicks on the same row +// that still counts as a double click, matching kitty's click_interval default. +const double_click_interval = 500 * time.Millisecond + +// click_tracker remembers the last click so that a second click on the same row +// opens it, while clicks on different rows stay single selections. +type click_tracker struct { + at time.Time + idx int +} + +func (c *click_tracker) is_double(now time.Time, idx int) bool { + prev_at, prev_idx := c.at, c.idx + c.at, c.idx = now, idx + return idx == prev_idx && !prev_at.IsZero() && now.Sub(prev_at) <= double_click_interval +} + type Handler struct { lp *loop.Loop screen_size loop.ScreenSize @@ -255,6 +277,7 @@ type Handler struct { sync *shell_sync sync_handled bool sync_published bool + clicks click_tracker } func (h *Handler) initialize() (string, error) { @@ -1088,13 +1111,42 @@ func (h *Handler) row_to_entry(cell_y int) int { } func (h *Handler) on_mouse_event(ev *loop.MouseEvent) error { + // The palette owns the pointer while it is open, so clicks and wheel events + // do not change the selection behind it. + if h.palette_open && ev.Event_type != loop.MOUSE_MOVE { + return nil + } switch ev.Event_type { + case loop.MOUSE_PRESS: + // Wheel notches arrive as presses carrying a wheel button. Moving the + // selection keeps the list scrolled to the row under it, without sending + // the event to the terminal that hosts the dock. + switch { + case ev.Buttons&loop.MOUSE_WHEEL_UP != 0: + h.move_selection(-wheel_scroll_lines) + case ev.Buttons&loop.MOUSE_WHEEL_DOWN != 0: + h.move_selection(wheel_scroll_lines) + } case loop.MOUSE_CLICK: - if ev.Buttons&loop.LEFT_MOUSE_BUTTON != 0 { + switch { + case ev.Buttons&loop.LEFT_MOUSE_BUTTON != 0: + idx := h.row_to_entry(ev.Cell.Y) + if idx < 0 { + return nil + } + h.selected = idx + if h.clicks.is_double(time.Now(), idx) { + h.activate() + return nil + } + h.draw_screen() + case ev.Buttons&loop.RIGHT_MOUSE_BUTTON != 0: + // The context menu is the action palette that :: already opens, so + // every panel action is reachable from the pointer too. if idx := h.row_to_entry(ev.Cell.Y); idx >= 0 { h.selected = idx - h.draw_screen() } + h.open_palette() } case loop.MOUSE_MOVE: h.lp.ClearPointerShapes() diff --git a/kittens/file_manager/main_test.go b/kittens/file_manager/main_test.go index 19a4133..8af062b 100644 --- a/kittens/file_manager/main_test.go +++ b/kittens/file_manager/main_test.go @@ -8,6 +8,8 @@ import ( "path/filepath" "testing" "time" + + "github.com/kovidgoyal/kitty/tools/tui/loop" ) func TestSortEntriesDirectoriesFirstThenByName(t *testing.T) { @@ -430,6 +432,47 @@ func TestEditArgsInWindow(t *testing.T) { } } +func TestRowToEntryAccountsForScroll(t *testing.T) { + h := &Handler{ + screen_size: loop.ScreenSize{WidthCells: 40, HeightCells: 10}, + entries: make([]Entry, 12), + scroll: 3, + } + // The list starts on row 2 and the status line takes the last row, so rows + // 2..8 display entries 3..9 + cases := map[int]int{0: -1, 1: 3, 4: 6, 7: 9, 8: -1, 9: -1} + for cell_y, want := range cases { + if got := h.row_to_entry(cell_y); got != want { + t.Fatalf("cell Y %d: wanted entry %d, got %d", cell_y, want, got) + } + } + // A scroll past the end of the list maps to no entry rather than panicking + h.scroll = 20 + if got := h.row_to_entry(1); got != -1 { + t.Fatalf("wanted no entry past the end of the list, got %d", got) + } +} + +func TestClickTrackerDetectsDoubleClick(t *testing.T) { + start := time.Unix(1000, 0) + var c click_tracker + if c.is_double(start, 2) { + t.Fatal("a first click must not be a double click") + } + if !c.is_double(start.Add(200*time.Millisecond), 2) { + t.Fatal("a second click on the same row within the interval is a double click") + } + if c.is_double(start.Add(5*time.Second), 2) { + t.Fatal("a click after the interval must not be a double click") + } + if c.is_double(start.Add(5*time.Second+100*time.Millisecond), 7) { + t.Fatal("a click on another row must not be a double click") + } + if !c.is_double(start.Add(5*time.Second+200*time.Millisecond), 7) { + t.Fatal("the tracker must accept the row clicked last") + } +} + func TestTruncateToWidth(t *testing.T) { if got := truncate_to_width("abcdef", 3); got != "ab\u2026" { t.Fatalf("unexpected truncation %q", got) diff --git a/kitty/launcher/main.c b/kitty/launcher/main.c index 9f99464..d7d8613 100644 --- a/kitty/launcher/main.c +++ b/kitty/launcher/main.c @@ -424,10 +424,10 @@ handle_fast_commandline(CLISpec *cli_spec, const char *instance_group_prefix) { if (get_bool_cli_val(cli_spec, "version")) { if (isatty(STDOUT_FILENO)) { printf("\x1b[3mkitty\x1b[23m \x1b[32m%s\x1b[39m created by \x1b[1;34mKovid Goyal\x1b[22;39m\n", KITTY_VERSION); - printf("\x1b[3mfws-kitty\x1b[23m \x1b[32m0.1.14\x1b[39m by \x1b[1;34mBlackAngelTV\x1b[22;39m\n"); + printf("\x1b[3mfws-kitty\x1b[23m \x1b[32m0.1.15\x1b[39m by \x1b[1;34mBlackAngelTV\x1b[22;39m\n"); } else { printf("kitty %s created by Kovid Goyal\n", KITTY_VERSION); - printf("fws-kitty 0.1.14 by BlackAngelTV\n"); + printf("fws-kitty 0.1.15 by BlackAngelTV\n"); } exit(0); } diff --git a/packaging/PKGBUILD b/packaging/PKGBUILD index 62fd598..e1e51f7 100644 --- a/packaging/PKGBUILD +++ b/packaging/PKGBUILD @@ -13,7 +13,7 @@ pkgname=fws-kitty # Fork version from the version file: it names the release and the package. # The upstream kitty release built inside is tracked by _kittyver below. -pkgver=0.1.14 +pkgver=0.1.15 pkgrel=1 pkgdesc='Fast, feature-rich, GPU based terminal (FWS fork with the file-manager kitten)' arch=('x86_64' 'aarch64') diff --git a/tools/cli/help.go b/tools/cli/help.go index c7d4b3c..f0f3ae4 100644 --- a/tools/cli/help.go +++ b/tools/cli/help.go @@ -31,7 +31,7 @@ func ShowError(err error) { func (self *Command) version_string(formatter *markup.Context) string { return fmt.Sprintln(formatter.Italic(self.CommandStringForUsage()), formatter.Opt(kitty.VersionString+kitty.VersionSuffix), "created by", formatter.Title("Kovid Goyal")) + - fmt.Sprintln(formatter.Italic("fws-kitty"), formatter.Opt("0.1.14"), "by", formatter.Title("BlackAngelTV")) + fmt.Sprintln(formatter.Italic("fws-kitty"), formatter.Opt("0.1.15"), "by", formatter.Title("BlackAngelTV")) } func (self *Command) ShowVersion() { diff --git a/version b/version index 71d6a66..c34958a 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.1.14 +0.1.15