From e6f70f85dadb248a6d97f06d78f8e49d60bbcba2 Mon Sep 17 00:00:00 2001 From: bptato Date: Sun, 24 Nov 2024 22:02:40 +0100 Subject: 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...) --- src/local/select.nim | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src') 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) = -- cgit