Skip to content

Commit

Permalink
I'm trying to make an Undo function for canvas drawing, but the issue…
Browse files Browse the repository at this point in the history
… is, i'm dumb
  • Loading branch information
rpsforza committed Dec 17, 2016
1 parent a4a5171 commit 13454f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/app/shared/model/whiteboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)]);
}

Expand Down
12 changes: 12 additions & 0 deletions src/app/whiteboard/whiteboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 13454f4

Please sign in to comment.