From 52de322789cf6a94598fe618cdc2becd1377a566 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 15 Jan 2016 18:31:07 +0000 Subject: [PATCH] Change history scolling so it doesn't interfere with moving between lines, even when those lines are wrapped rather than hard line breaks. --- src/components/views/rooms/MessageComposer.js | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/components/views/rooms/MessageComposer.js b/src/components/views/rooms/MessageComposer.js index 930725570b..c75c3f0a10 100644 --- a/src/components/views/rooms/MessageComposer.js +++ b/src/components/views/rooms/MessageComposer.js @@ -209,23 +209,18 @@ module.exports = React.createClass({ this.sentHistory.push(input); this.onEnter(ev); } - else if (ev.keyCode === KeyCode.UP) { - var input = this.refs.textarea.value; - var offset = this.refs.textarea.selectionStart || 0; - if (ev.ctrlKey || !input.substr(0, offset).match(/\n/)) { - this.sentHistory.next(1); - ev.preventDefault(); - this.resizeInput(); - } - } - else if (ev.keyCode === KeyCode.DOWN) { - var input = this.refs.textarea.value; - var offset = this.refs.textarea.selectionStart || 0; - if (ev.ctrlKey || !input.substr(offset).match(/\n/)) { - this.sentHistory.next(-1); - ev.preventDefault(); - this.resizeInput(); - } + else if (ev.keyCode === KeyCode.UP || ev.keyCode === KeyCode.DOWN) { + var oldSelectionStart = this.refs.textarea.selectionStart; + // Remember the keyboard because React will recycle the synthetic event + var keyCode = ev.keyCode; + // set a callback so we can see if the cursor position changes as + // a result of this event. If it doesn't, we cycle history. + setTimeout(() => { + if (this.refs.textarea.selectionStart == oldSelectionStart) { + this.sentHistory.next(keyCode === KeyCode.UP ? 1 : -1); + this.resizeInput(); + } + }, 0); } if (this.props.tabComplete) {