further improved keyboard handling
This commit is contained in:
parent
95eb8aef84
commit
fa70d2f3f4
5 changed files with 38 additions and 13 deletions
|
|
@ -2,7 +2,7 @@ import { Double, getType, Int, newDynamic, trie } from "dope2";
|
|||
import { focusNextElement, focusPrevElement, setRightMostCaretPosition } from "./util/dom_trickery";
|
||||
import { parseDouble, parseInt } from "./util/parse";
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { Type } from "./Type";
|
||||
|
||||
import "./InputBlock.css";
|
||||
|
|
@ -29,12 +29,13 @@ const computeSuggestions = (text, env, filter) => {
|
|||
const ls = [
|
||||
... (asDouble ? [[asDouble.toString(), newDynamic(asDouble)(Double)]] : []),
|
||||
... (asInt ? [[asInt.toString(), newDynamic(BigInt(asInt))(Int)]] : []),
|
||||
... trie.suggest(env.name2dyn)(text)(10),
|
||||
... trie.suggest(env.name2dyn)(text)(Infinity),
|
||||
]
|
||||
return [
|
||||
...ls.filter(filter), // ones that match filter come first
|
||||
...ls.filter(s => !filter(s)),
|
||||
];
|
||||
]
|
||||
// .slice(0,30);
|
||||
}
|
||||
|
||||
export function InputBlock({ state, setState, filter, onResolve, onCancel }: InputBlockProps) {
|
||||
|
|
@ -48,7 +49,7 @@ export function InputBlock({ state, setState, filter, onResolve, onCancel }: Inp
|
|||
}
|
||||
|
||||
const singleSuggestion = trie.growPrefix(env.name2dyn)(text);
|
||||
const suggestions = computeSuggestions(text, env, filter);
|
||||
const suggestions = useMemo(() => computeSuggestions(text, env, filter), [text]);
|
||||
|
||||
useEffect(() => {
|
||||
setI(0); // reset
|
||||
|
|
@ -186,7 +187,7 @@ function Suggestions({ suggestions, onSelect, i, setI }) {
|
|||
{suggestions.map(([name, dynamic], j) =>
|
||||
<div
|
||||
key={`${j}_${name}`}
|
||||
className={i === j ? "selected" : ""}
|
||||
className={(i === j ? " selected" : "")}
|
||||
onMouseEnter={onMouseEnter(j)}
|
||||
onMouseDown={onMouseDown(j)}>
|
||||
{name} :: <Type type={getType(dynamic)} />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue