feat(file-manager): handle the wheel, double clicks and right clicks
The panel only reacted to a left click on a row, so every other gesture was keyboard-only: the wheel did nothing, a double click did not open the entry and there was no way to reach the actions from the pointer. The wheel now steps the selection by three rows without leaking the event to the hosting terminal, a second click on the same row within kitty's click interval runs the primary action, and a right click opens the action palette on the clicked row. Fixes #47
This commit is contained in:
4 files changed
+112
-2
No files matched your search
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user