mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
open attachment by double click
This commit is contained in:
parent
54c0268593
commit
9e71c44c76
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
||||
return match ? match[1] : null;
|
||||
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 null;
|
||||
}
|
||||
|
||||
async loadIncludedNote(noteId, $el) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user