From 664f3acc3cd0c6d5fc0d351cb3f249dcb05813b7 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Tue, 4 Jul 2017 10:12:06 +0100 Subject: [PATCH] Only move through history if caret at start or end of line As suggested by @dbkr (because this is what we do for the old composer), only move through history when the caret is that the beginning of the first line (block) or end of the last. This has the nice property of being able to move the caret up to a really long message: fixes https://github.com/vector-im/riot-web/issues/4471 --- src/components/views/rooms/MessageComposerInput.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index 294cbdb84c..818c108211 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -640,17 +640,16 @@ export default class MessageComposerInput extends React.Component { const firstBlock = this.state.editorState.getCurrentContent().getFirstBlock(); const lastBlock = this.state.editorState.getCurrentContent().getLastBlock(); - const selectionOffset = selection.getAnchorOffset(); let canMoveUp = false; let canMoveDown = false; if (blockKey === firstBlock.getKey()) { - const textBeforeCursor = firstBlock.getText().slice(0, selectionOffset); - canMoveUp = textBeforeCursor.indexOf('\n') === -1; + canMoveUp = selection.getStartOffset() === selection.getEndOffset() && + selection.getStartOffset() === 0; } if (blockKey === lastBlock.getKey()) { - const textAfterCursor = lastBlock.getText().slice(selectionOffset); - canMoveDown = textAfterCursor.indexOf('\n') === -1; + canMoveDown = selection.getStartOffset() === selection.getEndOffset() && + selection.getStartOffset() === lastBlock.getText().length; } if ((up && !canMoveUp) || (!up && !canMoveDown)) return;