From 58301e5dd455e4f992a1a4feb107f1224f155329 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 10 Jul 2018 10:28:17 +0100 Subject: [PATCH] navigateHistory only when at edges of document, to prevent Firefox bug Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../views/rooms/MessageComposerInput.js | 39 ++++--------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index 24834d01d7..0f0d8787d6 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -1140,41 +1140,18 @@ export default class MessageComposerInput extends React.Component { // Select history only if we are not currently auto-completing if (this.autocomplete.state.completionList.length === 0) { + const selection = this.state.editorState.selection; - // determine whether our cursor is at the top or bottom of the multiline - // input box by just looking at the position of the plain old DOM selection. - const selection = window.getSelection(); - const range = selection.getRangeAt(0); - const cursorRect = range.getBoundingClientRect(); + // selection must be collapsed + if (!selection.isCollapsed) return; + const document = this.state.editorState.document; - const editorNode = ReactDOM.findDOMNode(this.refs.editor); - const editorRect = editorNode.getBoundingClientRect(); - - // heuristic to handle tall emoji, pills, etc pushing the cursor away from the top - // or bottom of the page. - // XXX: is this going to break on large inline images or top-to-bottom scripts? - const EDGE_THRESHOLD = 15; - - let navigateHistory = false; + // and we must be at the edge of the document (up=start, down=end) if (up) { - const scrollCorrection = editorNode.scrollTop; - const distanceFromTop = cursorRect.top - editorRect.top + scrollCorrection; - console.log(`Cursor distance from editor top is ${distanceFromTop}`); - if (distanceFromTop < EDGE_THRESHOLD) { - navigateHistory = true; - } + if (!selection.isAtStartOf(document)) return; + } else { + if (!selection.isAtEndOf(document)) return; } - else { - const scrollCorrection = - editorNode.scrollHeight - editorNode.clientHeight - editorNode.scrollTop; - const distanceFromBottom = editorRect.bottom - cursorRect.bottom + scrollCorrection; - console.log(`Cursor distance from editor bottom is ${distanceFromBottom}`); - if (distanceFromBottom < EDGE_THRESHOLD) { - navigateHistory = true; - } - } - - if (!navigateHistory) return; const selected = this.selectHistory(up); if (selected) {