focus composer when replying

This commit is contained in:
Bruno Windels 2021-08-06 23:43:10 +02:00
parent c3177b06bf
commit 2c8e259339
2 changed files with 11 additions and 0 deletions

View file

@ -32,6 +32,7 @@ export class ComposerViewModel extends ViewModel {
this._replyVM = this.track(this._roomVM._createTile(entry)); this._replyVM = this.track(this._roomVM._createTile(entry));
} }
this.emitChange("replyViewModel"); this.emitChange("replyViewModel");
this.emit("focus");
} }
} }

View file

@ -25,6 +25,7 @@ export class MessageComposer extends TemplateView {
super(viewModel); super(viewModel);
this._input = null; this._input = null;
this._attachmentPopup = null; this._attachmentPopup = null;
this._focusInput = null;
} }
render(t, vm) { render(t, vm) {
@ -34,6 +35,8 @@ export class MessageComposer extends TemplateView {
onKeydown: e => this._onKeyDown(e), onKeydown: e => this._onKeyDown(e),
onInput: () => vm.setInput(this._input.value), onInput: () => vm.setInput(this._input.value),
}); });
this._focusInput = () => this._input.focus();
this.value.on("focus", this._focusInput);
const replyPreview = t.map(vm => vm.replyViewModel, (rvm, t) => { const replyPreview = t.map(vm => vm.replyViewModel, (rvm, t) => {
const View = rvm && viewClassForEntry(rvm); const View = rvm && viewClassForEntry(rvm);
if (!View) { return null; } if (!View) { return null; }
@ -65,6 +68,13 @@ export class MessageComposer extends TemplateView {
return t.div({ className: "MessageComposer" }, [replyPreview, input]); return t.div({ className: "MessageComposer" }, [replyPreview, input]);
} }
unmount() {
if (this._focusInput) {
this.value.off("focus", this._focusInput);
}
super.unmount();
}
_clearReplyingTo() { _clearReplyingTo() {
this.value.clearReplyingTo(); this.value.clearReplyingTo();
} }