From 4cdd180ebcf32cdb293e5028c0f46ab761d6a596 Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Fri, 13 Feb 2026 13:06:41 -0700 Subject: [PATCH] Printable keys now don't include like meta-P e.g. Also really nailing down the index selection in palette --- src/cg/05-palette.cg | 27 +++++++++++++++------------ src/cg/10-os.cg | 4 +--- src/runtime-compiled.ts | 2 +- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/cg/05-palette.cg b/src/cg/05-palette.cg index b290de9..771c00b 100644 --- a/src/cg/05-palette.cg +++ b/src/cg/05-palette.cg @@ -31,7 +31,8 @@ # | None \ currentIndex); paletteState = { - query = "" + query = "", + focusedIndex = 0 }; nextSelectable = items index direction \ @@ -42,13 +43,16 @@ nextSelectable = items index direction \ | None \ index; palette = config \ - focusedIndex = 0; windowHeight = 400; windowWidth = 600; # results = take 8 (config.search paletteState.query); results = config.search paletteState.query; # once you get scrolling.. + effectiveIndex = nth paletteState.focusedIndex results + | Some (Section _) \ nextSelectable results paletteState.focusedIndex 1 + | _ \ paletteState.focusedIndex; + dialogPadding = 0; textInputHeight = 40; @@ -74,23 +78,22 @@ palette = config \ } }; + # stateful, just so it can get keyboard events ui.stateful { key = "palette", focusable = False, - init = { - focusedIndex = 0, - }, + init = {}, update = state event \ event - | Key { printable = True } \ { state = state.{ focusedIndex = 0 }, emit = [] } + | Key { printable = True } \ { state = state, emit = [paletteState.focusedIndex := nextSelectable results 0 1] } | Key { key = "ArrowUp" } \ - { state = state.{ focusedIndex = nextSelectable results state.focusedIndex (0 - 1) }, emit = [] } + { state = state, emit = [paletteState.focusedIndex := nextSelectable results effectiveIndex (0 - 1)] } | Key { key = "ArrowDown" } \ - { state = state.{ focusedIndex = nextSelectable results state.focusedIndex 1 }, emit = [] } + { state = state, emit = [paletteState.focusedIndex := nextSelectable results effectiveIndex 1] } | Key { key = "Enter" } \ - (nth state.focusedIndex results - | Some (Item data) \ { state = state, emit = [config.onSelect data.label] } + (nth paletteState.focusedIndex results + | Some (Item data) \ { state = state, emit = [paletteState.focusedIndex := 0, config.onSelect data.label] } | _ \ { state = state, emit = [] }) | _ \ { state = state, emit = [] }, @@ -109,7 +112,7 @@ palette = config \ children = [ textInput { key = "palette-query", - initialValue = "", + initialValue = paletteState.query, initialFocus = True, color = "white", backgroundColor = "rgba(0,0,0,0.2)", @@ -137,7 +140,7 @@ palette = config \ child = data.label, w = contentWidth, h = textInputHeight, - selected = (state.focusedIndex == i), + selected = (effectiveIndex == i), onClick = config.onSelect data.label } | _ \ empty diff --git a/src/cg/10-os.cg b/src/cg/10-os.cg index c3ba4fd..1940848 100644 --- a/src/cg/10-os.cg +++ b/src/cg/10-os.cg @@ -1,7 +1,5 @@ osState = { - palette = { - visible = True - }, + palette = { visible = True }, windows = [], wm = { focusedIndex = 0, diff --git a/src/runtime-compiled.ts b/src/runtime-compiled.ts index fcde0f5..cebf60c 100644 --- a/src/runtime-compiled.ts +++ b/src/runtime-compiled.ts @@ -236,7 +236,7 @@ export function runAppCompiled(canvas: HTMLCanvasElement, store: any) { meta: { _tag: e.metaKey ? 'True' : 'False' }, alt: { _tag: e.altKey ? 'True' : 'False' }, shift: { _tag: e.shiftKey ? 'True' : 'False' }, - printable: { _tag: e.key.length === 1 ? 'True' : 'False' } + printable: { _tag: (e.key.length === 1 && !e.metaKey && !e.ctrlKey && !e.altKey) ? 'True' : 'False' } } };