feat: Added "cmd + S" hook for editor

pull/7619/head
Ruslan Semak 8 months ago
parent 1602969825
commit 1601c2345a

@ -248,6 +248,8 @@ export default {
this.currentEditor = `editor${_.startCase(this.initEditor || 'markdown')}` this.currentEditor = `editor${_.startCase(this.initEditor || 'markdown')}`
} }
document.addEventListener('keydown', this.handleKeyDown)
window.onbeforeunload = () => { window.onbeforeunload = () => {
if (!this.exitConfirmed && this.initContentParsed !== this.$store.get('editor/content')) { if (!this.exitConfirmed && this.initContentParsed !== this.$store.get('editor/content')) {
return this.$t('editor:unsavedWarning') return this.$t('editor:unsavedWarning')
@ -263,7 +265,18 @@ export default {
// this.$store.set('editor/mode', 'edit') // this.$store.set('editor/mode', 'edit')
// this.currentEditor = `editorApi` // this.currentEditor = `editorApi`
}, },
beforeDestroy() {
// Удаляем обработчик при уничтожении компонента
document.removeEventListener('keydown', this.handleKeyDown)
},
methods: { methods: {
handleKeyDown(e) {
// Проверяем сочетание Ctrl+S (или Cmd+S для Mac)
if ((e.ctrlKey || e.metaKey) && e.key === 's') {
e.preventDefault() // Предотвращаем стандартное поведение браузера
this.save() // Вызываем метод сохранения
}
},
openPropsModal(name) { openPropsModal(name) {
this.dialogProps = true this.dialogProps = true
}, },

Loading…
Cancel
Save