Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop): preserve native input editing (R1-M4)

Josué56bb6ef5e400
diff --git a/desktop-app/src/__tests__/shortcutRouter.test.ts b/desktop-app/src/__tests__/shortcutRouter.test.ts
index df63e8b86..16da1db8f 100644
--- a/desktop-app/src/__tests__/shortcutRouter.test.ts
+++ b/desktop-app/src/__tests__/shortcutRouter.test.ts
@@ -1,6 +1,10 @@
import { describe, expect, it, vi } from 'vitest'
import type { DesktopShortcutInput } from '../desktopCommands.js'
-import { type DesktopShortcutRoute, routeDesktopShortcut } from '../shortcutRouter.js'
+import {
+ type DesktopShortcutRoute,
+ isStandardEditingShortcut,
+ routeDesktopShortcut,
+} from '../shortcutRouter.js'
function input(overrides: Partial<DesktopShortcutInput> = {}): DesktopShortcutInput {
return {
@@ -93,4 +97,30 @@ describe('main-process Desktop shortcut routing', () => {
expect(preventDefault).not.toHaveBeenCalled()
expect(current.trustedRenderer.send).not.toHaveBeenCalled()
})
+
+ it.each([
+ ['darwin', input({ key: 'a' })],
+ ['darwin', input({ key: 'c' })],
+ ['darwin', input({ key: 'x' })],
+ ['darwin', input({ key: 'v' })],
+ ['darwin', input({ key: 'z' })],
+ ['darwin', input({ key: 'z', shift: true })],
+ ['darwin', input({ key: 'ArrowLeft' })],
+ ['win32', input({ key: 'a', meta: false, control: true })],
+ ['win32', input({ key: 'c', meta: false, control: true })],
+ ['win32', input({ key: 'x', meta: false, control: true })],
+ ['win32', input({ key: 'v', meta: false, control: true })],
+ ['win32', input({ key: 'y', meta: false, control: true })],
+ ['win32', input({ key: 'Insert', meta: false, control: true })],
+ ['win32', input({ key: 'Insert', meta: false, shift: true })],
+ ['win32', input({ key: 'Delete', meta: false, shift: true })],
+ ] as const)('leaves standard %s editing input to Chromium', (platform, candidate) => {
+ expect(isStandardEditingShortcut(candidate, platform)).toBe(true)
+ const current = route('host')
+ current.platform = platform
+ const preventDefault = vi.fn()
+ expect(routeDesktopShortcut(current, { preventDefault }, candidate)).toBe(false)
+ expect(preventDefault).not.toHaveBeenCalled()
+ expect(current.trustedRenderer.send).not.toHaveBeenCalled()
+ })
})
diff --git a/desktop-app/src/shortcutRouter.ts b/desktop-app/src/shortcutRouter.ts
index 3e6ec1504..02dcf9992 100644
--- a/desktop-app/src/shortcutRouter.ts
+++ b/desktop-app/src/shortcutRouter.ts
@@ -21,6 +21,34 @@ export type DesktopShortcutRoute = {
isCurrentSource?: () => boolean
}
+/**
+ * Editing chords belong to Chromium/the active app, even if a future command
+ * definition accidentally reuses one. Keep this guard independent of DOM
+ * focus because before-input-event intentionally does not inspect renderer DOM.
+ */
+export function isStandardEditingShortcut(
+ input: DesktopShortcutInput,
+ platform: DesktopShortcutPlatform
+): boolean {
+ if (input.type !== 'keyDown' || input.isComposing || input.alt) return false
+ const key = input.key.toLowerCase()
+ const mod = platform === 'darwin' ? input.meta && !input.control : input.control && !input.meta
+ if (mod && ['a', 'c', 'v', 'x', 'z'].includes(key)) return true
+ if (platform !== 'darwin' && mod && key === 'y') return true
+ if (
+ platform === 'darwin' &&
+ mod &&
+ ['arrowleft', 'arrowright', 'arrowup', 'arrowdown', 'backspace'].includes(key)
+ ) {
+ return true
+ }
+ return (
+ platform !== 'darwin' &&
+ ((input.control && !input.meta && !input.shift && key === 'insert') ||
+ (!input.control && !input.meta && input.shift && ['delete', 'insert'].includes(key)))
+ )
+}
+
export function routeDesktopShortcut(
route: DesktopShortcutRoute,
event: ShortcutEvent,
@@ -34,11 +62,9 @@ export function routeDesktopShortcut(
) {
return false
}
- const command = matchDesktopCommand(
- input,
- route.platform ?? platformFromNode(process.platform),
- route.source
- )
+ const platform = route.platform ?? platformFromNode(process.platform)
+ if (isStandardEditingShortcut(input, platform)) return false
+ const command = matchDesktopCommand(input, platform, route.source)
if (!command) return false
event.preventDefault()
if (route.source === 'sandbox' && !route.trustedRenderer.isFocused()) {
diff --git a/desktop-app/ui/src/components/Common/EditableInputContracts.test.tsx b/desktop-app/ui/src/components/Common/EditableInputContracts.test.tsx
new file mode 100644
index 000000000..27fee3a99
--- /dev/null
+++ b/desktop-app/ui/src/components/Common/EditableInputContracts.test.tsx
@@ -0,0 +1,44 @@
+// @vitest-environment jsdom
+import { afterEach, describe, expect, it, vi } from 'vitest'
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { ChatLocalSearch } from '@components/ChatLocalSearch'
+import { CommandPalette } from '@components/CommandPalette'
+import { TextInput } from './TextInput'
+
+afterEach(cleanup)
+
+function expectEditingEventsRemainNative(input: HTMLElement): void {
+ for (const key of ['a', 'c', 'x', 'v', 'z']) {
+ expect(fireEvent.keyDown(input, { key, metaKey: true })).toBe(true)
+ expect(fireEvent.keyDown(input, { key, ctrlKey: true })).toBe(true)
+ }
+ expect(
+ fireEvent.paste(input, {
+ clipboardData: { files: [], items: [], getData: () => 'pasted text' },
+ })
+ ).toBe(true)
+}
+
+describe('Desktop editable input contracts', () => {
+ it('keeps shared text inputs available to native selection and clipboard commands', () => {
+ render(<TextInput aria-label="Settings text field" defaultValue="editable" />)
+ expectEditingEventsRemainNative(screen.getByRole('textbox', { name: 'Settings text field' }))
+ })
+
+ it('does not cancel editing commands in current-chat search', () => {
+ render(<ChatLocalSearch messages={[]} onClose={vi.fn()} onSearchStateChange={vi.fn()} />)
+ expectEditingEventsRemainNative(screen.getByRole('textbox', { name: 'Find in current chat' }))
+ })
+
+ it('does not cancel editing commands in the command palette', () => {
+ render(
+ <CommandPalette
+ platform="darwin"
+ isEligible={() => true}
+ onClose={vi.fn()}
+ onExecute={vi.fn()}
+ />
+ )
+ expectEditingEventsRemainNative(screen.getByRole('textbox', { name: 'Search commands' }))
+ })
+})