mirror of
https://github.com/zadam/trilium.git
synced 2025-02-22 14:03:36 +08: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
2 changed files with 28 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
import treeService from '../services/tree.js';
|
||||
import noteAutocompleteService from '../services/note_autocomplete.js';
|
||||
import utils from "../services/utils.js";
|
||||
import treeCache from "../services/tree_cache.js";
|
||||
|
||||
const $dialog = $("#include-note-dialog");
|
||||
const $form = $("#include-note-form");
|
||||
|
@ -20,15 +21,27 @@ export async function showDialog(widget) {
|
|||
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', () => {
|
||||
const notePath = $autoComplete.getSelectedPath();
|
||||
|
||||
if (notePath) {
|
||||
$dialog.modal('hide');
|
||||
|
||||
const includedNoteId = treeService.getNoteIdFromNotePath(notePath);
|
||||
|
||||
textTypeWidget.addIncludeNote(includedNoteId);
|
||||
includeNote(notePath);
|
||||
}
|
||||
else {
|
||||
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…
Reference in a new issue