Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: fix cursor jumps on edit in sticky title (#3028)

Muhammad Alic30c54ab9722
diff --git a/.github/workflows/web.beta.publish.yml b/.github/workflows/web.beta.publish.yml
index 9ef60735a..4198ab425 100644
--- a/.github/workflows/web.beta.publish.yml
+++ b/.github/workflows/web.beta.publish.yml
@@ -19,6 +19,7 @@ on:
- ready_for_review
- reopened
- opened
+ - synchronize
branches:
- master
paths-ignore:
diff --git a/apps/web/src/components/editor/title-box.tsx b/apps/web/src/components/editor/title-box.tsx
index aa6f96b60..59e47f50a 100644
--- a/apps/web/src/components/editor/title-box.tsx
+++ b/apps/web/src/components/editor/title-box.tsx
@@ -61,15 +61,19 @@ function TitleBox(props: TitleBoxProps) {
}, [id, updateFontSize]);
useEffect(() => {
- if (inputRef.current && inputRef.current.value !== title) {
- inputRef.current.placeholder = title || "Note title";
+ if (!inputRef.current) return;
+ if (inputRef.current.value && title !== inputRef.current.value) {
+ inputRef.current.placeholder = "Note title";
+ inputRef.current.value = title;
+ updateFontSize(title.length);
}
- }, [title]);
+ }, [title, updateFontSize]);
return (
<Input
ref={inputRef}
variant="clean"
+ id="editor-title"
data-test-id="editor-title"
className="editorTitle"
placeholder={"Note title"}
@@ -98,7 +102,7 @@ export default React.memo(TitleBox, (prevProps, nextProps) => {
return prevProps.readonly === nextProps.readonly;
});
-function onTitleChange(noteId: string | undefined, title: string) {
+export function onTitleChange(noteId: string | undefined, title: string) {
store.get().setTitle(noteId, title);
}
diff --git a/apps/web/src/components/editor/toolbar.jsx b/apps/web/src/components/editor/toolbar.jsx
index cebea46c2..3de44c6a9 100644
--- a/apps/web/src/components/editor/toolbar.jsx
+++ b/apps/web/src/components/editor/toolbar.jsx
@@ -44,6 +44,8 @@ import { AnimatedInput } from "../animated";
import { showPublishView } from "../publish-view";
import { db } from "../../common/db";
import { useEditorInstance, useHistory, useSearch } from "./context";
+import { debounceWithId } from "@notesnook/common";
+import { onTitleChange } from "./title-box";
// TODO: this needs to be cleaned up!
function Toolbar() {
@@ -226,10 +228,10 @@ function Toolbar() {
zIndex: isTitleVisible ? 1 : -1
}}
transition={{ duration: 0.5 }}
- value={title}
+ defaultValue={title}
onChange={(e) => {
- const title = e.target.value;
- setTitle(sessionId, title);
+ const { sessionId, id } = store.get().session;
+ debouncedOnTitleChange(sessionId, id, e.target.value);
}}
sx={{
flex: 1,
@@ -347,3 +349,5 @@ function exitFullscreen(elem) {
elem.msExitFullscreen();
}
}
+
+const debouncedOnTitleChange = debounceWithId(onTitleChange, 100);