mirror of
https://github.com/stablyai/orca.git
synced 2026-09-26 00:02:34 +00:00
fix: respect platform link edit shortcut
This commit is contained in:
@@ -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)
|
||||
})
|
||||
})
|
||||
@@ -28,6 +28,16 @@ export function getLinkBubblePosition(
|
||||
}
|
||||
}
|
||||
|
||||
export function isLinkEditCancelShortcut(
|
||||
event: Pick<KeyboardEvent, 'key' | 'metaKey' | 'ctrlKey'>,
|
||||
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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user