mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 07:08:55 +02:00
Merge pull request #1918 from TriliumNext/feat/note-edit-readonly-fix2
Store initial "automatic read-only" decision, so that actively edited Note doesn't transition to read-only
This commit is contained in:
commit
4489f6c437
@ -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!;
|
||||
|
||||
return sizeLimit && blob.contentLength > sizeLimit && !this.note.isLabelTruthy("autoReadOnlyDisabled");
|
||||
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 the cached decision, which won't change until viewScope is reset
|
||||
return viewScope.isReadOnly || false;
|
||||
}
|
||||
|
||||
async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user