11/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
22import { SplitSide , createDiffMultiSelectManager , multiSelectClassNames } from "@git-diff-view/core" ;
33import { DiffModeEnum } from "@git-diff-view/utils" ;
4- import { type JSXElement , type JSX , createSignal , createEffect , createMemo , onCleanup } from "solid-js" ;
4+ import { type JSXElement , type JSX , createSignal , createEffect , createMemo , onCleanup , on } from "solid-js" ;
55
66import { DiffView } from "./DiffView" ;
77
@@ -123,6 +123,16 @@ const InternalDiffViewWithMultiSelect = <T extends unknown>(props: DiffViewWithM
123123 const enableMultiSelect = ( ) => props . enableMultiSelect ?? true ;
124124 const isUnifiedMode = ( ) => ! ( ( props . diffViewMode ?? DiffModeEnum . SplitGitHub ) & DiffModeEnum . Split ) ;
125125
126+ createEffect (
127+ on (
128+ ( ) => [ props . diffViewWrap , props . diffViewMode ] ,
129+ ( ) => {
130+ setMultiResult ( undefined ) ;
131+ } ,
132+ { defer : true }
133+ )
134+ ) ;
135+
126136 createEffect ( ( ) => {
127137 const container = containerRef ( ) ;
128138 const diffFile = innerDiffFile ( ) ;
@@ -218,7 +228,9 @@ const InternalDiffViewWithMultiSelect = <T extends unknown>(props: DiffViewWithM
218228 const currentMultiResult = multiResult ( ) ;
219229 if ( currentMultiResult ) {
220230 const currentSide = SplitSide [ side ] as unknown as "new" | "old" ;
231+ const otherSide = currentSide === "new" ? "old" : "new" ;
221232 const sideResult = currentMultiResult [ currentSide ] as number [ ] ;
233+ const otherSideResult = currentMultiResult [ otherSide ] as number [ ] ;
222234 if ( sideResult ?. length ) {
223235 const max = Math . max ( ...sideResult ) ;
224236 if ( max === lineNum ) {
@@ -232,6 +244,19 @@ const InternalDiffViewWithMultiSelect = <T extends unknown>(props: DiffViewWithM
232244 return ;
233245 }
234246 }
247+ if ( isUnifiedMode ( ) && otherSideResult ?. length ) {
248+ const max = Math . max ( ...otherSideResult ) ;
249+ if ( max === lineNum ) {
250+ const finalResult = { [ otherSide ] : otherSideResult } ;
251+ setMultiResult ( finalResult as ReturnType < typeof extendDataToPreselectedLines > ) ;
252+ props . onAddWidgetClick ?.( {
253+ lineNumber : max ,
254+ fromLineNumber : Math . min ( ...otherSideResult ) ,
255+ side : otherSide === "old" ? SplitSide . old : SplitSide . new ,
256+ } ) ;
257+ return ;
258+ }
259+ }
235260 setMultiResult ( { old : [ ] , new : [ ] } ) ;
236261 props . onAddWidgetClick ?.( { lineNumber : lineNum , fromLineNumber : lineNum , side } ) ;
237262 } else {
0 commit comments