web: fix characters missing sometimes when creating a new note

This commit is contained in:
Abdullah Atta
2026-03-07 12:46:51 +05:00
parent ad78105a6e
commit ea2277ea4e
2 changed files with 13 additions and 2 deletions

View File

@@ -57,7 +57,7 @@ import {
downloadAttachment,
previewImageAttachment
} from "../../common/attachments";
import { EV, EVENTS } from "@notesnook/core";
import { EVENTS } from "@notesnook/core";
import { db } from "../../common/db";
import Titlebox, { resizeTextarea } from "./title-box";
import Config from "../../utils/config";

View File

@@ -959,7 +959,18 @@ class EditorStore extends BaseStore<EditorStore> {
if (index > -1) {
if (options?.force)
session.nonce = (state.sessions[index]?.nonce || 0) + 1;
state.sessions[index] = session;
const oldSession = state.sessions[index];
// SPECIAL CASE: when a user types in a new session, it gets converted
// into a default session with the same id. In this case, we want to
// keep the content that the user has typed in the editor instead of
// replacing it with the content of the note (which can be stale).
if (
oldSession.type === "new" &&
session.type === "default" &&
!!oldSession.content
)
state.sessions[index] = { ...session, content: oldSession.content };
else state.sessions[index] = session;
} else state.sessions.push(session);
});