@@ -18,6 +18,7 @@ import {
1818 writeLineRef ,
1919 parseLineRef ,
2020 type UnresolvedLineSelection ,
21+ lineSelectionsEqual ,
2122} from "$lib/components/diff/concise-diff-view.svelte" ;
2223import { countOccurrences , type FileTreeNodeData , makeFileTree , type LazyPromise , lazyPromise , animationFramePromise , yieldToBrowser } from "$lib/util" ;
2324import { onDestroy , onMount , tick } from "svelte" ;
@@ -422,21 +423,28 @@ export class MultiFileDiffViewerState {
422423 }
423424
424425 setSelection ( file : FileDetails , lines : LineSelection | undefined ) {
426+ const oldSelection = this . selection ;
425427 this . selection = { file, lines } ;
428+ const selectionChanged = oldSelection ?. file . index !== file . index || ! lineSelectionsEqual ( oldSelection ?. lines , lines ) ;
426429
427- goto ( `?${ page . url . searchParams } #${ makeUrlHashValue ( this . selection ) } ` , {
428- keepFocus : true ,
429- state : this . createPageState ( ) ,
430- } ) ;
430+ if ( selectionChanged ) {
431+ goto ( `?${ page . url . searchParams } #${ makeUrlHashValue ( this . selection ) } ` , {
432+ keepFocus : true ,
433+ state : this . createPageState ( ) ,
434+ } ) ;
435+ }
431436 }
432437
433438 clearSelection ( ) {
439+ const oldSelection = this . selection ;
434440 this . selection = undefined ;
435441
436- goto ( `?${ page . url . searchParams } ` , {
437- keepFocus : true ,
438- state : this . createPageState ( ) ,
439- } ) ;
442+ if ( oldSelection !== undefined ) {
443+ goto ( `?${ page . url . searchParams } ` , {
444+ keepFocus : true ,
445+ state : this . createPageState ( ) ,
446+ } ) ;
447+ }
440448 }
441449
442450 scrollToFile ( index : number , options : { autoExpand ?: boolean ; smooth ?: boolean ; focus ?: boolean } = { } ) {
@@ -604,7 +612,7 @@ export class MultiFileDiffViewerState {
604612
605613 if ( this . urlSelection ) {
606614 // TODO: This does store store the proper scroll offset on initial load
607-
615+
608616 const urlSelection = this . urlSelection ;
609617 this . urlSelection = undefined ;
610618 const file = this . fileDetails . find ( ( f ) => f . toFile === urlSelection . file ) ;
0 commit comments