web: fix editor cursor jumping to start on creating a new note

This commit is contained in:
Abdullah Atta
2025-03-24 12:28:30 +05:00
parent 15b32b312d
commit b56e381022
2 changed files with 20 additions and 21 deletions

View File

@@ -227,9 +227,8 @@ export default function TabsView() {
const MemoizedEditorView = React.memo(EditorView, (prev, next) => {
return (
prev.session.id === next.session.id &&
(prev.session.type === next.session.type ||
(prev.session.type === "new" && next.session.type === "default")) &&
!!prev.session.needsHydration === !!next.session.needsHydration
prev.session.type === next.session.type &&
prev.session.needsHydration === next.session.needsHydration
);
});
function EditorView({
@@ -252,14 +251,10 @@ function EditorView({
const event = db.eventManager.subscribe(
EVENTS.syncItemMerged,
async (item?: MaybeDeletedItem<Item>) => {
const defaultSession = session as DefaultEditorSession;
const sessionType = useEditorStore
.getState()
.getSession(defaultSession.id)?.type;
if (
sessionType === "new" ||
session.type === "new" ||
!editor ||
!defaultSession.note ||
!session.note ||
!item ||
isDeleted(item) ||
(item.type !== "tiptap" && item.type !== "note") ||
@@ -270,9 +265,8 @@ function EditorView({
}
const isContent =
item.type === "tiptap" && item.noteId === defaultSession.note.id;
const isNote =
item.type === "note" && item.id === defaultSession.note.id;
item.type === "tiptap" && item.noteId === session.note.id;
const isNote = item.type === "note" && item.id === session.note.id;
if (isContent && lastChangedTime.current < item.dateModified) {
if (!item.locked) return editor.updateContent(item.data);
@@ -281,7 +275,7 @@ function EditorView({
.catch(() => EV.publish(EVENTS.vaultLocked));
if (!result) return;
editor.updateContent(result.data);
} else if (isNote && defaultSession.note.title !== item.title) {
} else if (isNote && session.note.title !== item.title) {
AppEventManager.publish(AppEvents.changeNoteTitle, {
sessionId: session.id,
title: item.title,
@@ -871,7 +865,7 @@ function restoreScrollPosition(session: EditorSession) {
function restoreSelection(editor: IEditor, id: string) {
setTimeout(() => {
editor.focus({
position: Config.get(`${id}:selection`, { from: 0, to: 0 })
position: Config.get(`${id}:selection`)
});
});
}

File diff suppressed because one or more lines are too long