Skip to content

Build your personal knowledge base with Trilium Notes

client: Hide ribbon for non text or read-only notes

Elian Doranb88f0e010936
diff --git a/src/public/app/widgets/containers/ribbon_container.js b/src/public/app/widgets/containers/ribbon_container.js
index c75776a99c..ff0f439246 100644
--- a/src/public/app/widgets/containers/ribbon_container.js
+++ b/src/public/app/widgets/containers/ribbon_container.js
@@ -216,7 +216,7 @@ export default class RibbonContainer extends NoteContextAwareWidget {
this.$tabContainer.empty();
for (const ribbonWidget of this.ribbonWidgets) {
- const ret = ribbonWidget.getTitle(note);
+ const ret = await ribbonWidget.getTitle(note);
if (!ret.show) {
continue;
@@ -351,6 +351,16 @@ export default class RibbonContainer extends NoteContextAwareWidget {
}
}
+ /**
+ * Executed as soon as the user presses the "Edit" floating button in a read-only text note.
+ *
+ * <p>
+ * We need to refresh the ribbon for cases such as the classic editor which relies on the read-only state.
+ */
+ readOnlyTemporarilyDisabledEvent() {
+ this.refresh();
+ }
+
getActiveRibbonWidget() {
return this.ribbonWidgets.find(ch => ch.componentId === this.lastActiveComponentId)
}
diff --git a/src/public/app/widgets/ribbon_widgets/classic_editor_toolbar.js b/src/public/app/widgets/ribbon_widgets/classic_editor_toolbar.js
index 2cf5f46715..4b033b72d8 100644
--- a/src/public/app/widgets/ribbon_widgets/classic_editor_toolbar.js
+++ b/src/public/app/widgets/ribbon_widgets/classic_editor_toolbar.js
@@ -27,13 +27,25 @@ export default class ClassicEditorToolbar extends NoteContextAwareWidget {
this.contentSized();
}
- getTitle(note) {
+ async getTitle() {
return {
- show: true,
+ show: await this.#shouldDisplay(),
activate: true,
title: "Editor toolbar",
icon: "bx bx-edit-alt"
};
}
+ async #shouldDisplay() {
+ if (this.note.type !== "text") {
+ return false;
+ }
+
+ if (await this.noteContext.isReadOnly()) {
+ return false;
+ }
+
+ return true;
+ }
+
}
\ No newline at end of file