From fdf0a13687e925df2725344d81f4801a255cecee Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 5 Jul 2025 12:23:44 +0530 Subject: [PATCH] Change mouse pointer shape over input area --- kittens/choose_files/footer.go | 6 +++--- kittens/choose_files/main.go | 8 +++++--- kittens/choose_files/search-bar.go | 5 +++++ tools/tui/mouse.go | 14 +++++++++----- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/kittens/choose_files/footer.go b/kittens/choose_files/footer.go index 6d7cf79f4..89a72c5e4 100644 --- a/kittens/choose_files/footer.go +++ b/kittens/choose_files/footer.go @@ -41,8 +41,8 @@ func (h *Handler) draw_footer() (num_lines int, err error) { text = sfunc(text) } buf.WriteString(text) - if click_name != "" { - crs = append(crs, single_line_region{x: pos, width: sz, y: len(lines), id: click_name, callback: func(filter string) error { + if click_name != "" && click_name != h.state.current_filter { + crs = append(crs, single_line_region{x: pos, width: sz - 1, y: len(lines), id: click_name, callback: func(filter string) error { h.set_filter(filter) h.state.redraw_needed = true return nil @@ -59,7 +59,7 @@ func (h *Handler) draw_footer() (num_lines int, err error) { } offset := h.screen_size.height - len(lines) for _, cr := range crs { - h.state.mouse_state.AddCellRegion(cr.id, cr.x, cr.y+offset, cr.x+cr.width, cr.y+offset, cr.callback) + h.state.mouse_state.AddCellRegion(cr.id, cr.x, cr.y+offset, cr.x+cr.width, cr.y+offset, cr.callback).HoverStyle = "default fg=red" } } if len(lines) > 0 { diff --git a/kittens/choose_files/main.go b/kittens/choose_files/main.go index 3331a3b07..8c2b2e6d8 100644 --- a/kittens/choose_files/main.go +++ b/kittens/choose_files/main.go @@ -187,7 +187,11 @@ type Handler struct { func (h *Handler) draw_screen() (err error) { h.state.redraw_needed = false h.lp.StartAtomicUpdate() - defer h.lp.EndAtomicUpdate() + defer func() { + h.state.mouse_state.UpdateHoveredIds() + h.state.mouse_state.ApplyHoverStyles(h.lp) + h.lp.EndAtomicUpdate() + }() h.lp.ClearScreen() h.state.mouse_state.ClearCellRegions() switch h.state.screen { @@ -207,8 +211,6 @@ func (h *Handler) draw_screen() (err error) { case SAVE_FILE: err = h.draw_save_file_name_screen() } - h.state.mouse_state.UpdateHoveredIds() - h.state.mouse_state.ApplyHoverStyles(h.lp) return } diff --git a/kittens/choose_files/search-bar.go b/kittens/choose_files/search-bar.go index 67ea08af2..d671a2099 100644 --- a/kittens/choose_files/search-bar.go +++ b/kittens/choose_files/search-bar.go @@ -53,6 +53,11 @@ func (h *Handler) draw_search_bar(y int) { h.lp.MoveCursorTo(1+left_margin, 1+y) available_width := h.screen_size.width - left_margin - right_margin h.draw_frame(available_width, SEARCH_BAR_HEIGHT) + for y1 := y; y1 < y+4; y1++ { + cr := h.state.mouse_state.AddCellRegion("search-bar", left_margin, y1, left_margin+available_width, y1) + cr.PointerShape = loop.TEXT_POINTER + cr.HoverStyle = "none" + } h.lp.MoveCursorTo(1+left_margin+1, 2+y) h.draw_search_text(available_width - 2) } diff --git a/tools/tui/mouse.go b/tools/tui/mouse.go index 6b354b547..2d08ad055 100644 --- a/tools/tui/mouse.go +++ b/tools/tui/mouse.go @@ -4,6 +4,7 @@ package tui import ( "fmt" + "strings" "time" "github.com/kovidgoyal/kitty" @@ -214,6 +215,7 @@ type CellRegion struct { Id string OnClick []func(id string) error PointerShape loop.PointerShape + HoverStyle string // set to "default" for the global hover style } func (c CellRegion) Contains(x, y int) bool { // 0-based @@ -237,7 +239,7 @@ type MouseState struct { } } -func (m *MouseState) AddRegion(cr CellRegion) *CellRegion { +func (m *MouseState) add_region(cr CellRegion) *CellRegion { m.regions = append(m.regions, &cr) if m.region_id_map == nil { m.region_id_map = make(map[string][]*CellRegion) @@ -251,9 +253,8 @@ func (m *MouseState) AddRegion(cr CellRegion) *CellRegion { } func (m *MouseState) AddCellRegion(id string, start_x, start_y, end_x, end_y int, on_click ...func(id string) error) *CellRegion { - cr := CellRegion{ - TopLeft: Point{start_x, start_y}, BottomRight: Point{end_x, end_y}, Id: id, OnClick: on_click, PointerShape: loop.POINTER_POINTER} - return m.AddRegion(cr) + return m.add_region(CellRegion{ + TopLeft: Point{start_x, start_y}, BottomRight: Point{end_x, end_y}, Id: id, OnClick: on_click, PointerShape: loop.POINTER_POINTER, HoverStyle: "default"}) } func (m *MouseState) ClearCellRegions() { @@ -307,7 +308,10 @@ func (m *MouseState) ApplyHoverStyles(lp *loop.Loop, style ...string) { ps := loop.DEFAULT_POINTER for id := range m.hovered_ids.Iterable() { for _, r := range m.region_id_map[id] { - lp.StyleRegion(hs, r.TopLeft.X, r.TopLeft.Y, r.BottomRight.X, r.BottomRight.Y) + if r.HoverStyle != "" { + s := strings.Replace(r.HoverStyle, "default", hs, 1) + lp.StyleRegion(s, r.TopLeft.X, r.TopLeft.Y, r.BottomRight.X, r.BottomRight.Y) + } is_hovered = true ps = r.PointerShape }