From 1601c2345ae6f20fe0f92841f06117a2de47899e Mon Sep 17 00:00:00 2001 From: Ruslan Semak Date: Mon, 21 Apr 2025 10:20:08 +0300 Subject: [PATCH] feat: Added "cmd + S" hook for editor --- client/components/editor.vue | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/client/components/editor.vue b/client/components/editor.vue index 7cd577b1..8509df49 100644 --- a/client/components/editor.vue +++ b/client/components/editor.vue @@ -248,6 +248,8 @@ export default { this.currentEditor = `editor${_.startCase(this.initEditor || 'markdown')}` } + document.addEventListener('keydown', this.handleKeyDown) + window.onbeforeunload = () => { if (!this.exitConfirmed && this.initContentParsed !== this.$store.get('editor/content')) { return this.$t('editor:unsavedWarning') @@ -263,7 +265,18 @@ export default { // this.$store.set('editor/mode', 'edit') // this.currentEditor = `editorApi` }, + beforeDestroy() { + // Удаляем обработчик при уничтожении компонента + document.removeEventListener('keydown', this.handleKeyDown) + }, methods: { + handleKeyDown(e) { + // Проверяем сочетание Ctrl+S (или Cmd+S для Mac) + if ((e.ctrlKey || e.metaKey) && e.key === 's') { + e.preventDefault() // Предотвращаем стандартное поведение браузера + this.save() // Вызываем метод сохранения + } + }, openPropsModal(name) { this.dialogProps = true },