Add basic autocompletion

This commit is contained in:
Simon Ser
2020-06-29 12:36:17 +02:00
parent 2f284f183a
commit 20be67503b
2 changed files with 53 additions and 3 deletions
+22 -1
View File
@@ -55,6 +55,7 @@ export default class App extends Component {
this.handleComposerSubmit = this.handleComposerSubmit.bind(this);
this.handleNickClick = this.handleNickClick.bind(this);
this.handleJoinClick = this.handleJoinClick.bind(this);
this.autocomplete = this.autocomplete.bind(this);
if (window.localStorage && localStorage.getItem("autoconnect")) {
var connectParams = JSON.parse(localStorage.getItem("autoconnect"));
@@ -554,6 +555,26 @@ export default class App extends Component {
this.client.send({ command: "JOIN", params: [channel] });
}
autocomplete(prefix) {
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;
}
componentDidMount() {
if (this.state.connectParams.autoconnect) {
this.connect(this.state.connectParams);
@@ -609,7 +630,7 @@ export default class App extends Component {
</section>
</>
${memberList}
<${Composer} ref=${this.composer} readOnly=${this.state.activeBuffer == SERVER_BUFFER} onSubmit=${this.handleComposerSubmit}/>
<${Composer} ref=${this.composer} readOnly=${this.state.activeBuffer == SERVER_BUFFER} onSubmit=${this.handleComposerSubmit} autocomplete=${this.autocomplete}/>
`;
}
}