|
|
|
@ -91,6 +91,29 @@ const MemoEditor = () => {
|
|
|
|
|
}, [editorState.editMemoId]);
|
|
|
|
|
|
|
|
|
|
const handleKeyDown = (event: React.KeyboardEvent) => {
|
|
|
|
|
if (event.key === "Enter") {
|
|
|
|
|
if (!editorRef.current) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const cursorPosition = editorRef.current.getCursorPosition();
|
|
|
|
|
const prevValue = editorRef.current.getContent().slice(0, cursorPosition);
|
|
|
|
|
const prevRows = prevValue.split("\n");
|
|
|
|
|
const prevRowValue = prevRows[prevRows.length - 1];
|
|
|
|
|
if (prevRowValue === "- " || prevRowValue === "- [ ] " || prevRowValue === "- [x] " || prevRowValue === "- [X] ") {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
prevRows[prevRows.length - 1] = "";
|
|
|
|
|
editorRef.current.setContent(prevRows.join("\n"));
|
|
|
|
|
} else {
|
|
|
|
|
if (prevRowValue.startsWith("- [ ] ") || prevRowValue.startsWith("- [x] ") || prevRowValue.startsWith("- [X] ")) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
editorRef.current.insertText("", "\n- [ ] ");
|
|
|
|
|
} else if (prevRowValue.startsWith("- ")) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
editorRef.current.insertText("", "\n- ");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (event.key === "Escape") {
|
|
|
|
|
if (state.fullscreen) {
|
|
|
|
|
handleFullscreenBtnClick();
|
|
|
|
|