From 46f2e1eb616a51d56771763784952f911e4142a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florentin=20Schleu=C3=9F?= <27809595+macbrayne@users.noreply.github.com> Date: Sun, 5 Jul 2020 13:46:53 +0200 Subject: [PATCH 1/6] Started development on history integration Switched TextBox from using mutations for setting the content to actions for injecting history manipulation properly --- core/src/components/objects/TextBox.vue | 2 +- core/src/vuex/vuex.js | 56 ++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/core/src/components/objects/TextBox.vue b/core/src/components/objects/TextBox.vue index 842a3c25..01ed6645 100644 --- a/core/src/components/objects/TextBox.vue +++ b/core/src/components/objects/TextBox.vue @@ -45,7 +45,7 @@ export default { }, content: { set(content) { - this.$store.commit("setTextBoxContent", { id: this.id, content }, {module: "core" }); + this.$store.dispatch("setTextBoxContent", { id: this.id, content, ignoreHistory: false }); }, get() { return this.textBox.content; diff --git a/core/src/vuex/vuex.js b/core/src/vuex/vuex.js index 1c400aad..5e7e030b 100644 --- a/core/src/vuex/vuex.js +++ b/core/src/vuex/vuex.js @@ -35,6 +35,15 @@ export default { scrollOffsetY: 0, scale: 1, }, + historyStep: 0, + history: [ + { + location: 0, + type: "textBox", + oldValue: "Test", + newValue: "Neu" + } + ], navbarHeight: 10, pencils: [ { @@ -103,7 +112,7 @@ export default { state.loadedPage.scrollOffsetY = options.y; document.getElementsByClassName("PageContainer")[0].scrollTop = options.y * state.loadedPage.scale; }else { - console.log("no scroll y") + console.log("no scroll y"); } }, setScale(state, options) { @@ -163,6 +172,18 @@ export default { state.loadedPage.objects.textBoxes[state.focuseObjectId].quill.format(options.format, options.value, "user"); } }, + // History + pushHistory(state, action) { + state.history.push(action); + }, + clearHistory(state, index) { + for(let i = 0; i > index; i--) { + state.history.pop(); + } + }, + setHistoryStep(state, historyStep) { + state.historyStep = historyStep; + } }, getters: { // Page @@ -206,5 +227,38 @@ export default { pointerUp: function({ commit }) { commit("setPointer", {down: false, x: false, y: false, pressure: false,}); }, + pushHistory({commit, state}, action) { + const isHistoryDirty = () => state.historyStep < 0; + + if (isHistoryDirty()) { + commit("clearHistory", state.historyStep); + } + commit("pushHistory", action); + }, + restoreHistory({commit, state}, delta) { + let historyIndex = state.history.length - state.historyStep + delta; + console.log(state.history); + console.log(historyIndex); + let historyObject = state.history[historyIndex]; + console.log(historyObject); + switch (historyObject.type) { + case "textBox": + this.dispatch("setTextBoxContent", { id: historyObject.location, content: delta < 1 ? historyObject.oldValue : historyObject.newValue, ignoreHistory: true }); + break; + } + commit("setHistoryStep", historyIndex); + }, + setTextBoxContent({commit, state}, options) { + if (!options.ignoreHistory) { + this.dispatch("pushHistory", { + type: "textBox", + location: options.id, + newValue: options.content, + oldValue: state.loadedPage.objects.textBoxes[options.id].content + }); + } + + commit("setTextBoxContent", options, {module: "core"}); + } } }; From 76de55f917a51a1911540022f4c5e897f01f5966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florentin=20Schleu=C3=9F?= <27809595+macbrayne@users.noreply.github.com> Date: Sun, 5 Jul 2020 13:47:47 +0200 Subject: [PATCH 2/6] Added a undo and a redo button to the View tab --- core/src/components/navbar/Tab3/ZoomControl.vue | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/components/navbar/Tab3/ZoomControl.vue b/core/src/components/navbar/Tab3/ZoomControl.vue index 3e759a13..cfe0487e 100644 --- a/core/src/components/navbar/Tab3/ZoomControl.vue +++ b/core/src/components/navbar/Tab3/ZoomControl.vue @@ -1,5 +1,11 @@