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',
|
ev => ev.key === 'Escape',
|
||||||
() => {
|
() => {
|
||||||
|
setEditMode(undefined);
|
||||||
|
|
||||||
if (fabricCanvas.getActiveObject()) {
|
if (fabricCanvas.getActiveObject()) {
|
||||||
fabricCanvas.discardActiveObject();
|
fabricCanvas.discardActiveObject();
|
||||||
fabricCanvas.requestRenderAll();
|
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('keydown', handleKeydown);
|
||||||
|
document.addEventListener('mouseup', handleMouseup);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener('keydown', handleKeydown);
|
document.removeEventListener('keydown', handleKeydown);
|
||||||
|
document.removeEventListener('mouseup', handleMouseup);
|
||||||
};
|
};
|
||||||
}, [fabricCanvas, history]);
|
}, [fabricCanvas, history]);
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ export class FabricHistory extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.canRedo()) {
|
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 });
|
this.snapshots.push({ canvasState: this.getState(), imageState });
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue