aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvkalev <victor_kalev@brown.edu>2021-11-20 14:11:50 -0500
committervkalev <victor_kalev@brown.edu>2021-11-20 14:11:50 -0500
commit9b5c863f7b88db579fba3ea8f85c43c2562f4289 (patch)
tree922bd343ea439926f2c93cf0e43dd271ac944c6b
parent1fd8d25496d6a52902731cddc21969fe10cb2efa (diff)
fixing undo batch
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index bd72e4af9..4447b7624 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -99,6 +99,7 @@ export class CollectionFreeFormView extends CollectionSubView<PanZoomDocument, P
private _layoutSizeData = observable.map<string, { width?: number, height?: number }>();
private _cachedPool: Map<string, PoolData> = new Map();
private _lastTap = 0;
+ private _batch: UndoManager.Batch | undefined = undefined;
private get isAnnotationOverlay() { return this.props.isAnnotationOverlay; }
private get scaleFieldKey() { return this.props.scaleField || "_viewScale"; }
@@ -449,12 +450,12 @@ export class CollectionFreeFormView extends CollectionSubView<PanZoomDocument, P
document.addEventListener("pointerup", this.onPointerUp);
// if not using a pen and in no ink mode
if (CurrentUserUtils.SelectedTool === InkTool.None) {
- // this._batch = UndoManager.StartBatch("collectionErase");
this._downX = this._lastX = e.pageX;
this._downY = this._lastY = e.pageY;
}
// eraser plus anything else mode
else {
+ this._batch = UndoManager.StartBatch("collectionErase");
this._prevPoint = { X: e.clientX, Y: e.clientY };
e.stopPropagation();
e.preventDefault();
@@ -608,18 +609,13 @@ export class CollectionFreeFormView extends CollectionSubView<PanZoomDocument, P
this.removeEndListeners();
if (CurrentUserUtils.SelectedTool !== InkTool.None) {
if (this._deleteList.length > 0) {
- // Ensuring ink opacity returns to normal if the user undos after deletion.
- this._deleteList.forEach(ink => {
- ink.Document.opacity = 1;
- });
- const batch = UndoManager.StartBatch("collectionErase");
this._deleteList.forEach(ink => {
ink.props.removeDocument?.(ink.props.Document);
});
- batch.end();
}
this._prevPoint = this._currPoint = { X: -1, Y: -1 };
this._deleteList = [];
+ this._batch?.end();
}
}
}
@@ -653,7 +649,7 @@ export class CollectionFreeFormView extends CollectionSubView<PanZoomDocument, P
this._currPoint = { X: e.clientX, Y: e.clientY };
const intersections: DocumentView[] = this.getInkIntersection();
if (intersections.length > 0) {
- intersections.forEach(ink =>{
+ intersections.forEach(ink => {
if (!this._deleteList.includes(ink)) {
this._deleteList.push(ink);
// Lowering ink opacity to give the user a visual indicator of deletion.
@@ -695,8 +691,10 @@ export class CollectionFreeFormView extends CollectionSubView<PanZoomDocument, P
const currPointInkSpace = inkView?.ComponentView?.ptFromScreen?.(this._currPoint);
if (prevPointInkSpace && currPointInkSpace) {
const intersects = new Bezier(array.map(p => ({ x: p.X, y: p.Y }))).intersects(
- { p1: { x: prevPointInkSpace.X, y: prevPointInkSpace.Y },
- p2: { x: currPointInkSpace.X, y: currPointInkSpace.Y } });
+ {
+ p1: { x: prevPointInkSpace.X, y: prevPointInkSpace.Y },
+ p2: { x: currPointInkSpace.X, y: currPointInkSpace.Y }
+ });
if (inkView && intersects.length > 0) inks.push(inkView);
}
}
@@ -878,10 +876,10 @@ export class CollectionFreeFormView extends CollectionSubView<PanZoomDocument, P
.filter(({ pos, size }) => pos && size).map(({ pos, size }) => ({ pos: pos!, size: size! }));
if (measuredDocs.length) {
const ranges = measuredDocs.reduce(({ xrange, yrange }, { pos, size }) => // computes range of content
- ({
- xrange: { min: Math.min(xrange.min, pos.x), max: Math.max(xrange.max, pos.x + (size.width || 0)) },
- yrange: { min: Math.min(yrange.min, pos.y), max: Math.max(yrange.max, pos.y + (size.height || 0)) }
- })
+ ({
+ xrange: { min: Math.min(xrange.min, pos.x), max: Math.max(xrange.max, pos.x + (size.width || 0)) },
+ yrange: { min: Math.min(yrange.min, pos.y), max: Math.max(yrange.max, pos.y + (size.height || 0)) }
+ })
, {
xrange: { min: Number.MAX_VALUE, max: -Number.MAX_VALUE },
yrange: { min: Number.MAX_VALUE, max: -Number.MAX_VALUE }