diff --git a/src/domain/session/room/ComposerViewModel.js b/src/domain/session/room/ComposerViewModel.js index 240e7d4c..ba4627ca 100644 --- a/src/domain/session/room/ComposerViewModel.js +++ b/src/domain/session/room/ComposerViewModel.js @@ -32,6 +32,7 @@ export class ComposerViewModel extends ViewModel { this._replyVM = this.track(this._roomVM._createTile(entry)); } this.emitChange("replyViewModel"); + this.emit("focus"); } } diff --git a/src/platform/web/ui/session/room/MessageComposer.js b/src/platform/web/ui/session/room/MessageComposer.js index 5a6ba593..e1d8f13c 100644 --- a/src/platform/web/ui/session/room/MessageComposer.js +++ b/src/platform/web/ui/session/room/MessageComposer.js @@ -25,6 +25,7 @@ export class MessageComposer extends TemplateView { super(viewModel); this._input = null; this._attachmentPopup = null; + this._focusInput = null; } render(t, vm) { @@ -34,6 +35,8 @@ export class MessageComposer extends TemplateView { onKeydown: e => this._onKeyDown(e), 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 View = rvm && viewClassForEntry(rvm); if (!View) { return null; } @@ -65,6 +68,13 @@ export class MessageComposer extends TemplateView { return t.div({ className: "MessageComposer" }, [replyPreview, input]); } + unmount() { + if (this._focusInput) { + this.value.off("focus", this._focusInput); + } + super.unmount(); + } + _clearReplyingTo() { this.value.clearReplyingTo(); }