Skip to content

Commit 9a6bc86

Browse files
authored
add autocomplete feature for note linking (Closes pbek/QOwnNotes#2903) (#240)
* slicing works as desired. * add note name autocompletion script and metadata update * Updated manifest file (missing comma)
1 parent cac7745 commit 9a6bc86

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import QtQml 2.0
2+
import QOwnNotesTypes 1.0
3+
4+
Script {
5+
function autocompletionHook() {
6+
// get the current word plus non-word-characters before the word to also get the "[<"-character
7+
var word = script.noteTextEditCurrentWord(true);
8+
9+
var noteSubFolderQmlObj = Qt.createQmlObject("import QOwnNotesTypes 1.0; NoteSubFolder{}", mainWindow, "noteSubFolder");
10+
var noteSubFolder = noteSubFolderQmlObj.activeNoteSubFolder();
11+
12+
if (!word.startsWith("[<") || !noteSubFolder || !noteSubFolder.notes) {
13+
return [];
14+
}
15+
// cut the "[>]" off of the string and do a substring search for notes
16+
var searchString = word.slice(2,-1).trim();
17+
18+
// array holds the matching names
19+
var matchedNotes = [];
20+
21+
for(var i in noteSubFolder.notes){
22+
var note = noteSubFolder.notes[i];
23+
if(note.name.toLowerCase().startsWith(searchString.toLowerCase())){
24+
matchedNotes.push(note.name);
25+
}
26+
}
27+
return matchedNotes;
28+
}
29+
30+
}

autocomplete-note-names/info.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "Autocomplete Note Names",
3+
"identifier": "autocomplete-note-names",
4+
"script": "autocomplete-note-names.qml",
5+
"authors": ["@pi55man"],
6+
"platforms": ["linux", "macos", "windows"],
7+
"version": "1.0.0",
8+
"minAppVersion": "17.06.2",
9+
"description" : "This script provides autocompletion for note names in QOwnNotes."
10+
}

0 commit comments

Comments
 (0)