Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

feat: scrool to memo after editing (#907)

Stephen Zhou942e1f887b6b
diff --git a/web/src/components/MemoEditor.tsx b/web/src/components/MemoEditor.tsx
index dd233ef47..d3736d20e 100644
--- a/web/src/components/MemoEditor.tsx
+++ b/web/src/components/MemoEditor.tsx
@@ -295,6 +295,15 @@ const MemoEditor = () => {
return resource;
};
+ const scrollToEditingMemo = useCallback(() => {
+ if (editorState.editMemoId) {
+ const memoElements = document.getElementsByClassName(`memos-${editorState.editMemoId}`);
+ if (memoElements.length !== 0) {
+ memoElements[0].scrollIntoView({ behavior: "smooth" });
+ }
+ }
+ }, [editorState.editMemoId]);
+
const handleSaveBtnClick = async () => {
const content = editorRef.current?.getContent() ?? "";
try {
@@ -341,6 +350,8 @@ const MemoEditor = () => {
setEditorContentCache("");
storage.remove(["editingMemoVisibilityCache"]);
editorRef.current?.setContent("");
+
+ scrollToEditingMemo();
};
const handleCancelEdit = () => {
@@ -351,6 +362,8 @@ const MemoEditor = () => {
setEditorContentCache("");
storage.remove(["editingMemoVisibilityCache"]);
}
+
+ scrollToEditingMemo();
};
const handleContentChange = (content: string) => {