Fixes media editing undo

Co-authored-by: Josh Perez <60019601+josh-signal@users.noreply.github.com>
This commit is contained in:
automated-signal 2021-12-07 15:19:12 -08:00 committed by GitHub
parent d7edff196c
commit f5665e0e7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -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]);

View File

@ -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 });