Skip to content

Store initial "automatic read-only" decision, so that actively edited Note doesn't transition to read-only #1918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions apps/client/src/components/note_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,33 @@ 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");
// We've ensured viewScope exists by calling resetViewScope() if needed
const viewScope = this.viewScope as ViewScope;

if (viewScope.readOnlyDecision === undefined) {
const blob = await this.note.getBlob();
if (!blob) {
viewScope.readOnlyDecision = false;
return false;
}

const sizeLimit = this.note.type === "text"
? options.getInt("autoReadonlySizeText")
: options.getInt("autoReadonlySizeCode");

viewScope.readOnlyDecision = 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.readOnlyDecision || false;
}

async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
Expand Down
1 change: 1 addition & 0 deletions apps/client/src/services/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface ViewScope {
viewMode?: ViewMode;
attachmentId?: string;
readOnlyTemporarilyDisabled?: boolean;
readOnlyDecision?: boolean;
highlightsListPreviousVisible?: boolean;
highlightsListTemporarilyHidden?: boolean;
tocTemporarilyHidden?: boolean;
Expand Down
Loading