@@ -19,6 +19,7 @@ import { DEFAULT_THEME_LIGHT } from "$lib/global-options.svelte";
1919import type { WritableBoxedValues } from "svelte-toolbelt" ;
2020import type { Attachment } from "svelte/attachments" ;
2121import { on } from "svelte/events" ;
22+ import { watch } from "runed" ;
2223
2324export interface UnresolvedLineRef {
2425 /**
@@ -1157,7 +1158,6 @@ export class ConciseDiffViewState<K> {
11571158
11581159 private selectionAnchor : { hunkIdx : number ; lineIdx : number } | null = null ;
11591160 private dragSelectionState : { hunk : DiffViewerPatchHunk ; didMove : boolean } | null = null ;
1160- private suppressNextClick = false ;
11611161
11621162 constructor ( props : ConciseDiffViewStateProps < K > ) {
11631163 this . props = props ;
@@ -1166,6 +1166,15 @@ export class ConciseDiffViewState<K> {
11661166 this . update ( ) ;
11671167 } ) ;
11681168
1169+ watch ( [ ( ) => this . diffViewerPatch , ( ) => this . props . unresolvedSelection . current ] , ( [ patchPromise , unresolvedSelection ] , [ oldPatchPromise ] ) => {
1170+ // Update or resolve the selection whenever the patch changes or unresolvedSelection is set
1171+ if ( patchPromise !== oldPatchPromise || unresolvedSelection !== undefined ) {
1172+ patchPromise . then ( ( patch ) => {
1173+ this . resolveOrUpdateSelection ( patch ) ;
1174+ } ) ;
1175+ }
1176+ } ) ;
1177+
11691178 $effect ( ( ) => {
11701179 const promise = getBaseColors ( this . props . syntaxHighlightingTheme . current , this . props . syntaxHighlighting . current ) ;
11711180 promise . then (
@@ -1209,10 +1218,9 @@ export class ConciseDiffViewState<K> {
12091218 ) ;
12101219 this . cachedState = new ConciseDiffViewCachedState ( promise , this . props ) ;
12111220 promise . then (
1212- ( patch ) => {
1221+ ( ) => {
12131222 // Don't replace a potentially completed promise with a pending one, wait until the replacement is ready for smooth transitions
12141223 this . diffViewerPatch = promise ;
1215- this . resolveOrUpdateSelection ( patch ) ;
12161224 } ,
12171225 ( ) => {
12181226 // Propagate errors
@@ -1334,11 +1342,6 @@ export class ConciseDiffViewState<K> {
13341342 const onDragEnd = ( e : PointerEvent ) => {
13351343 element . releasePointerCapture ( e . pointerId ) ;
13361344 abortController . abort ( ) ;
1337-
1338- // Suppress the click event only if we actually moved during the drag
1339- if ( this . dragSelectionState ?. didMove ) {
1340- this . suppressNextClick = true ;
1341- }
13421345 this . dragSelectionState = null ;
13431346 } ;
13441347
0 commit comments