about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-11-24 22:02:40 +0100
committerbptato <nincsnevem662@gmail.com>2024-11-24 22:02:40 +0100
commite6f70f85dadb248a6d97f06d78f8e49d60bbcba2 (patch)
tree7cf1ed0844f5995d3406830a925eb1ed286c58cf /src
parentdc13734776e382cb986b55bebfa4f33f2522c657 (diff)
downloadchawan-e6f70f85dadb248a6d97f06d78f8e49d60bbcba2.tar.gz
select: misc fixes
* jump to first selected item (if any) when opened
* fix crash on control chars in option (at least they didn't bleed...)
Diffstat (limited to 'src')
-rw-r--r--src/local/select.nim12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/local/select.nim b/src/local/select.nim
index 76ca03c0..cbb91ab9 100644
--- a/src/local/select.nim
+++ b/src/local/select.nim
@@ -315,10 +315,16 @@ proc drawSelect*(select: Select; display: var FixedGrid) =
     while j < select.options[i].len:
       let pj = j
       let u = select.options[i].nextUTF8(j)
-      let nx = x + u.width()
+      let uw = u.width()
+      let nx = x + uw
       if nx > ex:
         break
-      display[dls + x].str = select.options[i].substr(pj, j - 1)
+      display[dls + x].str = ""
+      if u <= 0xFF and char(u) in Controls:
+        display[dls + x].str &= '^' & char(u).getControlLetter()
+      else:
+        for l in pj ..< j:
+          display[dls + x].str &= select.options[i][l]
       display[dls + x].format = format
       inc x
       while x < nx:
@@ -356,6 +362,8 @@ proc newSelect*(multiple: bool; options: seq[string]; selected: seq[int];
     opt.mnormalize()
     select.maxw = max(select.maxw, opt.width())
   select.windowChange(width, height)
+  if selected.len > 0:
+    select.setCursorY(selected[0])
   return select
 
 proc addSelectModule*(ctx: JSContext) =