mirror of
https://git.sr.ht/~emersion/gamja
synced 2024-11-14 19:25:26 -05:00
Autocomplete commands
This commit is contained in:
parent
476c135379
commit
897e0977e2
1 changed files with 23 additions and 13 deletions
|
@ -569,23 +569,33 @@ export default class App extends Component {
|
|||
}
|
||||
|
||||
autocomplete(prefix) {
|
||||
function fromList(l, prefix) {
|
||||
prefix = prefix.toLowerCase();
|
||||
var repl = null;
|
||||
for (var item of l) {
|
||||
if (item.toLowerCase().startsWith(prefix)) {
|
||||
if (repl) {
|
||||
return null;
|
||||
}
|
||||
repl = item;
|
||||
}
|
||||
}
|
||||
return repl;
|
||||
}
|
||||
|
||||
if (prefix.startsWith("/")) {
|
||||
var repl = fromList(Object.keys(commands), prefix.slice(1));
|
||||
if (repl) {
|
||||
repl = "/" + repl;
|
||||
}
|
||||
return repl;
|
||||
}
|
||||
|
||||
if (!this.state.activeBuffer) {
|
||||
return null;
|
||||
}
|
||||
var buf = this.state.buffers.get(this.state.activeBuffer);
|
||||
|
||||
prefix = prefix.toLowerCase();
|
||||
|
||||
var repl = null;
|
||||
for (var nick of buf.members.keys()) {
|
||||
if (nick.toLowerCase().startsWith(prefix)) {
|
||||
if (repl) {
|
||||
return null;
|
||||
}
|
||||
repl = nick;
|
||||
}
|
||||
}
|
||||
return repl;
|
||||
return fromList(buf.members.keys(), prefix);
|
||||
}
|
||||
|
||||
handleBufferScrollTop() {
|
||||
|
|
Loading…
Reference in a new issue