Skip to content

Commit

Permalink
[bug-fix] multiple image position and history fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lencyforce committed Apr 30, 2020
1 parent 73c8c4b commit fcd50a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
15 changes: 9 additions & 6 deletions image-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,18 @@ class ImageHandlers {
}
}

if(appliedDeltas && appliedDeltas.length !== 0) {
if(typeof(appliedDeltas) !== 'undefined') {
if(appliedDeltas && appliedDeltas.length !== 0) {

let composedAppliedDelta = new Delta();
let composedAppliedDelta = new Delta();

appliedDeltas.forEach((delta) => {
composedAppliedDelta = composedAppliedDelta.compose(delta);
});
appliedDeltas.forEach((delta) => {
composedAppliedDelta = composedAppliedDelta.compose(delta);
});

changeDelta = composedAppliedDelta.transform(changeDelta);
}

changeDelta = composedAppliedDelta.transform(changeDelta);
appliedDeltas.push(changeDelta);
}

Expand Down
9 changes: 4 additions & 5 deletions modules/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ class History {
this.editor = editor;
this.editor.on(EditorEvents.editorTextChanged, ({delta, oldDelta}) => {
let self = this;
// Wait for local fixing delta to be applied in this cycle before get quill content in record function.
setTimeout(() => {
self.record(delta, oldDelta);
}, 1);
self.record(delta, oldDelta);
});

this.quill.keyboard.addBinding({ key: 'Z', shortKey: true }, this.undo.bind(this));
Expand Down Expand Up @@ -62,7 +59,9 @@ class History {

if (changeDelta.ops.length === 0) return;
this.stack.redo = [];
let undoDelta = this.editor.getEditorContents().diff(oldDelta);

let editorContents = this.editor.getEditorContents();
let undoDelta = editorContents.diff(oldDelta);
let timestamp = Date.now();
if (this.lastRecorded + this.options.delay > timestamp && this.stack.undo.length > 0) {
let delta = this.stack.undo.pop();
Expand Down

0 comments on commit fcd50a2

Please sign in to comment.