Skip to content

Commit 09f2ce8

Browse files
author
HarshKhandeparkar
committed
fix: change snapshot order
1 parent 3e1f815 commit 09f2ce8

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

src/renderers/RealDrawBoard/RealDrawBoard.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ export class RealDrawBoard extends RealRenderer {
104104
this.canvas.addEventListener('mousemove', this._mouseMoveEventListener);
105105
this._isStroking = true;
106106

107+
if (this._currentSnapshotIndex < this._snapshots.length - 1 && this._maxSnapshots > 0) this._snapshots.splice(this._currentSnapshotIndex + 1); // Delete all redo snapshots
108+
107109
this._startStroke(
108110
this._getMouseCoords(e),
109111
'mouse'
@@ -118,7 +120,14 @@ export class RealDrawBoard extends RealRenderer {
118120
this._isStroking = false;
119121

120122
this._display(this.graphPixels);
123+
121124
this.canvas.removeEventListener('mousemove', this._mouseMoveEventListener);
125+
126+
if (this._maxSnapshots > 0) this._snapshots[++this._currentSnapshotIndex] = this.getData(); // Take snapshot
127+
if (this._snapshots.length > this._maxSnapshots) {
128+
this._snapshots.shift();
129+
this._currentSnapshotIndex--;
130+
}
122131
}
123132
}
124133

@@ -152,6 +161,8 @@ export class RealDrawBoard extends RealRenderer {
152161
for (let i = 0; i < e.touches.length; i++) {
153162
this._isStroking = true;
154163

164+
if (this._currentSnapshotIndex < this._snapshots.length - 1 && this._maxSnapshots > 0) this._snapshots.splice(this._currentSnapshotIndex + 1); // Delete all redo snapshots
165+
155166
this._startStroke(
156167
this._getTouchCoords(e.touches.item(i)),
157168
e.touches.item(i).identifier.toString()
@@ -168,6 +179,12 @@ export class RealDrawBoard extends RealRenderer {
168179

169180
this._isStroking = false;
170181
}
182+
183+
if (this._maxSnapshots > 0) this._snapshots[++this._currentSnapshotIndex] = this.getData(); // Take snapshot
184+
if (this._snapshots.length > this._maxSnapshots) {
185+
this._snapshots.shift();
186+
this._currentSnapshotIndex--;
187+
}
171188
}
172189

173190
_touchMoveEventListener = (e: TouchEvent) => {

src/renderers/RealDrawBoard/tools/brush.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export function _startStroke(
99
identifier: string
1010
) {
1111
this._doPreview = false;
12-
if (this._currentSnapshotIndex < this._snapshots.length - 1 && this._maxSnapshots > 0) this._snapshots.splice(this._currentSnapshotIndex + 1); // Delete all redo snapshots
1312
this._plot(coords[0], coords[1], this.brushSize, this.brushColor);
1413

1514
this._lastCoords.set(identifier, coords);
@@ -24,12 +23,6 @@ export function _endStroke(
2423

2524
this._lastCoords.delete(identifier);
2625

27-
if (this._maxSnapshots > 0) this._snapshots[++this._currentSnapshotIndex] = this.getData();
28-
if (this._snapshots.length > this._maxSnapshots) {
29-
this._snapshots.shift();
30-
this._currentSnapshotIndex--;
31-
}
32-
3326
this._doPreview = true;
3427
}
3528

src/renderers/RealDrawBoard/tools/eraser.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export function _startStroke(
99
identifier: string
1010
) {
1111
this._doPreview = false;
12-
if (this._currentSnapshotIndex < this._snapshots.length - 1 && this._maxSnapshots > 0) this._snapshots.splice(this._currentSnapshotIndex + 1); // Delete all redo snapshots
1312
this._plot(coords[0], coords[1], this.eraserSize, this.bgColor);
1413

1514
this._lastCoords.set(identifier, coords);
@@ -24,12 +23,6 @@ export function _endStroke(
2423
this._plot(endCoords[0], endCoords[1], this.eraserSize, this.bgColor);
2524

2625
this._lastCoords.delete(identifier);
27-
28-
if (this._maxSnapshots > 0) this._snapshots[++this._currentSnapshotIndex] = this.getData();
29-
if (this._snapshots.length > this._maxSnapshots) {
30-
this._snapshots.shift();
31-
this._currentSnapshotIndex--;
32-
}
3326
}
3427

3528
export function _doStroke(

src/renderers/RealDrawBoard/tools/line.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export function _startStroke(
1313
coords: [number, number],
1414
identifier: string
1515
) {
16-
if (this._currentSnapshotIndex < this._snapshots.length - 1 && this._maxSnapshots > 0) this._snapshots.splice(this._currentSnapshotIndex + 1); // Delete all redo snapshots
1716
this._plot(coords[0], coords[1], this.brushSize, this.brushColor);
1817

1918
this._lastCoords.set(identifier, coords);

0 commit comments

Comments
 (0)