Skip to content

Build your personal knowledge base with Trilium Notes

Add config option to change automatic readonly size (#2174)

Abitofevrythingb85cf07a28bf
diff --git a/src/public/app/dialogs/options/other.js b/src/public/app/dialogs/options/other.js
index 213075252b..aa5458f414 100644
--- a/src/public/app/dialogs/options/other.js
+++ b/src/public/app/dialogs/options/other.js
@@ -80,6 +80,22 @@ const TPL = `
<label for="note-revision-snapshot-time-interval-in-seconds">Note revision snapshot time interval (in seconds)</label>
<input class="form-control" id="note-revision-snapshot-time-interval-in-seconds" type="number">
</div>
+</div>
+
+<div>
+ <h4>Automatic readonly size</h4>
+
+ <p>Automatic readonly note size is the size after which notes will be readonly if automatic readonly is enabled.</p>
+
+ <div class="form-group">
+ <label for="automatic-readonly-size">Automatic readonly size (text notes)</label>
+ <input class="form-control" id="automatic-readonly-size-text" type="number">
+ </div>
+
+ <div class="form-group">
+ <label for="automatic-readonly-size">Automatic readonly size (code notes)</label>
+ <input class="form-control" id="automatic-readonly-size-code" type="number">
+ </div>
</div>`;
export default class ProtectedSessionOptions {
@@ -167,6 +183,24 @@ export default class ProtectedSessionOptions {
return false;
});
+
+ this.$autoReadonlySize = $("#automatic-readonly-size-text");
+
+ this.$autoReadonlySize.on('change', () => {
+ const opts = { 'autoReadonlySize': this.$autoReadonlySize.val() };
+ server.put('options', opts).then(() => toastService.showMessage("Options change have been saved."));
+
+ return false;
+ });
+
+ this.$autoCodeReadonlySize = $("#automatic-readonly-size-code");
+
+ this.$autoCodeReadonlySize.on('change', () => {
+ const opts = { 'autoCodeReadonlySize': this.$autoReadonlySize.val() };
+ server.put('options', opts).then(() => toastService.showMessage("Options change have been saved."));
+
+ return false;
+ });
}
optionsLoaded(options) {
@@ -179,5 +213,8 @@ export default class ProtectedSessionOptions {
this.$imageMaxWidthHeight.val(options['imageMaxWidthHeight']);
this.$imageJpegQuality.val(options['imageJpegQuality']);
+
+ this.$autoReadonlySize.val(options['autoReadonlySize']);
+ this.$autoCodeReadonlySize.val(options['autoCodeReadonlySize']);
}
}
diff --git a/src/public/app/services/note_context.js b/src/public/app/services/note_context.js
index f69712bb1c..c5c0de959e 100644
--- a/src/public/app/services/note_context.js
+++ b/src/public/app/services/note_context.js
@@ -6,6 +6,7 @@ import treeService from "./tree.js";
import Component from "../widgets/component.js";
import froca from "./froca.js";
import hoistedNoteService from "./hoisted_note.js";
+import options from "./options.js";
class NoteContext extends Component {
/**
@@ -192,7 +193,9 @@ class NoteContext extends Component {
const noteComplement = await this.getNoteComplement();
- const SIZE_LIMIT = this.note.type === 'text' ? 10000 : 30000;
+ const SIZE_LIMIT = this.note.type === 'text' ?
+ options.getInt('autoReadonlySize')
+ : options.getInt('autoCodeReadonlySize');
return noteComplement.content
&& noteComplement.content.length > SIZE_LIMIT
diff --git a/src/routes/api/options.js b/src/routes/api/options.js
index 46a6126363..8f1463267d 100644
--- a/src/routes/api/options.js
+++ b/src/routes/api/options.js
@@ -42,7 +42,9 @@ const ALLOWED_OPTIONS = new Set([
'promotedAttributesExpanded',
'similarNotesExpanded',
'headingStyle',
- 'autoCollapseNoteTree'
+ 'autoCollapseNoteTree',
+ 'autoReadonlySize',
+ 'autoCodeReadonlySize'
]);
function getOptions() {
diff --git a/src/services/options_init.js b/src/services/options_init.js
index d0e2cd2038..81913fabe8 100644
--- a/src/services/options_init.js
+++ b/src/services/options_init.js
@@ -87,6 +87,8 @@ const defaultOptions = [
{ name: 'debugModeEnabled', value: 'false', isSynced: false },
{ name: 'headingStyle', value: 'underline', isSynced: true },
{ name: 'autoCollapseNoteTree', value: 'true', isSynced: true },
+ { name: 'autoReadonlySize', value: '10000', isSynced: false },
+ { name: 'autoCodeReadonlySize', value: '30000', isSynced: false },
];
function initStartupOptions() {