mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
24 lines
623 B
TypeScript
24 lines
623 B
TypeScript
|
import { useEffect } from "react";
|
||
|
import { EditorRefApi } from "@plane/document-editor";
|
||
|
|
||
|
const useFocusOnSlash = (editorRef: React.RefObject<EditorRefApi>) => {
|
||
|
useEffect(() => {
|
||
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||
|
if (!editorRef.current?.isEditorFocused()) {
|
||
|
if (e.key === "/") {
|
||
|
e.preventDefault();
|
||
|
editorRef.current?.setFocusAtSavedSelection();
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
window.addEventListener("keydown", handleKeyDown);
|
||
|
|
||
|
return () => {
|
||
|
window.removeEventListener("keydown", handleKeyDown);
|
||
|
};
|
||
|
}, [editorRef]);
|
||
|
};
|
||
|
|
||
|
export default useFocusOnSlash;
|