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);
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

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

@ -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' }
}
};

Loading…
Cancel
Save