1
1
mirror of https://github.com/aelve/guide.git synced 2024-11-25 18:56:52 +03:00

Markdown editor confirmation of unsaved changes on escape

This commit is contained in:
avele 2019-10-30 00:12:39 +04:00
parent d20e5f99b0
commit 4ac5c1820c

View File

@ -10,7 +10,7 @@
@keydown.exact.capture.enter="onEnterDown"
@keydown.exact.ctrl.enter="onCtrlEnterDown"
@keydown.exact.meta.enter="onCtrlEnterDown"
@keydown.exact.esc="cancel"
@keydown.exact.esc="onEsc"
v-show="editor && isReady"
>
<textarea
@ -227,6 +227,22 @@ export default class MarkdownEditor extends Vue {
this.$emit('save', this.editor.value())
}
async onEsc () {
let isConfirmed = true
if (this.value !== this.editor.value()) {
isConfirmed = await this._confirm({
fullText: 'You have unsaved changes. Do you really want to discard them?',
confirmBtnText: 'Disacrd',
confirmBtnProps: {
color: 'error'
}
})
}
if (isConfirmed) {
this.cancel()
}
}
cancel () {
this.$emit('cancel')
}