Merge pull request #3874 from matrix-org/dbkr/fix_editor_modified_flag_2

Fix arrows keys moving through edit history
This commit is contained in:
David Baker 2020-01-20 13:42:44 +00:00 committed by GitHub
commit a849826a41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -126,7 +126,6 @@ export default class BasicMessageEditor extends React.Component {
} }
_updateEditorState = (selection, inputType, diff) => { _updateEditorState = (selection, inputType, diff) => {
this._modifiedFlag = true;
renderModel(this._editorRef, this.props.model); renderModel(this._editorRef, this.props.model);
if (selection) { // set the caret/selection if (selection) { // set the caret/selection
try { try {
@ -211,6 +210,7 @@ export default class BasicMessageEditor extends React.Component {
event.clipboardData.setData("application/x-riot-composer", JSON.stringify(selectedParts)); event.clipboardData.setData("application/x-riot-composer", JSON.stringify(selectedParts));
if (type === "cut") { if (type === "cut") {
// Remove the text, updating the model as appropriate // Remove the text, updating the model as appropriate
this._modifiedFlag = true;
replaceRangeAndMoveCaret(range, []); replaceRangeAndMoveCaret(range, []);
} }
event.preventDefault(); event.preventDefault();
@ -238,6 +238,7 @@ export default class BasicMessageEditor extends React.Component {
const text = event.clipboardData.getData("text/plain"); const text = event.clipboardData.getData("text/plain");
parts = parsePlainTextMessage(text, partCreator); parts = parsePlainTextMessage(text, partCreator);
} }
this._modifiedFlag = true;
const range = getRangeForSelection(this._editorRef, model, document.getSelection()); const range = getRangeForSelection(this._editorRef, model, document.getSelection());
replaceRangeAndMoveCaret(range, parts); replaceRangeAndMoveCaret(range, parts);
event.preventDefault(); event.preventDefault();
@ -248,6 +249,7 @@ export default class BasicMessageEditor extends React.Component {
if (this._isIMEComposing) { if (this._isIMEComposing) {
return; return;
} }
this._modifiedFlag = true;
const sel = document.getSelection(); const sel = document.getSelection();
const {caret, text} = getCaretOffsetAndText(this._editorRef, sel); const {caret, text} = getCaretOffsetAndText(this._editorRef, sel);
this.props.model.update(text, event.inputType, caret); this.props.model.update(text, event.inputType, caret);
@ -258,6 +260,7 @@ export default class BasicMessageEditor extends React.Component {
const {caret, text} = getCaretOffsetAndText(this._editorRef, sel); const {caret, text} = getCaretOffsetAndText(this._editorRef, sel);
const newText = text.substr(0, caret.offset) + textToInsert + text.substr(caret.offset); const newText = text.substr(0, caret.offset) + textToInsert + text.substr(caret.offset);
caret.offset += textToInsert.length; caret.offset += textToInsert.length;
this._modifiedFlag = true;
this.props.model.update(newText, inputType, caret); this.props.model.update(newText, inputType, caret);
} }