From 950cb098de7e04278c12cf2686b4cdc192eaaa18 Mon Sep 17 00:00:00 2001 From: anon_ally Date: Sat, 7 Mar 2026 19:07:10 +0100 Subject: [PATCH] feat: Add shortcut to link markdown action (#11466) Follow forgejo/forgejo!9110 and add a shortcut to the link action, via ctrl/command + K. Close #11353 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11466 Reviewed-by: 0ko <0ko@noreply.codeberg.org> Reviewed-by: Gusted Co-authored-by: anon_ally Co-committed-by: anon_ally --- options/locale/locale_en-US.ini | 2 +- templates/shared/combomarkdowneditor.tmpl | 2 +- tests/e2e/markdown-editor.test.e2e.ts | 39 +++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index a72ddb6116..6e6f8a81cf 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -205,7 +205,7 @@ buttons.bold.tooltip = Add bold text (Ctrl+B / ⌘B) buttons.italic.tooltip = Add italic text (Ctrl+I / ⌘I) buttons.quote.tooltip = Quote text buttons.code.tooltip = Add code -buttons.link.tooltip = Add a link +buttons.link.tooltip = Add a link (Ctrl+K / ⌘K) buttons.list.unordered.tooltip = Add a bullet list buttons.list.ordered.tooltip = Add a numbered list buttons.list.task.tooltip = Add a list of tasks diff --git a/templates/shared/combomarkdowneditor.tmpl b/templates/shared/combomarkdowneditor.tmpl index a7f7778db2..c1ec50ab70 100644 --- a/templates/shared/combomarkdowneditor.tmpl +++ b/templates/shared/combomarkdowneditor.tmpl @@ -29,7 +29,7 @@ Template Attributes:
{{svg "octicon-quote"}} {{svg "octicon-code"}} - +
{{svg "octicon-list-unordered"}} diff --git a/tests/e2e/markdown-editor.test.e2e.ts b/tests/e2e/markdown-editor.test.e2e.ts index 5be8c1ed67..5274b25a73 100644 --- a/tests/e2e/markdown-editor.test.e2e.ts +++ b/tests/e2e/markdown-editor.test.e2e.ts @@ -439,6 +439,40 @@ test('Markdown insert link', async ({page}) => { await screenshot(page); } + async function evaluateLinkInsertionShortcut(page: Page, selector: string) { + const url = 'https://example.com'; + const description = 'Where does this lead?'; + + const expectedContent = `[${description}](${url})`; + + const area = page.locator(selector); + + const textarea = area.locator('textarea[name=content]'); + + await textarea.fill(description); + await textarea.focus(); + await textarea.evaluate((it:HTMLTextAreaElement) => it.setSelectionRange(0, it.value.length)); + + await textarea.press('ControlOrMeta+KeyK'); + + const newLinkModal = page.locator('[data-modal-name="new-markdown-link"].active'); + await expect(newLinkModal).toBeVisible(); + await accessibilityCheck({page}, ['[data-modal-name="new-markdown-link"].active'], [], []); + await screenshot(page); + + const urlInput = newLinkModal.locator('input[name="link-url"]'); + + await expect(urlInput).not.toHaveAttribute('disabled'); + + await urlInput.fill(url); + + await newLinkModal.locator('button[data-selector-name="ok-button"]').click(); + await expect(newLinkModal).toBeHidden(); + + await expect(textarea).toHaveValue(expectedContent); + await screenshot(page); + } + const response = await page.goto('/user2/repo1/issues/1'); expect(response?.status()).toBe(200); @@ -446,6 +480,11 @@ test('Markdown insert link', async ({page}) => { await evaluateLinkInsertion(page, '#comment-form', false); await evaluateLinkInsertion(page, '#issuecomment-2', true); }).toPass(); + + await expect(async () => { + await evaluateLinkInsertionShortcut(page, '#comment-form'); + await evaluateLinkInsertionShortcut(page, '#issuecomment-2'); + }).toPass(); }); test('text expander has higher prio then prefix continuation', async ({page}) => {