mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: auto continuation list in editor (#689)
* feat: auto continuation list in editor * update * update
This commit is contained in:
@ -91,6 +91,29 @@ const MemoEditor = () => {
|
|||||||
}, [editorState.editMemoId]);
|
}, [editorState.editMemoId]);
|
||||||
|
|
||||||
const handleKeyDown = (event: React.KeyboardEvent) => {
|
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 (event.key === "Escape") {
|
||||||
if (state.fullscreen) {
|
if (state.fullscreen) {
|
||||||
handleFullscreenBtnClick();
|
handleFullscreenBtnClick();
|
||||||
|
Reference in New Issue
Block a user