diff --git a/apps/client/src/components/note_context.ts b/apps/client/src/components/note_context.ts index 074e03e4c8..11d32cf0db 100644 --- a/apps/client/src/components/note_context.ts +++ b/apps/client/src/components/note_context.ts @@ -269,14 +269,32 @@ class NoteContext extends Component implements EventListener<"entitiesReloaded"> return true; } - const blob = await this.note.getBlob(); - if (!blob) { - return false; + // Store the initial decision about read-only status in the viewScope + // This will be "remembered" until the viewScope is refreshed + if (!this.viewScope) { + this.resetViewScope(); } - const sizeLimit = this.note.type === "text" ? options.getInt("autoReadonlySizeText") : options.getInt("autoReadonlySizeCode"); + const viewScope = this.viewScope!; + + if (viewScope.isReadOnly === undefined) { + const blob = await this.note.getBlob(); + if (!blob) { + viewScope.isReadOnly = false; + return false; + } + + const sizeLimit = this.note.type === "text" + ? options.getInt("autoReadonlySizeText") + : options.getInt("autoReadonlySizeCode"); + + viewScope.isReadOnly = Boolean(sizeLimit && + blob.contentLength > sizeLimit && + !this.note.isLabelTruthy("autoReadOnlyDisabled")); + } - return sizeLimit && blob.contentLength > sizeLimit && !this.note.isLabelTruthy("autoReadOnlyDisabled"); + // Return the cached decision, which won't change until viewScope is reset + return viewScope.isReadOnly || false; } async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { diff --git a/apps/client/src/services/link.ts b/apps/client/src/services/link.ts index 0425652f6c..9a6b60d68b 100644 --- a/apps/client/src/services/link.ts +++ b/apps/client/src/services/link.ts @@ -48,6 +48,13 @@ export interface ViewScope { viewMode?: ViewMode; attachmentId?: string; readOnlyTemporarilyDisabled?: boolean; + /** + * If true, it indicates that the note in the view should be opened in read-only mode (for supported note types such as text or code). + * + * The reason why we store this information here is that a note can become read-only as the user types content in it, and we wouldn't want + * to immediately enter read-only mode. + */ + isReadOnly?: boolean; highlightsListPreviousVisible?: boolean; highlightsListTemporarilyHidden?: boolean; tocTemporarilyHidden?: boolean;