fix(sidebar): keep hover title editor cursor stable

This commit is contained in:
Neil
2026-07-02 12:28:03 -07:00
parent 7926b6a462
commit 73f417b38e
2 changed files with 25 additions and 2 deletions
@@ -213,15 +213,29 @@ describe('WorktreeCardDetailsHover interactions', () => {
title?.dispatchEvent(new MouseEvent('dblclick', { bubbles: true, cancelable: true }))
})
const input = container.querySelector('[data-worktree-title-rename-input]')
const sizingTitle = container.querySelector(
'[data-worktree-title-inline-rename="editing"] [aria-hidden="true"]'
)
expect(identityHeader?.className).toContain('cursor-text')
expect(input).not.toBeNull()
expect(input?.className).toContain('cursor-text')
expect(input?.className).toContain('select-text')
expect(sizingTitle?.className).toContain('pointer-events-none')
expect(input?.getAttribute('draggable')).toBe('false')
expect(input?.className).toContain('bg-input/40')
expect(input?.className).toContain('rounded-sm')
expect(input?.className).toContain('selection:bg-[Highlight]')
expect(input?.className).toContain('focus-visible:ring-[1px]')
const dragStart = new DragEvent('dragstart', { bubbles: true, cancelable: true })
act(() => {
input?.dispatchEvent(dragStart)
})
expect(dragStart.defaultPrevented).toBe(true)
act(() => {
interactionMocks.onHoverOpenChange?.(false)
})
@@ -180,6 +180,13 @@ export function WorktreeTitleInlineRename({
event.stopPropagation()
}, [])
const stopInputDragEvent = useCallback((event: React.DragEvent<HTMLInputElement>) => {
// Why: selected rename text can become a drag target, which flips the cursor
// away from the I-beam while the title editor is active.
event.preventDefault()
event.stopPropagation()
}, [])
const startRename = useCallback(
(event: React.MouseEvent<HTMLElement>) => {
if (disabled) {
@@ -263,7 +270,7 @@ export function WorktreeTitleInlineRename({
data-worktree-title-inline-rename="editing"
>
<span
className="invisible col-start-1 row-start-1 min-w-0 truncate whitespace-pre"
className="pointer-events-none invisible col-start-1 row-start-1 min-w-0 truncate whitespace-pre"
aria-hidden="true"
>
{displayName}
@@ -273,6 +280,7 @@ export function WorktreeTitleInlineRename({
value={value}
style={{ font: 'inherit' }}
disabled={saving}
draggable={false}
spellCheck={false}
aria-label={translate(
'auto.components.sidebar.WorktreeTitleInlineRename.bff3bdd00c',
@@ -283,10 +291,11 @@ export function WorktreeTitleInlineRename({
onBlur={() => void commitRename()}
onClick={stopCardEvent}
onDoubleClick={stopCardEvent}
onDragStart={stopInputDragEvent}
onPointerDown={stopCardEvent}
onKeyDown={handleKeyDown}
className={cn(
'col-start-1 row-start-1 min-w-0 select-text truncate text-foreground outline-none',
'col-start-1 row-start-1 min-w-0 cursor-text select-text truncate text-foreground outline-none',
editingInputClassName,
saving && savingInputClassName,
inputClassName