From 7776751e799b6a5917d59c8a1cae34a379a23bca Mon Sep 17 00:00:00 2001 From: Jean-Benoist Leger Date: Sat, 18 Apr 2020 16:54:37 +0000 Subject: [PATCH 1/2] undo buffer also in server part for redo --- s_whiteboard.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/s_whiteboard.js b/s_whiteboard.js index bc3b3b2..72a9cf4 100644 --- a/s_whiteboard.js +++ b/s_whiteboard.js @@ -1,6 +1,7 @@ //This file is only for saving the whiteboard. (Not to a file, only to RAM atm. Whiteboard is gone after server restart) var savedBoards = {}; +var savedUndos = {}; module.exports = { handleEventsAndData: function (content) { var tool = content["t"]; //Tool witch is used @@ -8,19 +9,46 @@ module.exports = { var username = content["username"]; if (tool === "clear") { //Clear the whiteboard delete savedBoards[wid]; + delete savedUndos[wid]; } else if (tool === "undo") { //Undo an action + if (!savedUndos[wid]) { + savedUndos[wid] = []; + } if (savedBoards[wid]) { for (var i = savedBoards[wid].length - 1; i >= 0; i--) { if (savedBoards[wid][i]["username"] == username) { var drawId = savedBoards[wid][i]["drawId"]; for (var i = savedBoards[wid].length - 1; i >= 0; i--) { if (savedBoards[wid][i]["drawId"] == drawId && savedBoards[wid][i]["username"] == username) { + savedUndos[wid].push(savedBoards[wid][i]); savedBoards[wid].splice(i, 1); } } break; } } + if(savedUndos[wid].length > 1000) { + savedUndos[wid].splice(0, savedUndos[wid].length - 1000); + } + } + } else if (tool === "redo") { + if (!savedUndos[wid]) { + savedUndos[wid] = []; + } + if (!savedBoards[wid]) { + savedBoards[wid] = []; + } + for (var i = savedUndos[wid].length - 1; i >= 0; i--) { + if (savedUndos[wid][i]["username"] == username) { + var drawId = savedUndos[wid][i]["drawId"]; + for (var i = savedUndos[wid].length - 1; i >= 0; i--) { + if (savedUndos[wid][i]["drawId"] == drawId && savedUndos[wid][i]["username"] == username) { + savedBoards[wid].push(savedUndos[wid][i]); + savedUndos[wid].splice(i, 1); + } + } + break; + } } } else if (["line", "pen", "rect", "circle", "eraser", "addImgBG", "recSelect", "eraseRec", "addTextBox", "setTextboxText", "removeTextbox", "setTextboxPosition", "setTextboxFontSize", "setTextboxFontColor"].includes(tool)) { //Save all this actions if (!savedBoards[wid]) { From 38147618e8c355d53da2f5381d888c8839276b52 Mon Sep 17 00:00:00 2001 From: Jean-Benoist Leger Date: Sat, 18 Apr 2020 16:58:05 +0000 Subject: [PATCH 2/2] typo on README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c920edb..c895ac0 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Result | Windows and Linux | macOS ------ | -------------------- | ------- Clear the whiteboard | Ctrl + Shift + Z | Command + Shift + Z Undo your last step | Ctrl + Z | Command + Z -Redo your last undo | Ctrl + Shift + Z | Command + + Shift + Z +Redo your last undo | Ctrl + Shift + Z | Command + Shift + Z Select an area | Ctrl + X | Command + X Take the mouse | Ctrl + M | Command + M Take the pen | Ctrl + P | Command + P