@@ -17,13 +17,20 @@ import { DiffSplitWidgetLine } from "./DiffSplitWidgetLineNormal";
1717
1818import type { DiffFile } from "@git-diff-view/core" ;
1919
20- const DiffSplitViewTable = ( props : { side : SplitSide ; diffFile : DiffFile ; onSelect ?: ( side ?: SplitSide ) => void } ) => {
20+ const DiffSplitViewTable = ( props : {
21+ side : SplitSide ;
22+ diffFile : DiffFile ;
23+ onSelect ?: ( side ?: SplitSide ) => void ;
24+ selectState : { current ?: SplitSide } ;
25+ } ) => {
2126 const className = createMemo ( ( ) => ( props . side === SplitSide . new ? "new-diff-table" : "old-diff-table" ) ) ;
2227
2328 const getAllLines = ( ) => getSplitContentLines ( props . diffFile ) ;
2429
2530 const [ lines , setLines ] = createSignal ( getAllLines ( ) ) ;
2631
32+ const selectState = props . selectState ;
33+
2734 createEffect ( ( ) => {
2835 const init = ( ) => setLines ( getAllLines ) ;
2936
@@ -46,11 +53,17 @@ const DiffSplitViewTable = (props: { side: SplitSide; diffFile: DiffFile; onSele
4653 const state = ele . getAttribute ( "data-state" ) ;
4754 if ( state ) {
4855 if ( state === "extend" || state === "hunk" || state === "widget" ) {
49- props . onSelect ?.( undefined ) ;
50- removeAllSelection ( ) ;
56+ if ( selectState . current !== undefined ) {
57+ selectState . current = undefined ;
58+ props . onSelect ?.( undefined ) ;
59+ removeAllSelection ( ) ;
60+ }
5161 } else {
52- props . onSelect ?.( props . side ) ;
53- removeAllSelection ( ) ;
62+ if ( selectState . current !== props . side ) {
63+ selectState . current = props . side ;
64+ props . onSelect ?.( props . side ) ;
65+ removeAllSelection ( ) ;
66+ }
5467 }
5568 return ;
5669 }
@@ -134,6 +147,8 @@ export const DiffSplitViewNormal = (props: { diffFile: DiffFile }) => {
134147
135148 createEffect ( initSyncScroll ) ;
136149
150+ const selectState = { current : undefined as SplitSide | undefined } ;
151+
137152 const onSelect = ( side ?: SplitSide ) => {
138153 const ele = styleRef ( ) ;
139154
@@ -169,7 +184,12 @@ export const DiffSplitViewNormal = (props: { diffFile: DiffFile }) => {
169184 "font-size" : `var(${ diffFontSizeName } )` ,
170185 } }
171186 >
172- < DiffSplitViewTable side = { SplitSide . old } diffFile = { props . diffFile } onSelect = { onSelect } />
187+ < DiffSplitViewTable
188+ side = { SplitSide . old }
189+ diffFile = { props . diffFile }
190+ onSelect = { onSelect }
191+ selectState = { selectState }
192+ />
173193 </ div >
174194 < div class = "diff-split-line w-[1.5px]" style = { { "background-color" : `var(${ borderColorName } )` } } />
175195 < div
@@ -182,7 +202,12 @@ export const DiffSplitViewNormal = (props: { diffFile: DiffFile }) => {
182202 "font-size" : `var(${ diffFontSizeName } )` ,
183203 } }
184204 >
185- < DiffSplitViewTable side = { SplitSide . new } diffFile = { props . diffFile } onSelect = { onSelect } />
205+ < DiffSplitViewTable
206+ side = { SplitSide . new }
207+ diffFile = { props . diffFile }
208+ onSelect = { onSelect }
209+ selectState = { selectState }
210+ />
186211 </ div >
187212 </ div >
188213 ) ;
0 commit comments