Skip to content

Build your personal knowledge base with Trilium Notes

open attachment by double click

zadam9e71c44c76bb
diff --git a/src/public/app/widgets/attachment_detail.js b/src/public/app/widgets/attachment_detail.js
index e8a954fa7a..de3a70d598 100644
--- a/src/public/app/widgets/attachment_detail.js
+++ b/src/public/app/widgets/attachment_detail.js
@@ -116,10 +116,6 @@ export default class AttachmentDetailWidget extends BasicWidget {
}
}
- openAttachmentDetailCommand() {
-
- }
-
async entitiesReloadedEvent({loadResults}) {
const attachmentChange = loadResults.getAttachments().find(att => att.attachmentId === this.attachment.attachmentId);
diff --git a/src/public/app/widgets/type_widgets/abstract_text_type_widget.js b/src/public/app/widgets/type_widgets/abstract_text_type_widget.js
index 3477e37900..7f6fa52bd3 100644
--- a/src/public/app/widgets/type_widgets/abstract_text_type_widget.js
+++ b/src/public/app/widgets/type_widgets/abstract_text_type_widget.js
@@ -3,47 +3,71 @@ import appContext from "../../components/app_context.js";
import froca from "../../services/froca.js";
import linkService from "../../services/link.js";
import noteContentRenderer from "../../services/note_content_renderer.js";
+import utils from "../../services/utils.js";
export default class AbstractTextTypeWidget extends TypeWidget {
setupImageOpening(singleClickOpens) {
this.$widget.on("dblclick", "img", e => this.openImageInCurrentTab($(e.target)));
this.$widget.on("click", "img", e => {
- if ((e.which === 1 && e.ctrlKey) || e.which === 2) {
+ const isLeftClick = e.which === 1;
+ const isMiddleClick = e.which === 2;
+ const ctrlKey = utils.isCtrlKey(e);
+
+ if ((isLeftClick && ctrlKey) || isMiddleClick) {
this.openImageInNewTab($(e.target));
}
- else if (e.which === 1 && singleClickOpens) {
+ else if (isLeftClick && singleClickOpens) {
this.openImageInCurrentTab($(e.target));
}
});
}
openImageInCurrentTab($img) {
- const imgSrc = $img.prop("src");
- const noteId = this.getNoteIdFromImage(imgSrc);
+ const { noteId, viewScope } = this.parseFromImage($img);
if (noteId) {
- appContext.tabManager.getActiveContext().setNote(noteId);
+ appContext.tabManager.getActiveContext().setNote(noteId, { viewScope });
} else {
- window.open(imgSrc, '_blank');
+ window.open($img.prop("src"), '_blank');
}
}
openImageInNewTab($img) {
- const imgSrc = $img.prop("src");
- const noteId = this.getNoteIdFromImage(imgSrc);
+ const { noteId, viewScope } = this.parseFromImage($img);
if (noteId) {
- appContext.tabManager.openTabWithNoteWithHoisting(noteId);
+ appContext.tabManager.openTabWithNoteWithHoisting(noteId, { viewScope });
} else {
- window.open(imgSrc, '_blank');
+ window.open($img.prop("src"), '_blank');
}
}
- getNoteIdFromImage(imgSrc) {
- const match = imgSrc.match(/\/api\/images\/([A-Za-z0-9_]+)\//);
+ parseFromImage($img) {
+ let noteId, viewScope;
+
+ const imgSrc = $img.prop("src");
+
+ const imageNoteMatch = imgSrc.match(/\/api\/images\/([A-Za-z0-9_]+)\//);
+ if (imageNoteMatch) {
+ return {
+ noteId: imageNoteMatch[1],
+ viewScope: {}
+ }
+ }
+
+ const attachmentMatch = imgSrc.match(/\/api\/notes\/([A-Za-z0-9_]+)\/images\/([A-Za-z0-9_]+)\//);
+ if (attachmentMatch) {
+ return {
+ noteId: attachmentMatch[1],
+ viewScope: {
+ viewMode: 'attachments',
+ attachmentId: attachmentMatch[2]
+ }
+ }
+ }
- return match ? match[1] : null;
+ return null;
}
async loadIncludedNote(noteId, $el) {