Fixes media editing undo
Co-authored-by: Josh Perez <60019601+josh-signal@users.noreply.github.com>
This commit is contained in:
parent
d7edff196c
commit
f5665e0e7b
|
@ -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…
Reference in New Issue