Skip to content

Build your personal knowledge base with Trilium Notes

bookmark buttons should behave similarly as other launcher buttons in respect to context menu, ctrl-click, left click

zadam8c4dda45eff7
diff --git a/src/public/app/components/tab_manager.js b/src/public/app/components/tab_manager.js
index 208836f8e9..3b9dd1c24b 100644
--- a/src/public/app/components/tab_manager.js
+++ b/src/public/app/components/tab_manager.js
@@ -249,6 +249,18 @@ export default class TabManager extends Component {
return noteContext;
}
+ async openInNewTab(targetNoteId, hoistedNoteId = null) {
+ const noteContext = await this.openEmptyTab(null, hoistedNoteId || this.getActiveContext().hoistedNoteId);
+
+ await noteContext.setNote(targetNoteId);
+ }
+
+ async openInSameTab(targetNoteId, hoistedNoteId = null) {
+ const activeContext = this.getActiveContext();
+ await activeContext.setHoistedNoteId(hoistedNoteId || activeContext.hoistedNoteId);
+ await activeContext.setNote(targetNoteId);
+ }
+
/**
* If the requested notePath is within current note hoisting scope then keep the note hoisting also for the new tab.
*/
diff --git a/src/public/app/widgets/bookmark_buttons.js b/src/public/app/widgets/bookmark_buttons.js
index 621da7d153..31585ad5f0 100644
--- a/src/public/app/widgets/bookmark_buttons.js
+++ b/src/public/app/widgets/bookmark_buttons.js
@@ -22,9 +22,8 @@ export default class BookmarkButtons extends FlexContainer {
const buttonWidget = note.hasLabel("bookmarkFolder")
? new BookmarkFolderWidget(note)
- : new OpenNoteButtonWidget().targetNote(note.noteId);
-
- buttonWidget.class("launcher-button");
+ : new OpenNoteButtonWidget(note)
+ .class("launcher-button");
this.child(buttonWidget);
diff --git a/src/public/app/widgets/buttons/bookmark_folder.js b/src/public/app/widgets/buttons/bookmark_folder.js
index e39edcc0ac..005c671bbd 100644
--- a/src/public/app/widgets/buttons/bookmark_folder.js
+++ b/src/public/app/widgets/buttons/bookmark_folder.js
@@ -8,7 +8,7 @@ const DROPDOWN_TPL = `
min-width: 400px;
max-height: 500px;
padding: 7px 15px 0 15px;
- font-size: 110%;
+ font-size: 1.2rem;
overflow: auto;
}
diff --git a/src/public/app/widgets/buttons/launcher/note_launcher.js b/src/public/app/widgets/buttons/launcher/note_launcher.js
index b3bcf899fd..38f3ca2d2b 100644
--- a/src/public/app/widgets/buttons/launcher/note_launcher.js
+++ b/src/public/app/widgets/buttons/launcher/note_launcher.js
@@ -42,30 +42,18 @@ export default class NoteLauncher extends AbstractLauncher {
if (!evt) {
// keyboard shortcut
- await this.openInSameTab(targetNoteId, hoistedNoteId);
+ await appContext.tabManager.openInSameTab(targetNoteId, hoistedNoteId);
} else {
const ctrlKey = utils.isCtrlKey(evt);
if ((evt.which === 1 && ctrlKey) || evt.which === 2) {
- await this.openInNewTab(targetNoteId, hoistedNoteId);
+ await appContext.tabManager.openInNewTab(targetNoteId, hoistedNoteId);
} else {
- await this.openInSameTab(targetNoteId, hoistedNoteId);
+ await appContext.tabManager.openInSameTab(targetNoteId, hoistedNoteId);
}
}
}
- async openInNewTab(targetNoteId, hoistedNoteId) {
- const noteContext = await appContext.tabManager.openEmptyTab(null, hoistedNoteId);
-
- await noteContext.setNote(targetNoteId);
- }
-
- async openInSameTab(targetNoteId, hoistedNoteId) {
- const activeContext = appContext.tabManager.getActiveContext();
- await activeContext.setHoistedNoteId(hoistedNoteId);
- await activeContext.setNote(targetNoteId);
- }
-
getTargetNoteId() {
const targetNoteId = this.launcherNote.getRelationValue('targetNote');
diff --git a/src/public/app/widgets/buttons/open_note_button_widget.js b/src/public/app/widgets/buttons/open_note_button_widget.js
index f36cc881d3..511c5353f5 100644
--- a/src/public/app/widgets/buttons/open_note_button_widget.js
+++ b/src/public/app/widgets/buttons/open_note_button_widget.js
@@ -1,38 +1,29 @@
import OnClickButtonWidget from "./onclick_button.js";
+import linkContextMenuService from "../../menus/link_context_menu.js";
+import utils from "../../services/utils.js";
import appContext from "../../components/app_context.js";
-import froca from "../../services/froca.js";
-
-// FIXME: this widget might not be useful anymore
export default class OpenNoteButtonWidget extends OnClickButtonWidget {
- targetNote(noteId) {
- froca.getNote(noteId).then(note => {
- if (!note) {
- console.log(`Note ${noteId} has not been found. This might happen on the first run before the target note is created.`);
-
- if (!this.retried) {
- this.retried = true;
-
- setTimeout(() => this.targetNote(noteId), 15000); // should be higher than timeout for checkHiddenSubtree
- }
+ constructor(noteToOpen) {
+ super();
- return;
- }
+ this.noteToOpen = noteToOpen;
- this.icon(note.getIcon());
- this.title(() => {
- const n = froca.getNoteFromCache(noteId);
-
- // always fresh, always decoded (when protected session is available)
- return n.title;
- });
-
- this.refreshIcon();
- });
+ this.title(() => this.noteToOpen.title)
+ .icon(() => this.noteToOpen.getIcon())
+ .onClick((widget, evt) => this.launch(evt))
+ .onAuxClick((widget, evt) => this.launch(evt))
+ .onContextMenu(evt => linkContextMenuService.openContextMenu(this.noteToOpen.noteId, null, evt));
+ }
- this.onClick(() => appContext.tabManager.openTabWithNoteWithHoisting(noteId, true));
+ async launch(evt) {
+ const ctrlKey = utils.isCtrlKey(evt);
- return this;
+ if ((evt.which === 1 && ctrlKey) || evt.which === 2) {
+ await appContext.tabManager.openInNewTab(this.noteToOpen.noteId);
+ } else {
+ await appContext.tabManager.openInSameTab(this.noteToOpen.noteId);
+ }
}
initialRenderCompleteEvent() {