@@ -292,6 +292,7 @@ function App() {
292292 selectedImagePathRef . current = selectedImage ?. path ?? null ;
293293 } , [ selectedImage ?. path ] ) ;
294294 const [ multiSelectedPaths , setMultiSelectedPaths ] = useState < Array < string > > ( [ ] ) ;
295+ const [ selectionAnchorPath , setSelectionAnchorPath ] = useState < string | null > ( null ) ;
295296 const [ libraryActivePath , setLibraryActivePath ] = useState < string | null > ( null ) ;
296297 const [ libraryActiveAdjustments , setLibraryActiveAdjustments ] = useState < Adjustments > ( INITIAL_ADJUSTMENTS ) ;
297298 const [ finalPreviewUrl , setFinalPreviewUrl ] = useState < string | null > ( null ) ;
@@ -3820,17 +3821,18 @@ function App() {
38203821 const { shiftAnchor, onSimpleClick, updateLibraryActivePath } = options ;
38213822
38223823 if ( shiftKey && shiftAnchor ) {
3823- const lastIndex = sortedImageList . findIndex ( ( f ) => f . path === shiftAnchor ) ;
3824+ const anchorIndex = sortedImageList . findIndex ( ( f ) => f . path === shiftAnchor ) ;
38243825 const currentIndex = sortedImageList . findIndex ( ( f ) => f . path === path ) ;
38253826
3826- if ( lastIndex !== - 1 && currentIndex !== - 1 ) {
3827- const start = Math . min ( lastIndex , currentIndex ) ;
3828- const end = Math . max ( lastIndex , currentIndex ) ;
3827+ if ( anchorIndex !== - 1 && currentIndex !== - 1 ) {
3828+ const start = Math . min ( anchorIndex , currentIndex ) ;
3829+ const end = Math . max ( anchorIndex , currentIndex ) ;
38293830 const range = sortedImageList . slice ( start , end + 1 ) . map ( ( f : ImageFile ) => f . path ) ;
3830- const baseSelection = isCtrlPressed ? multiSelectedPaths : [ shiftAnchor ] ;
3831+ const baseSelection = isCtrlPressed ? multiSelectedPaths : [ ] ;
38313832 const newSelection = Array . from ( new Set ( [ ...baseSelection , ...range ] ) ) ;
38323833
38333834 setMultiSelectedPaths ( newSelection ) ;
3835+ setSelectionAnchorPath ( path ) ;
38343836 if ( updateLibraryActivePath ) {
38353837 setLibraryActivePath ( path ) ;
38363838 }
@@ -3845,6 +3847,7 @@ function App() {
38453847
38463848 const newSelectionArray = Array . from ( newSelection ) ;
38473849 setMultiSelectedPaths ( newSelectionArray ) ;
3850+ setSelectionAnchorPath ( path ) ;
38483851
38493852 if ( updateLibraryActivePath ) {
38503853 if ( newSelectionArray . includes ( path ) ) {
@@ -3857,26 +3860,31 @@ function App() {
38573860 }
38583861 } else {
38593862 onSimpleClick ( path ) ;
3863+ setSelectionAnchorPath ( path ) ;
38603864 }
38613865 } ;
38623866
38633867 const handleLibraryImageSingleClick = ( path : string , event : any ) => {
38643868 handleMultiSelectClick ( path , event , {
3865- shiftAnchor : libraryActivePath ,
3869+ shiftAnchor : selectionAnchorPath ?? libraryActivePath ,
38663870 updateLibraryActivePath : true ,
38673871 onSimpleClick : ( p : any ) => {
38683872 setMultiSelectedPaths ( [ p ] ) ;
38693873 setLibraryActivePath ( p ) ;
3874+ setSelectionAnchorPath ( p ) ;
38703875 } ,
38713876 } ) ;
38723877 } ;
38733878
38743879 const handleImageClick = ( path : string , event : any ) => {
38753880 const inEditor = ! ! selectedImage ;
38763881 handleMultiSelectClick ( path , event , {
3877- shiftAnchor : inEditor ? selectedImage . path : libraryActivePath ,
3882+ shiftAnchor : selectionAnchorPath ?? ( inEditor ? selectedImage . path : libraryActivePath ) ,
38783883 updateLibraryActivePath : ! inEditor ,
3879- onSimpleClick : handleImageSelect ,
3884+ onSimpleClick : ( p : string ) => {
3885+ handleImageSelect ( p ) ;
3886+ setSelectionAnchorPath ( p ) ;
3887+ } ,
38803888 } ) ;
38813889 } ;
38823890
0 commit comments