Merge pull request #1248 from matrix-org/luke/fix-rte-auto-scroll
Scroll to the bottom of editor if on last line
This commit is contained in:
commit
9cb28ff33c
1 changed files with 11 additions and 5 deletions
|
@ -451,14 +451,20 @@ export default class MessageComposerInput extends React.Component {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.props.onContentChanged) {
|
const textContent = this.state.editorState.getCurrentContent().getPlainText();
|
||||||
const textContent = this.state.editorState
|
|
||||||
.getCurrentContent().getPlainText();
|
|
||||||
const selection = RichText.selectionStateToTextOffsets(
|
const selection = RichText.selectionStateToTextOffsets(
|
||||||
this.state.editorState.getSelection(),
|
this.state.editorState.getSelection(),
|
||||||
this.state.editorState.getCurrentContent().getBlocksAsArray());
|
this.state.editorState.getCurrentContent().getBlocksAsArray());
|
||||||
|
if (this.props.onContentChanged) {
|
||||||
this.props.onContentChanged(textContent, selection);
|
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;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue