Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/domains/task-terminals/src/client/TerminalContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
ContextMenuTrigger,
useShortcutDisplay,
useAppearance,
appearanceDefaults
appearanceDefaults,
detectPlatform
} from '@slayzone/ui'
import {
Copy,
Expand Down Expand Up @@ -60,6 +61,12 @@ export function TerminalContextMenu({
const [hasSelection, setHasSelection] = useState(false)
const { terminalFontSize } = useAppearance()

// Copy/Paste aren't registry shortcuts: macOS uses Cmd+C/V via xterm natively,
// while Windows/Linux use Ctrl+Shift+C/V (Terminal's DOM keydown listener), since
// plain Ctrl+C is reserved for SIGINT in a terminal.
const isMac = detectPlatform() === 'mac'
const copyShortcut = isMac ? '⌘C' : 'Ctrl+Shift+C'
const pasteShortcut = isMac ? '⌘V' : 'Ctrl+Shift+V'
const searchShortcut = useShortcutDisplay('terminal-search')
const clearShortcut = useShortcutDisplay('terminal-clear')
const splitShortcut = useShortcutDisplay('terminal-split')
Expand Down Expand Up @@ -123,12 +130,12 @@ export function TerminalContextMenu({
<ContextMenuItem disabled={!hasSelection} onSelect={handleCopy}>
<Copy className="size-4" />
Copy
<ContextMenuShortcut>⌘C</ContextMenuShortcut>
<ContextMenuShortcut>{copyShortcut}</ContextMenuShortcut>
</ContextMenuItem>
<ContextMenuItem onSelect={handlePaste}>
<ClipboardPaste className="size-4" />
Paste
<ContextMenuShortcut>⌘V</ContextMenuShortcut>
<ContextMenuShortcut>{pasteShortcut}</ContextMenuShortcut>
</ContextMenuItem>

<ContextMenuSeparator />
Expand Down
10 changes: 5 additions & 5 deletions packages/domains/task/src/client/CreateTaskDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Popover, PopoverContent, PopoverTrigger } from '@slayzone/ui'
import { Calendar } from '@slayzone/ui'
import { Checkbox } from '@slayzone/ui'
import { ProjectSelect } from '@slayzone/projects'
import { buildStatusOptions, cn } from '@slayzone/ui'
import { buildStatusOptions, cn, formatKeysForDisplay, isPrimaryModifier } from '@slayzone/ui'

interface CreateTaskDialogProps {
open: boolean
Expand Down Expand Up @@ -186,10 +186,10 @@ export function CreateTaskDialog({
<form
onSubmit={form.handleSubmit(onSubmit)}
onKeyDown={(e) => {
if (e.key === 'Enter' && e.metaKey && e.shiftKey) {
if (e.key === 'Enter' && isPrimaryModifier(e) && e.shiftKey) {
e.preventDefault()
form.handleSubmit(onSubmit)()
} else if (e.key === 'Enter' && e.metaKey) {
} else if (e.key === 'Enter' && isPrimaryModifier(e)) {
e.preventDefault()
if (onCreatedAndOpen) {
form.handleSubmit((data) => createTask(data, { andOpen: true }))()
Expand Down Expand Up @@ -450,7 +450,7 @@ export function CreateTaskDialog({
<Button type="submit" variant={onCreatedAndOpen ? 'outline' : 'default'}>
Create
<kbd className="ml-2 opacity-70" style={{ fontFamily: 'system-ui' }}>
{onCreatedAndOpen ? '⇧⌘↩' : '⌘↩'}
{formatKeysForDisplay(onCreatedAndOpen ? 'shift+mod+enter' : 'mod+enter')}
</kbd>
</Button>
{onCreatedAndOpen && (
Expand All @@ -460,7 +460,7 @@ export function CreateTaskDialog({
>
Create + open
<kbd className="ml-2 text-muted-foreground" style={{ fontFamily: 'system-ui' }}>
⌘↩
{formatKeysForDisplay('mod+enter')}
</kbd>
</Button>
)}
Expand Down
4 changes: 2 additions & 2 deletions packages/domains/tasks/src/client/KanbanColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
DropdownMenuItem,
DropdownMenuTrigger
} from '@slayzone/ui'
import { cn, getColumnStatusStyle } from '@slayzone/ui'
import { cn, getColumnStatusStyle, isPrimaryModifier } from '@slayzone/ui'

interface SortableKanbanCardProps {
task: Task
Expand Down Expand Up @@ -123,7 +123,7 @@ function SortableKanbanCard({
isFocused={isFocused}
isSelected={isSelected}
isMultiDragGhost={isMultiDragGhost}
onClick={(e) => onTaskClick?.(task, e)}
onClick={(e) => onTaskClick?.(task, { metaKey: isPrimaryModifier(e), shiftKey: e.shiftKey })}
isBlocked={isBlocked}
subTaskCount={subTaskCount}
cardProperties={cardProperties}
Expand Down
3 changes: 2 additions & 1 deletion packages/domains/tasks/src/client/KanbanListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
PriorityIcon
} from '@slayzone/ui'
import { IconButton } from '@slayzone/ui'
import { isPrimaryModifier } from '@slayzone/ui'
import { ChevronDown, Plus, AlertCircle, AlarmClockOff, Check, GitMerge, Link2 } from 'lucide-react'
import { usePty, useActiveTaskIds } from '@slayzone/terminal'
import { useDialogStore } from '@slayzone/settings/client'
Expand Down Expand Up @@ -203,7 +204,7 @@ function ListRowContent({
isDragging && 'opacity-50',
isTerminalStatus(task.status, columns) && 'opacity-60'
)}
onClick={(e) => onClick?.(task, e)}
onClick={(e) => onClick?.(task, { metaKey: isPrimaryModifier(e) })}
>
{/* Priority bar */}
{(cp?.priority ?? true) && <PriorityBar priority={task.priority} />}
Expand Down
28 changes: 18 additions & 10 deletions packages/domains/terminal/src/client/Terminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import { useEffect, useRef, useCallback, useState, forwardRef, useImperativeHand
import { CheckCircle2, XCircle, Loader2 } from 'lucide-react'
import { Terminal as XTerm } from '@xterm/xterm'
import { FitAddon } from '@xterm/addon-fit'
import { matchesShortcut, useShortcutStore, PulseGrid } from '@slayzone/ui'
import {
matchesShortcut,
isPrimaryModifier,
formatKeysForDisplay,
useShortcutStore,
PulseGrid
} from '@slayzone/ui'
import { WebLinkProvider, FileLinkProvider } from './web-link-provider'
import { SerializeAddon } from '@xterm/addon-serialize'
import { SearchAddon } from '@xterm/addon-search'
Expand Down Expand Up @@ -520,8 +526,10 @@ export const Terminal = forwardRef<TerminalHandle, TerminalProps>(function Termi
if (tooltipEl) tooltipEl.style.display = 'none'
}

const urlHint = '— ⌘+Click open · ⌘⇧+Click external'
const fileHint = '— ⌘+Click open'
const modKey = formatKeysForDisplay('mod')
const shiftKey = formatKeysForDisplay('shift')
const urlHint = `— ${modKey}+Click open · ${modKey}+${shiftKey}+Click external`
const fileHint = `— ${modKey}+Click open`
Comment thread
greptile-apps[bot] marked this conversation as resolved.

// xterm measures the character cell from whatever font is loaded when
// open() runs. If the terminal webfont has not loaded yet (cold start)
Expand Down Expand Up @@ -555,11 +563,11 @@ export const Terminal = forwardRef<TerminalHandle, TerminalProps>(function Termi
// a confirm() dialog + window.open().
linkHandler: {
activate: (event: MouseEvent, uri: string) => {
if (event.metaKey && event.shiftKey) {
if (isPrimaryModifier(event) && event.shiftKey) {
void window.api.shell.openExternal(uri)
} else if (event.metaKey && onOpenUrlRef.current) {
} else if (isPrimaryModifier(event) && onOpenUrlRef.current) {
onOpenUrlRef.current(uri)
} else if (event.metaKey) {
} else if (isPrimaryModifier(event)) {
void window.api.shell.openExternal(uri)
}
},
Expand Down Expand Up @@ -587,11 +595,11 @@ export const Terminal = forwardRef<TerminalHandle, TerminalProps>(function Termi
const linkProvider = new WebLinkProvider(
terminal,
(event, uri) => {
if (event.metaKey && event.shiftKey) {
if (isPrimaryModifier(event) && event.shiftKey) {
void window.api.shell.openExternal(uri)
} else if (event.metaKey && onOpenUrlRef.current) {
} else if (isPrimaryModifier(event) && onOpenUrlRef.current) {
onOpenUrlRef.current(uri)
} else if (event.metaKey) {
} else if (isPrimaryModifier(event)) {
void window.api.shell.openExternal(uri)
}
},
Expand All @@ -606,7 +614,7 @@ export const Terminal = forwardRef<TerminalHandle, TerminalProps>(function Termi
new FileLinkProvider(
terminal,
(event, filePath, line, col) => {
if (!event.metaKey) return
if (!isPrimaryModifier(event)) return
// Resolve relative paths against terminal cwd
const resolved = filePath.startsWith('/') ? filePath : `${cwd}/${filePath}`
const isInProject = resolved.startsWith(cwd + '/') || resolved === cwd
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/shortcuts/src/accelerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const DISPLAY_MAP_MAC: Record<string, string> = {
shift: '⇧',
alt: '⌥',
ctrl: '⌃',
enter: '↩',
period: '.',
comma: ',',
slash: '/',
Expand All @@ -15,6 +16,7 @@ const DISPLAY_MAP_OTHER: Record<string, string> = {
shift: 'Shift',
alt: 'Alt',
ctrl: 'Ctrl',
enter: '↩',
period: '.',
comma: ',',
slash: '/',
Expand Down
19 changes: 19 additions & 0 deletions packages/shared/shortcuts/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
shortcutDefinitions,
MENU_SHORTCUT_DEFAULTS,
detectPlatform,
isPrimaryModifier,
getBlockedWebPanelKeys,
type ElectronInput
} from './index'
Expand Down Expand Up @@ -270,6 +271,24 @@ describe('detectPlatform', () => {
})
})

describe('isPrimaryModifier', () => {
const isMac = detectPlatform() === 'mac'

it('treats Cmd as primary on macOS and Ctrl elsewhere', () => {
expect(isPrimaryModifier({ metaKey: true, ctrlKey: false })).toBe(isMac)
expect(isPrimaryModifier({ metaKey: false, ctrlKey: true })).toBe(!isMac)
})

it('returns false when no modifier is pressed', () => {
expect(isPrimaryModifier({ metaKey: false, ctrlKey: false })).toBe(false)
})

it('off macOS, does not fire when meta (Win/Super) is also held', () => {
// Mirrors the registry rejecting non-mac events with metaKey set.
expect(isPrimaryModifier({ metaKey: true, ctrlKey: true })).toBe(isMac)
})
})

describe('getBlockedWebPanelKeys', () => {
it('includes OS reserved keys', () => {
const blocked = getBlockedWebPanelKeys()
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/shortcuts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { detectPlatform, type Platform } from './platform'
export { detectPlatform, isPrimaryModifier, type Platform } from './platform'
export { type ShortcutScope, SCOPE_PRIORITY } from './scope'
export {
shortcutDefinitions,
Expand Down
12 changes: 12 additions & 0 deletions packages/shared/shortcuts/src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@ export function detectPlatform(): Platform {
}
return cached
}

/**
* Whether the platform's primary shortcut modifier is pressed for an event.
* Maps to Cmd (metaKey) on macOS and Ctrl (ctrlKey) everywhere else — the same
* `mod` semantics used by the shortcut registry, but for raw mouse/keyboard
* handlers that can't go through `matchesShortcut`. On Windows/Linux metaKey is
* the Super/Win key, so handlers must not gate on it — and, mirroring the
* registry's non-mac rejection of meta, must not fire while it is also held.
*/
export function isPrimaryModifier(e: { metaKey: boolean; ctrlKey: boolean }): boolean {
return detectPlatform() === 'mac' ? e.metaKey : e.ctrlKey && !e.metaKey
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.
2 changes: 2 additions & 0 deletions packages/shared/ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export {
withShortcut,
toElectronAccelerator,
matchesShortcut,
isPrimaryModifier,
detectPlatform,
SCOPE_PRIORITY,
registry,
scopeTracker,
Expand Down
1 change: 1 addition & 0 deletions packages/shared/ui/src/shortcut-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {
formatKeysVerbose,
withShortcut,
detectPlatform,
isPrimaryModifier,
SCOPE_PRIORITY,
registry,
scopeTracker,
Expand Down