From 4bbc4f181cb8bed365d23db0262c39c49bafe315 Mon Sep 17 00:00:00 2001 From: Luka Trovic Date: Fri, 5 Apr 2024 21:23:17 +0200 Subject: [PATCH] fix: focus issue on translate modal, remove duplicate code Signed-off-by: Luka Trovic --- src/components/Assistant.vue | 33 ++------------------------- src/components/Editor.vue | 36 ++++++++++++++++++++++++++++++ src/components/Menu/MenuBar.vue | 33 +++------------------------ src/components/Modal/Translate.vue | 13 ++++++++++- 4 files changed, 53 insertions(+), 62 deletions(-) diff --git a/src/components/Assistant.vue b/src/components/Assistant.vue index 81e749eadc3..a055d29392d 100644 --- a/src/components/Assistant.vue +++ b/src/components/Assistant.vue @@ -63,12 +63,6 @@ class="floating-menu--badge" /> - -

@@ -154,8 +148,7 @@ import { useIsPublicMixin, } from './Editor.provider.js' import { FloatingMenu } from '@tiptap/vue-2' -import Translate from './Modal/Translate.vue' -import { subscribe, unsubscribe } from '@nextcloud/event-bus' +import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus' const limitInRange = (num, min, max) => { return Math.min(Math.max(parseInt(num), parseInt(min)), parseInt(max)) @@ -170,7 +163,6 @@ const STATUS_UNKNOWN = 0 export default { name: 'Assistant', components: { - Translate, FloatingMenu, ErrorIcon, CreationIcon, @@ -209,7 +201,6 @@ export default { STATUS_UNKNOWN, showTaskList: false, - displayTranslate: false, canTranslate: loadState('text', 'translation_languages', []).length > 0, } }, @@ -304,27 +295,7 @@ export default { await this.fetchTasks() }, openTranslateDialog() { - this.displayTranslate = this.selection - }, - hideTranslate() { - this.displayTranslate = false - }, - translateInsert(content) { - this.$editor.commands.command(({ tr, commands }) => { - return commands.insertContentAt(tr.selection.to, content) - }) - this.displayTranslate = false - }, - translateReplace(content) { - this.$editor.commands.command(({ tr, commands }) => { - const selection = tr.selection - const range = { - from: selection.from, - to: selection.to, - } - return commands.insertContentAt(range, content) - }) - this.displayTranslate = false + emit('text:translate-modal:show', { content: this.selection || '' }) }, async openResult(task) { window.OCA?.TPAssistant.openAssistantResult(task) diff --git a/src/components/Editor.vue b/src/components/Editor.vue index 4c4d6bde990..a7b9258f5b6 100644 --- a/src/components/Editor.vue +++ b/src/components/Editor.vue @@ -77,6 +77,11 @@ :is-rich-editor="isRichEditor" /> +

@@ -125,6 +130,7 @@ import MainContainer from './Editor/MainContainer.vue' import Wrapper from './Editor/Wrapper.vue' import SkeletonLoading from './SkeletonLoading.vue' import Assistant from './Assistant.vue' +import Translate from './Modal/Translate.vue' export default { name: 'Editor', @@ -139,6 +145,7 @@ export default { Reader: () => import(/* webpackChunkName: "editor" */'./Reader.vue'), Status, Assistant, + Translate, }, mixins: [ isMobile, @@ -251,6 +258,8 @@ export default { draggedOver: false, contentWrapper: null, + translateModal: false, + translateContent: '', } }, computed: { @@ -338,6 +347,7 @@ export default { const maxWidth = width - 36 this.$el.style.setProperty('--widget-full-width', `${maxWidth}px`) }) + subscribe('text:translate-modal:show', this.showTranslateModal) }, created() { this.$ydoc = new Doc() @@ -364,6 +374,7 @@ export default { await Promise.any([timeout, this.$syncService.save()]) } this.$providers.forEach(p => p.destroy()) + unsubscribe('text:translate-modal:show', this.showTranslateModal) }, methods: { initSession() { @@ -757,6 +768,31 @@ export default { event.preventDefault() } }, + + showTranslateModal(e) { + this.translateContent = e.content + this.translateModal = true + }, + hideTranslate() { + this.translateModal = false + }, + translateInsert(content) { + this.$editor.commands.command(({ tr, commands }) => { + return commands.insertContentAt(tr.selection.to, content) + }) + this.translateModal = false + }, + translateReplace(content) { + this.$editor.commands.command(({ tr, commands }) => { + const selection = tr.selection + const range = { + from: selection.from, + to: selection.to, + } + return commands.insertContentAt(range, content) + }) + this.translateModal = false + }, }, } diff --git a/src/components/Menu/MenuBar.vue b/src/components/Menu/MenuBar.vue index a66b45cfddb..f429ff7c5ec 100644 --- a/src/components/Menu/MenuBar.vue +++ b/src/components/Menu/MenuBar.vue @@ -34,11 +34,6 @@ 'text-menubar--is-workspace': $isRichWorkspace }"> -