From 4c5bfe5c32d84699f3cdd978bccfecb6210ecd2f Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sun, 31 May 2026 09:31:03 -0700 Subject: [PATCH] fix: respect platform link edit shortcut --- .../editor/RichMarkdownLinkBubble.test.ts | 11 +++++++++++ .../components/editor/RichMarkdownLinkBubble.tsx | 13 ++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/renderer/src/components/editor/RichMarkdownLinkBubble.test.ts diff --git a/src/renderer/src/components/editor/RichMarkdownLinkBubble.test.ts b/src/renderer/src/components/editor/RichMarkdownLinkBubble.test.ts new file mode 100644 index 00000000000..8e67e0a7d40 --- /dev/null +++ b/src/renderer/src/components/editor/RichMarkdownLinkBubble.test.ts @@ -0,0 +1,11 @@ +import { describe, expect, it } from 'vitest' +import { isLinkEditCancelShortcut } from './RichMarkdownLinkBubble' + +describe('isLinkEditCancelShortcut', () => { + it('uses only the platform primary modifier for link-edit cancellation', () => { + expect(isLinkEditCancelShortcut({ key: 'k', metaKey: true, ctrlKey: false }, true)).toBe(true) + expect(isLinkEditCancelShortcut({ key: 'k', metaKey: false, ctrlKey: true }, true)).toBe(false) + expect(isLinkEditCancelShortcut({ key: 'k', metaKey: false, ctrlKey: true }, false)).toBe(true) + expect(isLinkEditCancelShortcut({ key: 'k', metaKey: true, ctrlKey: false }, false)).toBe(false) + }) +}) diff --git a/src/renderer/src/components/editor/RichMarkdownLinkBubble.tsx b/src/renderer/src/components/editor/RichMarkdownLinkBubble.tsx index 5a033cdc530..0d2a510c801 100644 --- a/src/renderer/src/components/editor/RichMarkdownLinkBubble.tsx +++ b/src/renderer/src/components/editor/RichMarkdownLinkBubble.tsx @@ -28,6 +28,16 @@ export function getLinkBubblePosition( } } +export function isLinkEditCancelShortcut( + event: Pick, + isMac: boolean +): boolean { + if (event.key.toLowerCase() !== 'k') { + return false + } + return isMac ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey +} + function LinkEditInput({ initialHref, onSave, @@ -38,6 +48,7 @@ function LinkEditInput({ onCancel: () => void }): React.JSX.Element { const [value, setValue] = useState(initialHref) + const isMac = navigator.userAgent.includes('Mac') const setInputElement = useCallback((input: HTMLInputElement | null) => { if (!input) { @@ -64,7 +75,7 @@ function LinkEditInput({ onCancel() } // Cmd/Ctrl+K while editing cancels the edit. - if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') { + if (isLinkEditCancelShortcut(e, isMac)) { e.preventDefault() onCancel() }