From 27a2e3c4883d7de5428de55f0e08cd4ad5f92508 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 7 May 2024 12:26:28 +0530 Subject: [PATCH] Use correct pointer shape for hyperlinks --- tools/tui/loop/api.go | 2 ++ tools/tui/mouse.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/tools/tui/loop/api.go b/tools/tui/loop/api.go index 2c083eb10..669ee3e0e 100644 --- a/tools/tui/loop/api.go +++ b/tools/tui/loop/api.go @@ -493,6 +493,8 @@ func (self *Loop) PopPointerShape() { } } +// Remove all pointer shapes from the shape stack resetting to default pointer +// shape. This is called automatically on loop termination. func (self *Loop) ClearPointerShapes() (ans []PointerShape) { ans = self.pointer_shapes for i := len(self.pointer_shapes) - 1; i >= 0; i-- { diff --git a/tools/tui/mouse.go b/tools/tui/mouse.go index eb1a56b6d..72f222402 100644 --- a/tools/tui/mouse.go +++ b/tools/tui/mouse.go @@ -289,11 +289,20 @@ func (m *MouseState) ApplyHoverStyles(lp *loop.Loop, style ...string) { } else { hs = style[0] } + is_hovered := false 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) + is_hovered = true } } + if is_hovered { + if s, has := lp.CurrentPointerShape(); !has || s != loop.POINTER_POINTER { + lp.PushPointerShape(loop.POINTER_POINTER) + } + } else { + lp.ClearPointerShapes() + } } func (m *MouseState) ClickHoveredRegions() error {