From 9dac91a70d81a41db03fe3b3018cc8ec50739757 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 5 Sep 2019 15:34:42 +0200 Subject: [PATCH] ensure step before formatting is persisted in undo history --- src/components/views/rooms/BasicMessageComposer.js | 1 + src/editor/history.js | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/views/rooms/BasicMessageComposer.js b/src/components/views/rooms/BasicMessageComposer.js index 36e142c0ea..8f4d05c446 100644 --- a/src/components/views/rooms/BasicMessageComposer.js +++ b/src/components/views/rooms/BasicMessageComposer.js @@ -437,6 +437,7 @@ export default class BasicMessageEditor extends React.Component { if (range.length === 0) { return; } + this.historyManager.ensureLastChangesPushed(this.props.model); switch (action) { case "bold": formatInline(range, "**"); diff --git a/src/editor/history.js b/src/editor/history.js index de052cf682..d66def4704 100644 --- a/src/editor/history.js +++ b/src/editor/history.js @@ -106,6 +106,12 @@ export default class HistoryManager { return shouldPush; } + ensureLastChangesPushed(model) { + if (this._changedSinceLastPush) { + this._pushState(model, this._lastCaret); + } + } + canUndo() { return this._currentIndex >= 1 || this._changedSinceLastPush; } @@ -117,9 +123,7 @@ export default class HistoryManager { // returns state that should be applied to model undo(model) { if (this.canUndo()) { - if (this._changedSinceLastPush) { - this._pushState(model, this._lastCaret); - } + this.ensureLastChangesPushed(model); this._currentIndex -= 1; return this._stack[this._currentIndex]; }