mirror of
https://github.com/urbit/shrub.git
synced 2024-11-28 05:22:27 +03:00
parent
54f50e9146
commit
f40848eb1f
@ -136,7 +136,11 @@ const ChatEditor = React.forwardRef<CodeMirrorShim, ChatEditorProps>(({ inCodeMo
|
|||||||
setMessage
|
setMessage
|
||||||
} = useChatStore();
|
} = useChatStore();
|
||||||
|
|
||||||
function onKeyPress(e) {
|
const onKeyPress = (e: KeyboardEvent, editor: CodeMirrorShim) => {
|
||||||
|
if (!editor) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const focusedTag = document.activeElement?.nodeName?.toLowerCase();
|
const focusedTag = document.activeElement?.nodeName?.toLowerCase();
|
||||||
const shouldCapture = !(focusedTag === 'textarea' || focusedTag === 'input' || e.metaKey || e.ctrlKey);
|
const shouldCapture = !(focusedTag === 'textarea' || focusedTag === 'input' || e.metaKey || e.ctrlKey);
|
||||||
if(/^[a-z]|[A-Z]$/.test(e.key) && shouldCapture) {
|
if(/^[a-z]|[A-Z]$/.test(e.key) && shouldCapture) {
|
||||||
@ -145,13 +149,14 @@ const ChatEditor = React.forwardRef<CodeMirrorShim, ChatEditorProps>(({ inCodeMo
|
|||||||
if(e.key === 'Escape') {
|
if(e.key === 'Escape') {
|
||||||
editor.getInputField().blur();
|
editor.getInputField().blur();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
document.addEventListener('keydown', onKeyPress);
|
const focusListener = (e: KeyboardEvent) => onKeyPress(e, editorRef.current);
|
||||||
|
document.addEventListener('keydown', focusListener);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener('keydown', onKeyPress);
|
document.removeEventListener('keydown', focusListener);
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user