mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
40 lines
952 B
JavaScript
40 lines
952 B
JavaScript
import { app } from './app.js';
|
|
import { Folder } from 'lib/models/folder.js';
|
|
import { Note } from 'lib/models/note.js';
|
|
|
|
// For now, to go around this issue: https://github.com/dthree/vorpal/issues/114
|
|
function quotePromptArg(s) {
|
|
if (s.indexOf(' ') >= 0) {
|
|
return '"' + s + '"';
|
|
}
|
|
return s;
|
|
}
|
|
|
|
function autocompleteFolders() {
|
|
return Folder.all({ includeConflictFolder: true }).then((folders) => {
|
|
let output = [];
|
|
for (let i = 0; i < folders.length; i++) {
|
|
output.push(quotePromptArg(folders[i].title));
|
|
}
|
|
return output;
|
|
});
|
|
}
|
|
|
|
function autocompleteItems() {
|
|
let promise = null;
|
|
if (!app().currentFolder()) {
|
|
promise = Folder.all();
|
|
} else {
|
|
promise = Note.previews(app().currentFolder().id);
|
|
}
|
|
|
|
return promise.then((items) => {
|
|
let output = [];
|
|
for (let i = 0; i < items.length; i++) {
|
|
output.push(quotePromptArg(items[i].title));
|
|
}
|
|
return output;
|
|
});
|
|
}
|
|
|
|
export { autocompleteFolders, autocompleteItems }; |