diff --git a/cypress/e2e/Assistant.spec.js b/cypress/e2e/Assistant.spec.js index b34e6b2b89a..0e9895969d3 100644 --- a/cypress/e2e/Assistant.spec.js +++ b/cypress/e2e/Assistant.spec.js @@ -73,4 +73,28 @@ describe('Assistant', () => { .should('be.visible') .should('contain', 'Hello World') }) + + it('Open translate dialog', () => { + cy.isolateTest({ + sourceFile: fileName, + }) + cy.openFile(fileName, { force: true }) + + cy.getContent() + .click({ force: true }) + cy.get('[data-cy="assistantMenu"]') + .click() + cy.get('[data-cy="open-translate"]') + .should('be.visible') + .click() + + cy.get('[data-cy="translate-input"]') + .should('be.visible') + .click() + cy.get('[data-cy="translate-input"]') + .should('be.visible') + .type('Hello World') + cy.get('[data-cy="translate-input"]') + .should('be.focused') + }) }) diff --git a/cypress/e2e/share.spec.js b/cypress/e2e/share.spec.js index 504a0a735c7..d0571e6e68d 100644 --- a/cypress/e2e/share.spec.js +++ b/cypress/e2e/share.spec.js @@ -117,7 +117,7 @@ describe('Open test.md in viewer', function() { cy.getModal().getContent().should('contain', 'Hello world') cy.getModal().getContent().find('h2').should('contain', 'Hello world') cy.getModal().find('.modal-header button.header-close').click() - cy.get('.modal-mask').should('not.exist') + cy.get('.modal-mask').should('not.be.visible') // cy.get('#rich-workspace').getContent().should('contain', 'Hello world') }) }) diff --git a/src/components/Assistant.vue b/src/components/Assistant.vue index 81e749eadc3..c7f34a82fb0 100644 --- a/src/components/Assistant.vue +++ b/src/components/Assistant.vue @@ -43,7 +43,7 @@ {{ provider.name }} - + @@ -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,10 @@ 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 + if (!this.selection.trim().length) { + this.$editor.commands.selectAll() + } + 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 295597cca7c..da46735e71a 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..a782c4fd88f 100644 --- a/src/components/Menu/MenuBar.vue +++ b/src/components/Menu/MenuBar.vue @@ -34,11 +34,6 @@ 'text-menubar--is-workspace': $isRichWorkspace }"> -