Fixes media editing undo
This commit is contained in:
parent
d9990c162e
commit
e81821f4a6
2 changed files with 18 additions and 1 deletions
|
@ -167,6 +167,8 @@ export const MediaEditor = ({
|
|||
[
|
||||
ev => ev.key === 'Escape',
|
||||
() => {
|
||||
setEditMode(undefined);
|
||||
|
||||
if (fabricCanvas.getActiveObject()) {
|
||||
fabricCanvas.discardActiveObject();
|
||||
fabricCanvas.requestRenderAll();
|
||||
|
@ -294,10 +296,25 @@ export const MediaEditor = ({
|
|||
});
|
||||
}
|
||||
|
||||
function handleMouseup(ev: MouseEvent): void {
|
||||
if (
|
||||
ev.target instanceof HTMLCanvasElement ||
|
||||
ev.target instanceof HTMLButtonElement
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
setEditMode(undefined);
|
||||
ev.stopPropagation();
|
||||
ev.preventDefault();
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', handleKeydown);
|
||||
document.addEventListener('mouseup', handleMouseup);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('keydown', handleKeydown);
|
||||
document.removeEventListener('mouseup', handleMouseup);
|
||||
};
|
||||
}, [fabricCanvas, history]);
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ export class FabricHistory extends EventEmitter {
|
|||
}
|
||||
|
||||
if (this.canRedo()) {
|
||||
this.snapshots.splice(this.highWatermark, this.snapshots.length);
|
||||
this.snapshots.splice(this.highWatermark + 1, this.snapshots.length);
|
||||
}
|
||||
|
||||
this.snapshots.push({ canvasState: this.getState(), imageState });
|
||||
|
|
Loading…
Add table
Reference in a new issue