Skip to content

Commit af685eb

Browse files
FourWindffclaude
andauthored
feat(inline-input): add cancel button and global Esc to dismiss (#105)
The inline review/ask input shown after selecting code in the diff viewer could not be cancelled once the input lost focus. Add a global keydown listener for Escape and an explicit cancel button so users can always dismiss the popup. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a35c05a commit af685eb

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

src/components/InlineInput.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createSignal, onMount } from 'solid-js';
1+
import { createSignal, onCleanup, onMount } from 'solid-js';
22
import { theme } from '../lib/theme';
33
import { sf } from '../lib/fontScale';
44
import type { DiffInteractionMode } from './review-types';
@@ -15,6 +15,15 @@ export function InlineInput(props: InlineInputProps) {
1515

1616
onMount(() => {
1717
requestAnimationFrame(() => inputRef?.focus());
18+
const onGlobalKeyDown = (e: KeyboardEvent) => {
19+
if (e.key === 'Escape') {
20+
e.preventDefault();
21+
e.stopPropagation();
22+
props.onDismiss();
23+
}
24+
};
25+
document.addEventListener('keydown', onGlobalKeyDown, true);
26+
onCleanup(() => document.removeEventListener('keydown', onGlobalKeyDown, true));
1827
});
1928

2029
const borderColor = () => (mode() === 'review' ? theme.warning : theme.accent);
@@ -128,6 +137,26 @@ export function InlineInput(props: InlineInputProps) {
128137
>
129138
{mode() === 'review' ? 'Comment' : 'Ask'}
130139
</button>
140+
141+
{/* Cancel button */}
142+
<button
143+
onClick={() => props.onDismiss()}
144+
title="Cancel (Esc)"
145+
aria-label="Cancel"
146+
style={{
147+
background: 'transparent',
148+
border: `1px solid ${theme.borderSubtle}`,
149+
color: theme.fgMuted,
150+
cursor: 'pointer',
151+
padding: '4px 8px',
152+
'border-radius': '4px',
153+
'font-size': sf(14),
154+
'line-height': '1',
155+
'align-self': 'center',
156+
}}
157+
>
158+
&times;
159+
</button>
131160
</div>
132161
);
133162
}

0 commit comments

Comments
 (0)