From 7e0fecbc8cc6f3a93b86419a7ce7abc903ef341e Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Tue, 25 Jul 2017 15:22:10 +0100 Subject: [PATCH] Scroll to the bottom of editor if on last line Make the MessageComposerInput scroll to the bottom if we are on the last line of the contents. fixes https://github.com/vector-im/riot-web/issues/4652 --- .../views/rooms/MessageComposerInput.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index 5e451e07ac..1732d3d26f 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -451,14 +451,20 @@ export default class MessageComposerInput extends React.Component { callback(); } + const textContent = this.state.editorState.getCurrentContent().getPlainText(); + const selection = RichText.selectionStateToTextOffsets( + this.state.editorState.getSelection(), + this.state.editorState.getCurrentContent().getBlocksAsArray()); if (this.props.onContentChanged) { - const textContent = this.state.editorState - .getCurrentContent().getPlainText(); - const selection = RichText.selectionStateToTextOffsets( - this.state.editorState.getSelection(), - this.state.editorState.getCurrentContent().getBlocksAsArray()); this.props.onContentChanged(textContent, selection); } + + // Scroll to the bottom of the editor if the cursor is on the last line of the + // composer. For some reason the editor won't scroll automatically if we paste + // blocks of text in or insert newlines. + if (textContent.slice(selection.start).indexOf("\n") === -1) { + this.refs.editor.refs.editor.scrollTop = this.refs.editor.refs.editor.scrollHeight; + } }); }