1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-04-01 21:24:45 +02:00

Improve autocompletion

1. Removed autocomplete menu because it lists the entire line, not just what is
being autocompleted.

2. Autocomplete positional args first unless cursor is at - then autocomplete
long options

3. Don't autocomplete an options that is already present.

4. Other fixes
This commit is contained in:
Gabe Cohen 2017-12-14 07:53:49 -06:00
parent 3bf9d01f0a
commit 39c73e1649
2 changed files with 52 additions and 42 deletions

View File

@ -14,6 +14,9 @@ async function handleAutocompletionPromise(line) {
if (words.length == 1) {
if (names.indexOf(words[0]) === -1) {
let x = names.filter((n) => n.indexOf(words[0]) === 0);
if (x.length === 1) {
return x[0] + ' ';
}
return x.length > 0 ? x.map((a) => a + ' ') : line;
} else {
return line;
@ -29,6 +32,7 @@ async function handleAutocompletionPromise(line) {
//complete an option
let next = words.length > 1 ? words[words.length - 1] : '';
let l = [];
if (next[0] === '-') {
for (let i = 0; i<metadata.options.length; i++) {
const options = metadata.options[i][0].split(' ');
//if there are multiple options then they will be seperated by comma and
@ -40,11 +44,12 @@ async function handleAutocompletionPromise(line) {
continue;
}
//First two elements are the flag and the third is the description
if (options[0].indexOf(next) === 0) {
l.push(line.slice(0, line.lastIndexOf(next)) + options[0] + ' ');
}
//Only autocomplete long
if (options.length > 1 && options[1].indexOf(next) === 0) {
l.push(line.slice(0, line.lastIndexOf(next)) + options[1] + ' ');
} else if (options[0].indexOf(next) === 0) {
l.push(line.slice(0, line.lastIndexOf(next)) + options[0] + ' ');
}
}
}
//Complete an argument
@ -55,7 +60,7 @@ async function handleAutocompletionPromise(line) {
let cmdUsage = yargParser(metadata.usage)['_'];
cmdUsage.splice(0, 1);
if (cmdUsage.length <= positionalArgs) return line;
if (cmdUsage.length > positionalArgs) {
let argName = cmdUsage[positionalArgs];
argName = cliUtils.parseCommandArg(argName).name;
@ -84,7 +89,13 @@ async function handleAutocompletionPromise(line) {
let c = filterList(['toggle', 'clear'], next);
l = l.concat(c.map((n) => line.slice(0, line.lastIndexOf(next)) + n + ' '))
}
return l.length > 0 ? l : line;
}
if (l.length === 1) {
return l[0];
} else if (l.length > 1) {
return l;
}
return line;
}
function handleAutocompletion(str, callback) {

View File

@ -111,7 +111,6 @@ class StatusBarWidget extends BaseWidget {
history: this.history,
default: this.promptState_.initialText,
autoComplete: handleAutocompletion,
autoCompleteMenu: true,
autoCompleteHint : true,
};