Printable keys now don't include like meta-P e.g. Also really nailing down the index selection in palette

master
Dustin Swan 2 weeks ago
parent 6ab98c1448
commit 4cdd180ebc
Signed by: dustinswan
GPG Key ID: 30D46587E2100467

@ -31,7 +31,8 @@
# | None \ currentIndex); # | None \ currentIndex);
paletteState = { paletteState = {
query = "" query = "",
focusedIndex = 0
}; };
nextSelectable = items index direction \ nextSelectable = items index direction \
@ -42,13 +43,16 @@ nextSelectable = items index direction \
| None \ index; | None \ index;
palette = config \ palette = config \
focusedIndex = 0;
windowHeight = 400; windowHeight = 400;
windowWidth = 600; windowWidth = 600;
# results = take 8 (config.search paletteState.query); # results = take 8 (config.search paletteState.query);
results = config.search paletteState.query; # once you get scrolling.. 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; dialogPadding = 0;
textInputHeight = 40; textInputHeight = 40;
@ -74,23 +78,22 @@ palette = config \
} }
}; };
# stateful, just so it can get keyboard events
ui.stateful { ui.stateful {
key = "palette", key = "palette",
focusable = False, focusable = False,
init = { init = {},
focusedIndex = 0,
},
update = state event \ event 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" } \ | 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" } \ | Key { key = "ArrowDown" } \
{ state = state.{ focusedIndex = nextSelectable results state.focusedIndex 1 }, emit = [] } { state = state, emit = [paletteState.focusedIndex := nextSelectable results effectiveIndex 1] }
| Key { key = "Enter" } \ | Key { key = "Enter" } \
(nth state.focusedIndex results (nth paletteState.focusedIndex results
| Some (Item data) \ { state = state, emit = [config.onSelect data.label] } | Some (Item data) \ { state = state, emit = [paletteState.focusedIndex := 0, config.onSelect data.label] }
| _ \ { state = state, emit = [] }) | _ \ { state = state, emit = [] })
| _ \ { state = state, emit = [] }, | _ \ { state = state, emit = [] },
@ -109,7 +112,7 @@ palette = config \
children = [ children = [
textInput { textInput {
key = "palette-query", key = "palette-query",
initialValue = "", initialValue = paletteState.query,
initialFocus = True, initialFocus = True,
color = "white", color = "white",
backgroundColor = "rgba(0,0,0,0.2)", backgroundColor = "rgba(0,0,0,0.2)",
@ -137,7 +140,7 @@ palette = config \
child = data.label, child = data.label,
w = contentWidth, w = contentWidth,
h = textInputHeight, h = textInputHeight,
selected = (state.focusedIndex == i), selected = (effectiveIndex == i),
onClick = config.onSelect data.label onClick = config.onSelect data.label
} }
| _ \ empty | _ \ empty

@ -1,7 +1,5 @@
osState = { osState = {
palette = { palette = { visible = True },
visible = True
},
windows = [], windows = [],
wm = { wm = {
focusedIndex = 0, focusedIndex = 0,

@ -236,7 +236,7 @@ export function runAppCompiled(canvas: HTMLCanvasElement, store: any) {
meta: { _tag: e.metaKey ? 'True' : 'False' }, meta: { _tag: e.metaKey ? 'True' : 'False' },
alt: { _tag: e.altKey ? 'True' : 'False' }, alt: { _tag: e.altKey ? 'True' : 'False' },
shift: { _tag: e.shiftKey ? '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' }
} }
}; };

Loading…
Cancel
Save