feat: auto continuation list in editor (#689)

* feat: auto continuation list in editor

* update

* update
pull/703/head
Zeng1998 2 years ago committed by GitHub
parent 4d9857ce18
commit 36b92ad884
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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();

Loading…
Cancel
Save