custom dialog for editing text labels (no more window.prompt)
This commit is contained in:
parent
20f28d8382
commit
88dee7e3b9
6 changed files with 98 additions and 62 deletions
|
|
@ -184,7 +184,7 @@ export function App() {
|
|||
flexGrow:1,
|
||||
overflow:'auto',
|
||||
}}>
|
||||
<VisualEditor {...{ast, setAST, rt: rt.at(rtIdx!), setRT, errors, setErrors, mode, highlightActive, highlightTransitions}}/>
|
||||
<VisualEditor {...{ast, setAST, rt: rt.at(rtIdx!), setRT, errors, setErrors, mode, highlightActive, highlightTransitions, setModal}}/>
|
||||
</Box>
|
||||
|
||||
{/* right sidebar */}
|
||||
|
|
|
|||
26
src/App/TextDialog.tsx
Normal file
26
src/App/TextDialog.tsx
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { Dispatch, ReactElement, SetStateAction, useState } from "react";
|
||||
|
||||
export function TextDialog(props: {setModal: Dispatch<SetStateAction<ReactElement|null>>, text: string, done: (newText: string|undefined) => void}) {
|
||||
const [text, setText] = useState(props.text);
|
||||
function onKeyDown(e: KeyboardEvent) {
|
||||
if (e.key === "Enter") {
|
||||
if (!e.shiftKey) {
|
||||
e.preventDefault();
|
||||
props.done(text);
|
||||
props.setModal(null);
|
||||
}
|
||||
}
|
||||
if (e.key === "Escape") {
|
||||
props.setModal(null);
|
||||
e.stopPropagation();
|
||||
}
|
||||
e.stopPropagation();
|
||||
}
|
||||
return <span onKeyDown={onKeyDown} style={{backgroundColor:'white'}}>
|
||||
<textarea style={{fontFamily: 'Roboto', width:500, height: 100}} onChange={e=>setText(e.target.value)}>{text}</textarea>
|
||||
<br/>
|
||||
<span style={{backgroundColor:'lightyellow'}}>
|
||||
Tip: <kbd>Shift</kbd>+<kbd>Enter</kbd> to insert newline.
|
||||
</span>
|
||||
</span>;
|
||||
}
|
||||
|
|
@ -75,38 +75,40 @@ export function TopPanel({rt, rtIdx, time, setTime, onInit, onClear, onRaise, on
|
|||
|
||||
useEffect(() => {
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === " ") {
|
||||
e.preventDefault();
|
||||
if (rt)
|
||||
onChangePaused(time.kind !== "paused", Math.round(performance.now()));
|
||||
};
|
||||
if (e.key === "i") {
|
||||
e.preventDefault();
|
||||
onInit();
|
||||
}
|
||||
if (e.key === "c") {
|
||||
e.preventDefault();
|
||||
onClear();
|
||||
}
|
||||
if (e.key === "Tab") {
|
||||
e.preventDefault();
|
||||
onSkip();
|
||||
}
|
||||
if (e.key === "s") {
|
||||
e.preventDefault();
|
||||
onSlower();
|
||||
}
|
||||
if (e.key === "f") {
|
||||
e.preventDefault();
|
||||
onFaster();
|
||||
}
|
||||
if (e.key === "`") {
|
||||
e.preventDefault();
|
||||
setShowKeys(show => !show);
|
||||
}
|
||||
if (e.key === "Backspace") {
|
||||
e.preventDefault();
|
||||
onBack();
|
||||
if (!e.ctrlKey) {
|
||||
if (e.key === " ") {
|
||||
e.preventDefault();
|
||||
if (rt)
|
||||
onChangePaused(time.kind !== "paused", Math.round(performance.now()));
|
||||
};
|
||||
if (e.key === "i") {
|
||||
e.preventDefault();
|
||||
onInit();
|
||||
}
|
||||
if (e.key === "c") {
|
||||
e.preventDefault();
|
||||
onClear();
|
||||
}
|
||||
if (e.key === "Tab") {
|
||||
e.preventDefault();
|
||||
onSkip();
|
||||
}
|
||||
if (e.key === "s") {
|
||||
e.preventDefault();
|
||||
onSlower();
|
||||
}
|
||||
if (e.key === "f") {
|
||||
e.preventDefault();
|
||||
onFaster();
|
||||
}
|
||||
if (e.key === "`") {
|
||||
e.preventDefault();
|
||||
setShowKeys(show => !show);
|
||||
}
|
||||
if (e.key === "Backspace") {
|
||||
e.preventDefault();
|
||||
onBack();
|
||||
}
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
|
|
|
|||
|
|
@ -3,26 +3,28 @@ import { InsertMode } from "../VisualEditor/VisualEditor";
|
|||
|
||||
export function getKeyHandler(setMode: Dispatch<SetStateAction<InsertMode>>) {
|
||||
return function onKeyDown(e: KeyboardEvent) {
|
||||
if (e.key === "a") {
|
||||
setMode("and");
|
||||
}
|
||||
if (e.key === "o") {
|
||||
setMode("or");
|
||||
}
|
||||
if (e.key === "p") {
|
||||
setMode("pseudo");
|
||||
}
|
||||
if (e.key === "t") {
|
||||
setMode("transition");
|
||||
}
|
||||
if (e.key === "x") {
|
||||
setMode("text");
|
||||
}
|
||||
if (e.key === "h") {
|
||||
setMode(oldMode => {
|
||||
if (oldMode === "shallow") return "deep";
|
||||
return "shallow";
|
||||
})
|
||||
if (!e.ctrlKey) {
|
||||
if (e.key === "a") {
|
||||
setMode("and");
|
||||
}
|
||||
if (e.key === "o") {
|
||||
setMode("or");
|
||||
}
|
||||
if (e.key === "p") {
|
||||
setMode("pseudo");
|
||||
}
|
||||
if (e.key === "t") {
|
||||
setMode("transition");
|
||||
}
|
||||
if (e.key === "x") {
|
||||
setMode("text");
|
||||
}
|
||||
if (e.key === "h") {
|
||||
setMode(oldMode => {
|
||||
if (oldMode === "shallow") return "deep";
|
||||
return "shallow";
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue