feat(client): try a different approach to handling read-only threshold

feat(client): revert note_details.ts
This commit is contained in:
perf3ct
2025-05-13 21:59:43 +00:00
parent f07ad03343
commit caccbf49c0
3 changed files with 30 additions and 113 deletions

View File

@@ -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;
return sizeLimit && blob.contentLength > sizeLimit && !this.note.isLabelTruthy("autoReadOnlyDisabled");
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 the cached decision, which won't change until viewScope is reset
return viewScope.readOnlyDecision || false;
}
async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {