diff options
Diffstat (limited to 'src/client/views/InkingCanvas.tsx')
-rw-r--r-- | src/client/views/InkingCanvas.tsx | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/client/views/InkingCanvas.tsx b/src/client/views/InkingCanvas.tsx index 45ca52d00..fed349af3 100644 --- a/src/client/views/InkingCanvas.tsx +++ b/src/client/views/InkingCanvas.tsx @@ -10,6 +10,7 @@ import "./InkingCanvas.scss"; import { InkingControl } from "./InkingControl"; import { InkingStroke } from "./InkingStroke"; import React = require("react"); +import { undoBatch, UndoManager } from "../util/UndoManager"; interface InkCanvasProps { getScreenTransform: () => Transform; @@ -19,6 +20,8 @@ interface InkCanvasProps { @observer export class InkingCanvas extends React.Component<InkCanvasProps> { + private strokeBatch?: UndoManager.Batch; + maxCanvasDim = 8192 / 2; // 1/2 of the maximum canvas dimension for Chrome @observable inkMidX: number = 0; @observable inkMidY: number = 0; @@ -59,6 +62,7 @@ export class InkingCanvas extends React.Component<InkCanvasProps> { if (e.button != 0 || e.altKey || e.ctrlKey || InkingControl.Instance.selectedTool === InkTool.None) { return; } + document.addEventListener("pointermove", this.onPointerMove, true); document.addEventListener("pointerup", this.onPointerUp, true); e.stopPropagation(); @@ -67,6 +71,7 @@ export class InkingCanvas extends React.Component<InkCanvasProps> { if (InkingControl.Instance.selectedTool != InkTool.Eraser) { // start the new line, saves a uuid to represent the field of the stroke this._currentStrokeId = Utils.GenerateGuid(); + this.strokeBatch = UndoManager.StartBatch("drawing stroke"); this.inkData.set(this._currentStrokeId, { pathData: [this.relativeCoordinatesForEvent(e.clientX, e.clientY)], color: InkingControl.Instance.selectedColor, @@ -74,8 +79,9 @@ export class InkingCanvas extends React.Component<InkCanvasProps> { tool: InkingControl.Instance.selectedTool, page: this.props.Document.GetNumber(KeyStore.CurPage, -1) }); + this.strokeBatch.end(); } - } + }; @action onPointerUp = (e: PointerEvent): void => { @@ -103,13 +109,14 @@ export class InkingCanvas extends React.Component<InkCanvasProps> { } this.inkData = data; } - } + }; relativeCoordinatesForEvent = (ex: number, ey: number): { x: number, y: number } => { let [x, y] = this.props.getScreenTransform().transformPoint(ex, ey); return { x, y }; } + @undoBatch @action removeLine = (id: string): void => { let data = this.inkData; |