mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 13:39:01 +01:00 
			
		
		
		
	create note directly from mention linking
This commit is contained in:
		
							parent
							
								
									c70a842bc6
								
							
						
					
					
						commit
						2e837642e2
					
				@ -1,2 +0,0 @@
 | 
			
		||||
#n:main
 | 
			
		||||
!<md> [0, 0, null, null, -2147483648, -2147483648]
 | 
			
		||||
							
								
								
									
										2
									
								
								libraries/ckeditor/ckeditor.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								libraries/ckeditor/ckeditor.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@ -68,7 +68,7 @@ export async function showDialog(ancestorNoteId) {
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                const note = await treeCache.getNote(change.noteId);
 | 
			
		||||
                const notePath = await treeService.getSomeNotePath(note);
 | 
			
		||||
                const notePath = treeService.getSomeNotePath(note);
 | 
			
		||||
 | 
			
		||||
                if (notePath) {
 | 
			
		||||
                    $noteLink = await linkService.createNoteLink(notePath, {
 | 
			
		||||
 | 
			
		||||
@ -61,7 +61,13 @@ async function createNote(parentNoteId, options = {}) {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return {note, branch};
 | 
			
		||||
    const noteEntity = await treeCache.getNote(note.noteId);
 | 
			
		||||
    const branchEntity = treeCache.getBranchId(branch.branchId);
 | 
			
		||||
 | 
			
		||||
    return {
 | 
			
		||||
        note: noteEntity,
 | 
			
		||||
        branch: branchEntity
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* If first element is heading, parse it out and use it as a new heading. */
 | 
			
		||||
 | 
			
		||||
@ -71,7 +71,7 @@ async function getRunPath(notePath) {
 | 
			
		||||
                if (parents.length > 0) {
 | 
			
		||||
                    console.debug(utils.now(), "Available parents:", parents);
 | 
			
		||||
 | 
			
		||||
                    const someNotePath = await getSomeNotePath(parents[0]);
 | 
			
		||||
                    const someNotePath = getSomeNotePath(parents[0]);
 | 
			
		||||
 | 
			
		||||
                    if (someNotePath) { // in case it's root the path may be empty
 | 
			
		||||
                        const pathToRoot = someNotePath.split("/").reverse();
 | 
			
		||||
@ -103,7 +103,7 @@ async function getRunPath(notePath) {
 | 
			
		||||
    return effectivePath.reverse();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function getSomeNotePath(note) {
 | 
			
		||||
function getSomeNotePath(note) {
 | 
			
		||||
    utils.assertArguments(note);
 | 
			
		||||
 | 
			
		||||
    const path = [];
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -6,6 +6,7 @@
 | 
			
		||||
      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
 | 
			
		||||
      <sourceFolder url="file://$MODULE_DIR$/src/public" isTestSource="false" />
 | 
			
		||||
      <excludeFolder url="file://$MODULE_DIR$/dist" />
 | 
			
		||||
      <excludeFolder url="file://$MODULE_DIR$/src/public/app-dist" />
 | 
			
		||||
    </content>
 | 
			
		||||
    <orderEntry type="inheritedJdk" />
 | 
			
		||||
    <orderEntry type="sourceFolder" forTests="false" />
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user