feat: add some hotkeys (#320)

* feat: add some hotkeys

* fix: hotkeys lose the text behind selected

* chore: adjust insertText params passing
This commit is contained in:
Mahoo Huang
2022-10-23 19:33:45 +08:00
committed by GitHub
parent 65506a5b30
commit 5690dab6bb
2 changed files with 39 additions and 6 deletions

View File

@ -76,6 +76,10 @@ const MemoEditor: React.FC = () => {
prevGlobalStateRef.current = editorState;
}, [state, editorState.editMemoId]);
const handleInsertMark = (mark: string) => {
editorRef.current?.insertText("", mark);
};
const handleKeyDown = (event: React.KeyboardEvent) => {
if (event.key === "Escape" && state.fullscreen) {
handleFullscreenBtnClick();
@ -90,6 +94,21 @@ const MemoEditor: React.FC = () => {
editorRef.current?.insertText(" ".repeat(TAB_SPACE_WIDTH));
return;
}
if (event.ctrlKey || event.metaKey) {
event.preventDefault();
switch (event.key) {
case "b":
handleInsertMark("**");
break;
case "i":
handleInsertMark("*");
break;
case "e":
handleInsertMark("`");
break;
}
return;
}
};
const handleDropEvent = async (event: React.DragEvent) => {