From 96bca3ad8e3e9c4e6abd15b8d126fa35b5cd9176 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Wed, 29 May 2024 08:35:44 +0000 Subject: [PATCH] fixes #4020 Closes #4020 Merge request studip/studip!2869 --- resources/vue/components/StudipWysiwyg.vue | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/resources/vue/components/StudipWysiwyg.vue b/resources/vue/components/StudipWysiwyg.vue index e343e80bc68..799c5f1fc29 100644 --- a/resources/vue/components/StudipWysiwyg.vue +++ b/resources/vue/components/StudipWysiwyg.vue @@ -2,7 +2,7 @@ <ckeditor :editor="editor" :config="editorConfig" - @ready="prefill" + @ready="onReady" v-model="currentText" @input="onInput" /> @@ -29,11 +29,15 @@ export default { }, default: 'classic', }, + autofocus: Boolean, }, data() { return { currentText: '', editorConfig: {}, + + createdEditor: null, + shouldFocus: this.autofocus, }; }, computed: { @@ -48,13 +52,25 @@ export default { }, }, methods: { - prefill(editor) { + onReady(editor) { + this.createdEditor = editor; this.currentText = this.text; + + if (this.shouldFocus) { + this.focus(); + } }, onInput(value) { this.currentText = value; this.$emit('input', value); }, + focus() { + if (this.createdEditor) { + this.createdEditor.focus(); + } else { + this.shouldFocus = true; + } + } }, created() { STUDIP.loadChunk('mathjax'); -- GitLab