Cancel current edits and exit edit mode with escape
This commit is contained in:
parent
9de48aa6b2
commit
6ad8ce8f44
@ -190,7 +190,7 @@ import BaseButton from '@/components/base/BaseButton.vue'
|
|||||||
import XButton from '@/components/input/button.vue'
|
import XButton from '@/components/input/button.vue'
|
||||||
import {Placeholder} from '@tiptap/extension-placeholder'
|
import {Placeholder} from '@tiptap/extension-placeholder'
|
||||||
import {eventToHotkeyString} from '@github/hotkey'
|
import {eventToHotkeyString} from '@github/hotkey'
|
||||||
import {mergeAttributes} from '@tiptap/core'
|
import {Extension, mergeAttributes} from '@tiptap/core'
|
||||||
import {isEditorContentEmpty} from '@/helpers/editorContentEmpty'
|
import {isEditorContentEmpty} from '@/helpers/editorContentEmpty'
|
||||||
import inputPrompt from '@/helpers/inputPrompt'
|
import inputPrompt from '@/helpers/inputPrompt'
|
||||||
import {setLinkInEditor} from '@/components/input/editor/setLinkInEditor'
|
import {setLinkInEditor} from '@/components/input/editor/setLinkInEditor'
|
||||||
@ -312,6 +312,8 @@ const internalMode = ref<Mode>('preview')
|
|||||||
const isEditing = computed(() => internalMode.value === 'edit' && isEditEnabled)
|
const isEditing = computed(() => internalMode.value === 'edit' && isEditEnabled)
|
||||||
const contentHasChanged = ref<boolean>(false)
|
const contentHasChanged = ref<boolean>(false)
|
||||||
|
|
||||||
|
let lastSavedState = modelValue
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => internalMode.value,
|
() => internalMode.value,
|
||||||
mode => {
|
mode => {
|
||||||
@ -349,6 +351,19 @@ const editor = useEditor({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
// Add a custom extension for the Escape key
|
||||||
|
Extension.create({
|
||||||
|
name: 'escapeKey',
|
||||||
|
|
||||||
|
addKeyboardShortcuts() {
|
||||||
|
return {
|
||||||
|
'Escape': () => {
|
||||||
|
exitEditMode()
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
Heading,
|
Heading,
|
||||||
History,
|
History,
|
||||||
HorizontalRule,
|
HorizontalRule,
|
||||||
@ -462,7 +477,15 @@ function bubbleNow() {
|
|||||||
|
|
||||||
function bubbleSave() {
|
function bubbleSave() {
|
||||||
bubbleNow()
|
bubbleNow()
|
||||||
emit('save', editor.value?.getHTML())
|
lastSavedState = editor.value?.getHTML() ?? ''
|
||||||
|
emit('save', lastSavedState)
|
||||||
|
if (isEditing.value) {
|
||||||
|
internalMode.value = 'preview'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function exitEditMode() {
|
||||||
|
editor.value?.commands.setContent(lastSavedState, false)
|
||||||
if (isEditing.value) {
|
if (isEditing.value) {
|
||||||
internalMode.value = 'preview'
|
internalMode.value = 'preview'
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user