about summary refs log tree commit diff stats
path: root/src/local/select.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-12-18 18:19:09 +0100
committerbptato <nincsnevem662@gmail.com>2024-12-18 21:01:28 +0100
commit9d784a19b345085360f8b663ccc7450c2dab18f2 (patch)
treec747dfa6df2a2a7fb62afbcc4e870aba54883673 /src/local/select.nim
parentf4daa425483e902e2bd43b82427fe10a27eaca66 (diff)
downloadchawan-9d784a19b345085360f8b663ccc7450c2dab18f2.tar.gz
pager, select: hide menu if right click ends outside
Inspired by Dillo.  (Just the movement mechanism; Dillo doesn't hide the
context menu on double click, but we still do.)

Also, we now disable highlighting of menu items when the mouse is
hovering outside.
Diffstat (limited to 'src/local/select.nim')
-rw-r--r--src/local/select.nim17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/local/select.nim b/src/local/select.nim
index b8e19d6c..f98fb944 100644
--- a/src/local/select.nim
+++ b/src/local/select.nim
@@ -27,6 +27,7 @@ type
     x*: int
     y*: int
     redraw*: bool
+    unselected*: bool
     bpos: seq[int]
     opaque: RootRef
     finishImpl: SelectFinish
@@ -53,12 +54,17 @@ proc setCursorY*(select: Select; y: int) =
   if not select.multiple:
     y = max(y, 0)
   if select.options[max(y, 0)].nop:
+    if not select.unselected:
+      select.unselected = true
+      select.queueDraw()
     return
   if select.fromy > y:
     select.setFromY(y)
   if select.fromy + select.maxh <= y:
     select.setFromY(y - select.maxh + 1)
   select.cursory = y
+  if select.unselected:
+    select.unselected = false
   select.queueDraw()
 
 proc getCursorX*(select: Select): int =
@@ -139,7 +145,8 @@ proc submit(select: Select) {.jsfunc.} =
   select.finishImpl(select.opaque, select, srSubmit)
 
 proc click*(select: Select) {.jsfunc.} =
-  if select.cursory >= 0 and select.cursory < select.options.len and
+  if select.unselected or
+      select.cursory >= 0 and select.cursory < select.options.len and
       select.options[select.cursory].nop:
     discard
   elif not select.multiple:
@@ -233,6 +240,11 @@ proc popCursorPos*(select: Select; nojump = false) =
   if not nojump:
     select.queueDraw()
 
+proc unselect*(select: Select) =
+  if not select.unselected:
+    select.unselected = true
+    select.queueDraw()
+
 const HorizontalBar = "\u2500"
 const VerticalBar = "\u2502"
 const CornerTopLeft = "\u250C"
@@ -325,7 +337,8 @@ proc drawSelect*(select: Select; display: var FixedGrid) =
     let dls = y * display.width
     if (select.multiple and k < select.selected.len and
           select.selected[k] == i or
-        not select.multiple and select.getCursorY() == y):
+        not select.multiple and select.getCursorY() == y and
+          not select.unselected):
       format.flags.incl(ffReverse)
       inc k
     else: