From 13454f4e669188983b182941ea4241b07e25672d Mon Sep 17 00:00:00 2001 From: Bob Sforza Date: Sat, 17 Dec 2016 01:03:21 -0600 Subject: [PATCH] I'm trying to make an Undo function for canvas drawing, but the issue is, i'm dumb --- src/app/shared/model/whiteboard.service.ts | 2 +- src/app/whiteboard/whiteboard.component.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/app/shared/model/whiteboard.service.ts b/src/app/shared/model/whiteboard.service.ts index efc3857..defa459 100644 --- a/src/app/shared/model/whiteboard.service.ts +++ b/src/app/shared/model/whiteboard.service.ts @@ -67,7 +67,7 @@ export class WhiteboardService { path }; - const whiteboardMarkings = this.af.database.list('whiteboardMarkings/' + key); + const whiteboardMarkings = this.getMarkings(key); return Observable.from([whiteboardMarkings.push(marking)]); } diff --git a/src/app/whiteboard/whiteboard.component.ts b/src/app/whiteboard/whiteboard.component.ts index 7d4b757..07e2c69 100644 --- a/src/app/whiteboard/whiteboard.component.ts +++ b/src/app/whiteboard/whiteboard.component.ts @@ -68,6 +68,7 @@ export class WhiteboardComponent implements OnInit, OnChanges, OnDestroy { if (this.markings) { this.markingsToCanvas(this.markings); } + document.addEventListener('keydown', this.keyboardInput); } ngOnChanges(changes: SimpleChanges) { @@ -224,6 +225,17 @@ export class WhiteboardComponent implements OnInit, OnChanges, OnDestroy { } } + keyboardInput(event: KeyboardEvent) { + if (event.keyCode == 90 && event.ctrlKey) { + window.alert("Undo"); + var newMarks = []; + for (var i = 0; i < (this.markings.length - 1); ++i) { + newMarks[i] = this.markings[i]; + } + this.markingsToCanvas(newMarks); + } + } + cursorPoint(event) { // Return a paper.js point where the mouse is at relative to the canvas const canvasPos = this.canvasEl.getBoundingClientRect();