mirror of
https://github.com/zadam/trilium.git
synced 2025-11-15 09:45:52 +01:00
create note directly from mention linking
This commit is contained in:
@@ -115,7 +115,7 @@ export default class NotePathsWidget extends TabAwareWidget {
|
||||
const activeNoteParentNoteId = pathSegments[pathSegments.length - 2]; // we know this is not root so there must be a parent
|
||||
|
||||
for (const parentNote of this.note.getParentNotes()) {
|
||||
const parentNotePath = await treeService.getSomeNotePath(parentNote);
|
||||
const parentNotePath = treeService.getSomeNotePath(parentNote);
|
||||
// this is to avoid having root notes leading '/'
|
||||
const notePath = parentNotePath ? (parentNotePath + '/' + this.noteId) : this.noteId;
|
||||
const isCurrent = activeNoteParentNoteId === parentNote.noteId;
|
||||
@@ -158,4 +158,4 @@ export default class NotePathsWidget extends TabAwareWidget {
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import mimeTypesService from '../../services/mime_types.js';
|
||||
import utils from "../../services/utils.js";
|
||||
import keyboardActionService from "../../services/keyboard_actions.js";
|
||||
import treeCache from "../../services/tree_cache.js";
|
||||
import treeService from "../../services/tree.js";
|
||||
import noteCreateService from "../../services/note_create.js";
|
||||
import AbstractTextTypeWidget from "./abstract_text_type_widget.js";
|
||||
|
||||
const ENABLE_INSPECTOR = false;
|
||||
@@ -15,7 +17,7 @@ const mentionSetup = {
|
||||
feed: queryText => {
|
||||
return new Promise((res, rej) => {
|
||||
noteAutocompleteService.autocompleteSource(queryText, rows => {
|
||||
if (rows.length === 1 && rows[0].title === 'No results') {
|
||||
if (rows.length === 1 && rows[0].pathTitle === 'No results') {
|
||||
rows = [];
|
||||
}
|
||||
|
||||
@@ -25,6 +27,17 @@ const mentionSetup = {
|
||||
row.link = '#' + row.path;
|
||||
}
|
||||
|
||||
if (queryText.trim().length > 0) {
|
||||
rows = [
|
||||
{
|
||||
highlightedTitle: `Create and link note "<strong>${queryText}</strong>"`,
|
||||
id: 'create',
|
||||
title: queryText
|
||||
},
|
||||
...rows
|
||||
];
|
||||
}
|
||||
|
||||
res(rows);
|
||||
});
|
||||
});
|
||||
@@ -256,4 +269,20 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
||||
this.textEditor.model.insertContent(imageElement, this.textEditor.model.document.selection);
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
async createNoteForReferenceLink(title) {
|
||||
const {parentNoteId} = treeService.getNoteIdAndParentIdFromNotePath(this.notePath);
|
||||
|
||||
const {note} = await noteCreateService.createNote(parentNoteId, {
|
||||
activate: false,
|
||||
title: title,
|
||||
target: 'after',
|
||||
targetBranchId: await treeCache.getBranchId(parentNoteId, this.noteId),
|
||||
type: 'text'
|
||||
});
|
||||
|
||||
const notePath = treeService.getSomeNotePath(note);
|
||||
|
||||
return notePath;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user