mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
add image through "include note" will just insert image instead of standard include note element, #922
This commit is contained in:
parent
84d7097b1a
commit
6de0b19569
@ -1,6 +1,7 @@
|
|||||||
import treeService from '../services/tree.js';
|
import treeService from '../services/tree.js';
|
||||||
import noteAutocompleteService from '../services/note_autocomplete.js';
|
import noteAutocompleteService from '../services/note_autocomplete.js';
|
||||||
import utils from "../services/utils.js";
|
import utils from "../services/utils.js";
|
||||||
|
import treeCache from "../services/tree_cache.js";
|
||||||
|
|
||||||
const $dialog = $("#include-note-dialog");
|
const $dialog = $("#include-note-dialog");
|
||||||
const $form = $("#include-note-form");
|
const $form = $("#include-note-form");
|
||||||
@ -20,15 +21,27 @@ export async function showDialog(widget) {
|
|||||||
noteAutocompleteService.showRecentNotes($autoComplete);
|
noteAutocompleteService.showRecentNotes($autoComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function includeNote(notePath) {
|
||||||
|
const noteId = treeService.getNoteIdFromNotePath(notePath);
|
||||||
|
const note = await treeCache.getNote(noteId);
|
||||||
|
|
||||||
|
if (note.type === 'image') {
|
||||||
|
// there's no benefit to use insert note functionlity for images
|
||||||
|
// so we'll just add an IMG tag
|
||||||
|
textTypeWidget.addImage(noteId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
textTypeWidget.addIncludeNote(noteId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$form.on('submit', () => {
|
$form.on('submit', () => {
|
||||||
const notePath = $autoComplete.getSelectedPath();
|
const notePath = $autoComplete.getSelectedPath();
|
||||||
|
|
||||||
if (notePath) {
|
if (notePath) {
|
||||||
$dialog.modal('hide');
|
$dialog.modal('hide');
|
||||||
|
|
||||||
const includedNoteId = treeService.getNoteIdFromNotePath(notePath);
|
includeNote(notePath);
|
||||||
|
|
||||||
textTypeWidget.addIncludeNote(includedNoteId);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.error("No noteId to include.");
|
console.error("No noteId to include.");
|
||||||
|
@ -279,4 +279,16 @@ export default class TextTypeWidget extends TypeWidget {
|
|||||||
}));
|
}));
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async addImage(noteId) {
|
||||||
|
const note = await treeCache.getNote(noteId);
|
||||||
|
|
||||||
|
this.textEditor.model.change( writer => {
|
||||||
|
const src = `api/images/${note.noteId}/${note.title}`;
|
||||||
|
|
||||||
|
const imageElement = writer.createElement( 'image', { 'src': src } );
|
||||||
|
|
||||||
|
this.textEditor.model.insertContent(imageElement, this.textEditor.model.document.selection);
|
||||||
|
} );
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user