From 20d32ecc4e2b601fe3f4fb1f5867503d7d812ef6 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Thu, 13 Mar 2025 14:54:49 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8(frontend)=20ctrl+k=20modal=20not?= =?UTF-8?q?=20when=20editor=20is=20focused?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ctrl+k interaction was as well used in the editor. So if the user has a focus on the editor, we don't open the searchmodal. --- CHANGELOG.md | 5 +++ .../__tests__/app-impress/doc-search.spec.ts | 31 +++++++++++++++++++ .../apps/impress/src/hook/useCmdK.tsx | 7 +++++ 3 files changed, 43 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f5910b2..808ceb2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,10 +12,15 @@ and this project adheres to - 📝(doc) add publiccode.yml +## Changed + +- 🚸(frontend) ctrl+k modal not when editor is focused #712 + ## Fixed - 🐛(back) allow only images to be used with the cors-proxy #781 + ## [2.5.0] - 2025-03-18 ## Added diff --git a/src/frontend/apps/e2e/__tests__/app-impress/doc-search.spec.ts b/src/frontend/apps/e2e/__tests__/app-impress/doc-search.spec.ts index 143e383e..fdd82c11 100644 --- a/src/frontend/apps/e2e/__tests__/app-impress/doc-search.spec.ts +++ b/src/frontend/apps/e2e/__tests__/app-impress/doc-search.spec.ts @@ -63,4 +63,35 @@ test.describe('Document search', () => { listSearch.getByRole('option').getByText(doc2Title), ).toBeHidden(); }); + + test('it checks cmd+k modal search interaction', async ({ + page, + browserName, + }) => { + const [doc1Title] = await createDoc( + page, + 'Doc seack ctrl k', + browserName, + 1, + ); + await verifyDocName(page, doc1Title); + + await page.keyboard.press('Control+k'); + await expect( + page.getByLabel('Search modal').getByText('search'), + ).toBeVisible(); + + await page.keyboard.press('Escape'); + + const editor = page.locator('.ProseMirror'); + await editor.click(); + await editor.fill('Hello world'); + await editor.getByText('Hello world').dblclick(); + + await page.keyboard.press('Control+k'); + await expect(page.getByRole('textbox', { name: 'Edit URL' })).toBeVisible(); + await expect( + page.getByLabel('Search modal').getByText('search'), + ).toBeHidden(); + }); }); diff --git a/src/frontend/apps/impress/src/hook/useCmdK.tsx b/src/frontend/apps/impress/src/hook/useCmdK.tsx index dd828865..457af3cd 100644 --- a/src/frontend/apps/impress/src/hook/useCmdK.tsx +++ b/src/frontend/apps/impress/src/hook/useCmdK.tsx @@ -5,6 +5,13 @@ export const useCmdK = (callback: () => void) => { const down = (e: KeyboardEvent) => { if ((e.key === 'k' || e.key === 'K') && (e.metaKey || e.ctrlKey)) { e.preventDefault(); + + const isProseMirrorFocused = + document.activeElement?.classList.contains('ProseMirror'); + if (isProseMirrorFocused) { + return; + } + callback(); } };