composer: cycle through auto-completions

Closes: https://todo.sr.ht/~emersion/gamja/42
This commit is contained in:
Simon Ser
2021-06-30 22:20:40 +02:00
parent 08aefc9dc5
commit 00eebc9859
2 changed files with 58 additions and 35 deletions

View File

@@ -1007,13 +1007,10 @@ export default class App extends Component {
autocomplete(prefix) {
function fromList(l, prefix) {
prefix = prefix.toLowerCase();
let repl = null;
let repl = [];
for (let item of l) {
if (item.toLowerCase().startsWith(prefix)) {
if (repl) {
return null;
}
repl = item;
repl.push(item);
}
}
return repl;
@@ -1021,15 +1018,12 @@ export default class App extends Component {
if (prefix.startsWith("/")) {
let repl = fromList(Object.keys(commands), prefix.slice(1));
if (repl) {
repl = "/" + repl;
}
return repl;
return repl.map(cmd => "/" + cmd);
}
let buf = this.state.buffers.get(this.state.activeBuffer);
if (!buf || !buf.members) {
return null;
return [];
}
return fromList(buf.members.keys(), prefix);
}