mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
Merge remote-tracking branch 'origin/stable'
This commit is contained in:
commit
58e4bd4974
@ -5,24 +5,47 @@ import linkService from "../../services/link.js";
|
|||||||
import noteContentRenderer from "../../services/note_content_renderer.js";
|
import noteContentRenderer from "../../services/note_content_renderer.js";
|
||||||
|
|
||||||
export default class AbstractTextTypeWidget extends TypeWidget {
|
export default class AbstractTextTypeWidget extends TypeWidget {
|
||||||
doRender() {
|
setupImageOpening(singleClickOpens) {
|
||||||
this.$widget.on("dblclick", "img", e => {
|
this.$widget.on("dblclick", "img", e => this.openImageInCurrentTab($(e.target)));
|
||||||
const $img = $(e.target);
|
|
||||||
const src = $img.prop("src");
|
|
||||||
|
|
||||||
const match = src.match(/\/api\/images\/([A-Za-z0-9]+)\//);
|
this.$widget.on("click", "img", e => {
|
||||||
|
if ((e.which === 1 && e.ctrlKey) || e.which === 2) {
|
||||||
if (match) {
|
this.openImageInNewTab($(e.target));
|
||||||
const noteId = match[1];
|
|
||||||
|
|
||||||
appContext.tabManager.getActiveTabContext().setNote(noteId);
|
|
||||||
}
|
}
|
||||||
else {
|
else if (e.which === 1 && singleClickOpens) {
|
||||||
window.open(src, '_blank');
|
this.openImageInCurrentTab($(e.target));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openImageInCurrentTab($img) {
|
||||||
|
const imgSrc = $img.prop("src");
|
||||||
|
const noteId = this.getNoteIdFromImage(imgSrc);
|
||||||
|
|
||||||
|
if (noteId) {
|
||||||
|
appContext.tabManager.getActiveTabContext().setNote(noteId);
|
||||||
|
} else {
|
||||||
|
window.open(imgSrc, '_blank');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
openImageInNewTab($img) {
|
||||||
|
const imgSrc = $img.prop("src");
|
||||||
|
const noteId = this.getNoteIdFromImage(imgSrc);
|
||||||
|
|
||||||
|
if (noteId) {
|
||||||
|
appContext.tabManager.openTabWithNoteWithHoisting(noteId);
|
||||||
|
} else {
|
||||||
|
window.open(imgSrc, '_blank');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getNoteIdFromImage(imgSrc) {
|
||||||
|
const match = imgSrc.match(/\/api\/images\/([A-Za-z0-9]+)\//);
|
||||||
|
|
||||||
|
return match ? match[1] : null;
|
||||||
|
}
|
||||||
|
|
||||||
async loadIncludedNote(noteId, $el) {
|
async loadIncludedNote(noteId, $el) {
|
||||||
const note = await treeCache.getNote(noteId);
|
const note = await treeCache.getNote(noteId);
|
||||||
|
|
||||||
|
@ -84,6 +84,8 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
|
|
||||||
keyboardActionService.setupActionsForElement('text-detail', this.$widget, this);
|
keyboardActionService.setupActionsForElement('text-detail', this.$widget, this);
|
||||||
|
|
||||||
|
this.setupImageOpening(false);
|
||||||
|
|
||||||
super.doRender();
|
super.doRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ const TPL = `
|
|||||||
|
|
||||||
.note-detail-readonly-text img {
|
.note-detail-readonly-text img {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.edit-text-note-button {
|
.edit-text-note-button {
|
||||||
@ -67,6 +68,8 @@ export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
this.triggerEvent('textPreviewDisabled', {tabContext: this.tabContext});
|
this.triggerEvent('textPreviewDisabled', {tabContext: this.tabContext});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.setupImageOpening(true);
|
||||||
|
|
||||||
super.doRender();
|
super.doRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user