mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-24 12:08:28 +00:00
minirepl: add keyboard shortcuts
This commit is contained in:
parent
c350f262e6
commit
3209afa4ff
@ -63,6 +63,27 @@ export function MiniRepl({ tune, hideOutsideView = false, enableKeyboard, drawTi
|
|||||||
getTime: () => scheduler.now(),
|
getTime: () => scheduler.now(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// keyboard shortcuts
|
||||||
|
useKeydown(
|
||||||
|
useCallback(
|
||||||
|
async (e) => {
|
||||||
|
if (view?.hasFocus) {
|
||||||
|
if (e.ctrlKey || e.altKey) {
|
||||||
|
if (e.code === 'Enter') {
|
||||||
|
e.preventDefault();
|
||||||
|
flash(view);
|
||||||
|
await activateCode();
|
||||||
|
} else if (e.code === 'Period') {
|
||||||
|
stop();
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[activateCode, stop, view],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
// set active pattern on ctrl+enter
|
// set active pattern on ctrl+enter
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (enableKeyboard) {
|
if (enableKeyboard) {
|
||||||
@ -150,3 +171,8 @@ function useEvent(name, onTrigger, useCapture = false) {
|
|||||||
};
|
};
|
||||||
}, [onTrigger]);
|
}, [onTrigger]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: dedupe
|
||||||
|
function useKeydown(onTrigger) {
|
||||||
|
useEvent('keydown', onTrigger, true);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user