From 5c21efe09d9dbe4cd8ef50423581ef946e3647a2 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 12 Jun 2015 16:37:43 +0930 Subject: [PATCH] Move between title/post inputs with return and backspace keys --- .../src/components/discussion-composer.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/js/forum/src/components/discussion-composer.js b/js/forum/src/components/discussion-composer.js index eb987b48f..3703b156e 100644 --- a/js/forum/src/components/discussion-composer.js +++ b/js/forum/src/components/discussion-composer.js @@ -41,12 +41,32 @@ export default class DiscussionComposer extends ComposerBody { if (empty) { $this.val(''); } }); setTimeout(() => $(element).trigger('input')); + }, + onkeydown: (e) => { + if (e.which === 13) { // return + e.preventDefault(); + this.editor.setSelectionRange(0, 0); + } + m.redraw.strategy('none'); } }))); return items; } + onload(element) { + super.onload(element); + + this.editor.$('textarea').keydown((e) => { + if (e.which === 8 && e.target.selectionStart == 0 && e.target.selectionEnd == 0) { // Backspace + e.preventDefault(); + var title = this.$(':input:enabled:visible:first')[0]; + title.focus(); + title.selectionStart = title.selectionEnd = title.value.length; + } + }); + } + preventExit() { return (this.title() || this.content()) && !confirm(this.props.confirmExit); }