Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 897d18b

Browse files
authored
Merge pull request #2093 from matrix-org/t3chguy/slate_cont2
Fix composer bug where cursor position would change when Riot regained focus
2 parents 8a99c71 + f264075 commit 897d18b

File tree

1 file changed

+8
-24
lines changed

1 file changed

+8
-24
lines changed

src/components/views/rooms/MessageComposerInput.js

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,16 +1255,14 @@ export default class MessageComposerInput extends React.Component {
12551255

12561256
let editorState;
12571257
const historyItem = this.historyManager.getItem(delta);
1258-
if (historyItem) {
1259-
if (historyItem.format === 'rich' && !this.state.isRichTextEnabled) {
1260-
editorState = this.richToMdEditorState(historyItem.value);
1261-
}
1262-
else if (historyItem.format === 'markdown' && this.state.isRichTextEnabled) {
1263-
editorState = this.mdToRichEditorState(historyItem.value);
1264-
}
1265-
else {
1266-
editorState = historyItem.value;
1267-
}
1258+
if (!historyItem) return;
1259+
1260+
if (historyItem.format === 'rich' && !this.state.isRichTextEnabled) {
1261+
editorState = this.richToMdEditorState(historyItem.value);
1262+
} else if (historyItem.format === 'markdown' && this.state.isRichTextEnabled) {
1263+
editorState = this.mdToRichEditorState(historyItem.value);
1264+
} else {
1265+
editorState = historyItem.value;
12681266
}
12691267

12701268
// Move selection to the end of the selected history
@@ -1544,18 +1542,6 @@ export default class MessageComposerInput extends React.Component {
15441542
this.handleKeyCommand('toggle-mode');
15451543
};
15461544

1547-
onBlur = (e) => {
1548-
this.selection = this.state.editorState.selection;
1549-
};
1550-
1551-
onFocus = (e) => {
1552-
if (this.selection) {
1553-
const change = this.state.editorState.change().select(this.selection);
1554-
this.onChange(change);
1555-
delete this.selection;
1556-
}
1557-
};
1558-
15591545
focusComposer = () => {
15601546
this.refs.editor.focus();
15611547
};
@@ -1601,8 +1587,6 @@ export default class MessageComposerInput extends React.Component {
16011587
onChange={this.onChange}
16021588
onKeyDown={this.onKeyDown}
16031589
onPaste={this.onPaste}
1604-
onBlur={this.onBlur}
1605-
onFocus={this.onFocus}
16061590
renderNode={this.renderNode}
16071591
renderMark={this.renderMark}
16081592
// disable spell check for the placeholder because browsers don't like "unencrypted"

0 commit comments

Comments
 (0)