mirror of
https://github.com/element-hq/element-web
synced 2024-11-24 18:25:49 +03:00
Merge pull request #3391 from matrix-org/bwindels/cider-format-history
New composer: ensure undo history is persisted before applying formatting
This commit is contained in:
commit
5014b606db
2 changed files with 8 additions and 3 deletions
|
@ -454,6 +454,7 @@ export default class BasicMessageEditor extends React.Component {
|
||||||
if (range.length === 0) {
|
if (range.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.historyManager.ensureLastChangesPushed(this.props.model);
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case "bold":
|
case "bold":
|
||||||
formatInline(range, "**");
|
formatInline(range, "**");
|
||||||
|
|
|
@ -106,6 +106,12 @@ export default class HistoryManager {
|
||||||
return shouldPush;
|
return shouldPush;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ensureLastChangesPushed(model) {
|
||||||
|
if (this._changedSinceLastPush) {
|
||||||
|
this._pushState(model, this._lastCaret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
canUndo() {
|
canUndo() {
|
||||||
return this._currentIndex >= 1 || this._changedSinceLastPush;
|
return this._currentIndex >= 1 || this._changedSinceLastPush;
|
||||||
}
|
}
|
||||||
|
@ -117,9 +123,7 @@ export default class HistoryManager {
|
||||||
// returns state that should be applied to model
|
// returns state that should be applied to model
|
||||||
undo(model) {
|
undo(model) {
|
||||||
if (this.canUndo()) {
|
if (this.canUndo()) {
|
||||||
if (this._changedSinceLastPush) {
|
this.ensureLastChangesPushed(model);
|
||||||
this._pushState(model, this._lastCaret);
|
|
||||||
}
|
|
||||||
this._currentIndex -= 1;
|
this._currentIndex -= 1;
|
||||||
return this._stack[this._currentIndex];
|
return this._stack[this._currentIndex];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue