From 2ed5d89c9fca8f4449b1cc32f8aa72dcfe39cb5a Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 20 Jan 2020 12:20:21 +0000 Subject: [PATCH 1/2] Fix arrows keys moving through edit history Different fix that fixes https://github.com/vector-im/riot-web/issues/11817 by setting the flag before the callback rather than having the update method set the flag. Regressed in https://github.com/matrix-org/matrix-react-sdk/pull/3842 Fixes https://github.com/vector-im/riot-web/issues/11917 --- src/components/views/rooms/BasicMessageComposer.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/views/rooms/BasicMessageComposer.js b/src/components/views/rooms/BasicMessageComposer.js index 15a7c29e3a..e54396a9ed 100644 --- a/src/components/views/rooms/BasicMessageComposer.js +++ b/src/components/views/rooms/BasicMessageComposer.js @@ -126,7 +126,6 @@ export default class BasicMessageEditor extends React.Component { } _updateEditorState = (selection, inputType, diff) => { - this._modifiedFlag = true; renderModel(this._editorRef, this.props.model); if (selection) { // set the caret/selection try { @@ -212,6 +211,7 @@ export default class BasicMessageEditor extends React.Component { if (type === "cut") { // Remove the text, updating the model as appropriate replaceRangeAndMoveCaret(range, []); + this._modifiedFlag = true; } event.preventDefault(); } @@ -238,6 +238,7 @@ export default class BasicMessageEditor extends React.Component { const text = event.clipboardData.getData("text/plain"); parts = parsePlainTextMessage(text, partCreator); } + this._modifiedFlag = true; const range = getRangeForSelection(this._editorRef, model, document.getSelection()); replaceRangeAndMoveCaret(range, parts); event.preventDefault(); @@ -248,6 +249,7 @@ export default class BasicMessageEditor extends React.Component { if (this._isIMEComposing) { return; } + this._modifiedFlag = true; const sel = document.getSelection(); const {caret, text} = getCaretOffsetAndText(this._editorRef, sel); 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 newText = text.substr(0, caret.offset) + textToInsert + text.substr(caret.offset); caret.offset += textToInsert.length; + this._modifiedFlag = true; this.props.model.update(newText, inputType, caret); } From 277f10792481d78881695df9af30f8a9e3ddb265 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 20 Jan 2020 13:03:09 +0000 Subject: [PATCH 2/2] Set flag before mutating on cut too --- src/components/views/rooms/BasicMessageComposer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/rooms/BasicMessageComposer.js b/src/components/views/rooms/BasicMessageComposer.js index e54396a9ed..94904242c3 100644 --- a/src/components/views/rooms/BasicMessageComposer.js +++ b/src/components/views/rooms/BasicMessageComposer.js @@ -210,8 +210,8 @@ export default class BasicMessageEditor extends React.Component { event.clipboardData.setData("application/x-riot-composer", JSON.stringify(selectedParts)); if (type === "cut") { // Remove the text, updating the model as appropriate - replaceRangeAndMoveCaret(range, []); this._modifiedFlag = true; + replaceRangeAndMoveCaret(range, []); } event.preventDefault(); }