From: Adam Dullage Date: Tue, 19 Sep 2023 07:22:53 +0000 (+0100) Subject: Only confirm cancellation when there are changes X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=49911c73e3feb2bf0eb7a715805642a488e2c69e;p=flatnotes.git Only confirm cancellation when there are changes --- diff --git a/flatnotes/src/components/NoteViewerEditor.vue b/flatnotes/src/components/NoteViewerEditor.vue index 215ff60..8d6c5b1 100644 --- a/flatnotes/src/components/NoteViewerEditor.vue +++ b/flatnotes/src/components/NoteViewerEditor.vue @@ -60,7 +60,7 @@ v-if="editMode == true" type="button" class="bttn" - @click="cancelNote" + @click="confirmCancelNote" > Cancel @@ -302,7 +302,7 @@ export default { setBeforeUnloadConfirmation: function (enable = true) { if (enable) { - window.onbeforeunload = function() { + window.onbeforeunload = function () { return true; }; } else { @@ -517,24 +517,40 @@ export default { }, cancelNote: function () { - this.$bvModal.msgBoxConfirm(`Are you sure you want to close the note '${this.currentNote.title}' without saving?`, - { - centered: true, - title: "Confirm Closure", - okTitle: "Yes, Close", - okVariant: "warning", - }) - .then(function (response) { - if (response == true) { - localStorage.removeItem(this.currentNote.title); - if (this.currentNote.lastModified == null) { - // Cancelling a new note - EventBus.$emit("navigate", constants.basePaths.home); - } else { - this.setEditMode(false); - } - } - }); + localStorage.removeItem(this.currentNote.title); + if (this.currentNote.lastModified == null) { + // Cancelling a new note + EventBus.$emit("navigate", constants.basePaths.home); + } else { + this.setEditMode(false); + } + }, + + confirmCancelNote: function () { + let parent = this; + let newContent = this.getEditorContent(); + if ( + newContent != this.currentNote.content || + this.titleInput != this.currentNote.title + ) { + this.$bvModal + .msgBoxConfirm( + `Are you sure you want to close the note '${this.currentNote.title}' without saving?`, + { + centered: true, + title: "Confirm Closure", + okTitle: "Yes, Close", + okVariant: "warning", + } + ) + .then(function (response) { + if (response == true) { + parent.cancelNote(); + } + }); + } else { + this.cancelNote(); + } }, deleteNote: function () {