Skip to content

Commit 2e83764

Browse files
committed
create note directly from mention linking
1 parent c70a842 commit 2e83764

File tree

9 files changed

+48
-14
lines changed

9 files changed

+48
-14
lines changed

.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997/storage_v2/_src_/schema/main.uQUzAA.meta

-2
This file was deleted.

libraries/ckeditor/ckeditor.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libraries/ckeditor/ckeditor.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/app/dialogs/recent_changes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export async function showDialog(ancestorNoteId) {
6868
}
6969
else {
7070
const note = await treeCache.getNote(change.noteId);
71-
const notePath = await treeService.getSomeNotePath(note);
71+
const notePath = treeService.getSomeNotePath(note);
7272

7373
if (notePath) {
7474
$noteLink = await linkService.createNoteLink(notePath, {

src/public/app/services/note_create.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@ async function createNote(parentNoteId, options = {}) {
6161
}
6262
}
6363

64-
return {note, branch};
64+
const noteEntity = await treeCache.getNote(note.noteId);
65+
const branchEntity = treeCache.getBranchId(branch.branchId);
66+
67+
return {
68+
note: noteEntity,
69+
branch: branchEntity
70+
};
6571
}
6672

6773
/* If first element is heading, parse it out and use it as a new heading. */
@@ -95,4 +101,4 @@ export default {
95101
createNote,
96102
createNewTopLevelNote,
97103
duplicateNote
98-
};
104+
};

src/public/app/services/tree.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async function getRunPath(notePath) {
7171
if (parents.length > 0) {
7272
console.debug(utils.now(), "Available parents:", parents);
7373

74-
const someNotePath = await getSomeNotePath(parents[0]);
74+
const someNotePath = getSomeNotePath(parents[0]);
7575

7676
if (someNotePath) { // in case it's root the path may be empty
7777
const pathToRoot = someNotePath.split("/").reverse();
@@ -103,7 +103,7 @@ async function getRunPath(notePath) {
103103
return effectivePath.reverse();
104104
}
105105

106-
async function getSomeNotePath(note) {
106+
function getSomeNotePath(note) {
107107
utils.assertArguments(note);
108108

109109
const path = [];
@@ -286,4 +286,4 @@ export default {
286286
getNotePathTitle,
287287
getHashValueFromAddress,
288288
parseNotePath
289-
};
289+
};

src/public/app/widgets/note_paths.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export default class NotePathsWidget extends TabAwareWidget {
115115
const activeNoteParentNoteId = pathSegments[pathSegments.length - 2]; // we know this is not root so there must be a parent
116116

117117
for (const parentNote of this.note.getParentNotes()) {
118-
const parentNotePath = await treeService.getSomeNotePath(parentNote);
118+
const parentNotePath = treeService.getSomeNotePath(parentNote);
119119
// this is to avoid having root notes leading '/'
120120
const notePath = parentNotePath ? (parentNotePath + '/' + this.noteId) : this.noteId;
121121
const isCurrent = activeNoteParentNoteId === parentNote.noteId;
@@ -158,4 +158,4 @@ export default class NotePathsWidget extends TabAwareWidget {
158158
this.refresh();
159159
}
160160
}
161-
}
161+
}

src/public/app/widgets/type_widgets/editable_text.js

+31-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import mimeTypesService from '../../services/mime_types.js';
44
import utils from "../../services/utils.js";
55
import keyboardActionService from "../../services/keyboard_actions.js";
66
import treeCache from "../../services/tree_cache.js";
7+
import treeService from "../../services/tree.js";
8+
import noteCreateService from "../../services/note_create.js";
79
import AbstractTextTypeWidget from "./abstract_text_type_widget.js";
810

911
const ENABLE_INSPECTOR = false;
@@ -15,7 +17,7 @@ const mentionSetup = {
1517
feed: queryText => {
1618
return new Promise((res, rej) => {
1719
noteAutocompleteService.autocompleteSource(queryText, rows => {
18-
if (rows.length === 1 && rows[0].title === 'No results') {
20+
if (rows.length === 1 && rows[0].pathTitle === 'No results') {
1921
rows = [];
2022
}
2123

@@ -25,6 +27,17 @@ const mentionSetup = {
2527
row.link = '#' + row.path;
2628
}
2729

30+
if (queryText.trim().length > 0) {
31+
rows = [
32+
{
33+
highlightedTitle: `Create and link note "<strong>${queryText}</strong>"`,
34+
id: 'create',
35+
title: queryText
36+
},
37+
...rows
38+
];
39+
}
40+
2841
res(rows);
2942
});
3043
});
@@ -256,4 +269,20 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
256269
this.textEditor.model.insertContent(imageElement, this.textEditor.model.document.selection);
257270
} );
258271
}
259-
}
272+
273+
async createNoteForReferenceLink(title) {
274+
const {parentNoteId} = treeService.getNoteIdAndParentIdFromNotePath(this.notePath);
275+
276+
const {note} = await noteCreateService.createNote(parentNoteId, {
277+
activate: false,
278+
title: title,
279+
target: 'after',
280+
targetBranchId: await treeCache.getBranchId(parentNoteId, this.noteId),
281+
type: 'text'
282+
});
283+
284+
const notePath = treeService.getSomeNotePath(note);
285+
286+
return notePath;
287+
}
288+
}

trilium.iml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
77
<sourceFolder url="file://$MODULE_DIR$/src/public" isTestSource="false" />
88
<excludeFolder url="file://$MODULE_DIR$/dist" />
9+
<excludeFolder url="file://$MODULE_DIR$/src/public/app-dist" />
910
</content>
1011
<orderEntry type="inheritedJdk" />
1112
<orderEntry type="sourceFolder" forTests="false" />

0 commit comments

Comments
 (0)