Skip to content

Commit a02c58a

Browse files
FourWindffclaude
andcommitted
fix(diff): ignore double-click in blank area outside diff lines
Double-clicking in the empty area below the last file caused the browser to snap-select the nearest text node (the last diff line), which both flashed a stray highlight and incorrectly opened the inline input. Bail out of the mouseup handler when the click target isn't inside a diff line, and preventDefault on mousedown for double-clicks outside diff lines so the browser never creates the ghost selection. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a35c05a commit a02c58a

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

src/components/ScrollingDiffView.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,28 @@ export function ScrollingDiffView(props: ScrollingDiffViewProps) {
891891
});
892892

893893
onMount(() => {
894-
function onMouseUp() {
894+
function onMouseDown(e: MouseEvent) {
895+
// For double-clicks (detail >= 2) outside a diff line, prevent the
896+
// browser from creating its "snap to nearest text" selection at all,
897+
// so the user doesn't see a brief blue flash on the last diff line.
898+
if (e.detail >= 2) {
899+
const target = e.target as HTMLElement | null;
900+
if (!target?.closest('[data-new-line]')) {
901+
e.preventDefault();
902+
}
903+
}
904+
}
905+
906+
function onMouseUp(e: MouseEvent) {
907+
// Ignore clicks that didn't land on a diff line. Without this, a
908+
// double-click in the blank area below the last file collapses the
909+
// browser's "snap to nearest text" selection onto the previous line
910+
// and incorrectly opens the inline input.
911+
const target = e.target as HTMLElement | null;
912+
if (!target?.closest('[data-new-line]')) {
913+
if (!pendingInput()) setHighlightedRange(null);
914+
return;
915+
}
895916
requestAnimationFrame(() => {
896917
const sel = getDiffSelection();
897918
if (!sel) {
@@ -911,8 +932,12 @@ export function ScrollingDiffView(props: ScrollingDiffViewProps) {
911932
});
912933
}
913934

935+
containerRef?.addEventListener('mousedown', onMouseDown);
914936
containerRef?.addEventListener('mouseup', onMouseUp);
915-
onCleanup(() => containerRef?.removeEventListener('mouseup', onMouseUp));
937+
onCleanup(() => {
938+
containerRef?.removeEventListener('mousedown', onMouseDown);
939+
containerRef?.removeEventListener('mouseup', onMouseUp);
940+
});
916941
});
917942

918943
function handleSubmit(text: string, mode: 'review' | 'ask') {

0 commit comments

Comments
 (0)