@@ -169,7 +169,7 @@ func (m *Model) refreshViewportContent() {
169169 }
170170
171171 var lines []string
172- parentIsLast := make ([ ]bool , 100 )
172+ parentIsLast := make (map [ int ]bool )
173173
174174 for i , node := range nodes {
175175 var prefixBuilder strings.Builder
@@ -184,27 +184,26 @@ func (m *Model) refreshViewportContent() {
184184 treeBranch := "├── "
185185 if node .IsLast {
186186 treeBranch = "└── "
187- if node .Level >= 0 {
188- parentIsLast [node .Level ] = true
189- }
187+ parentIsLast [node .Level ] = true
190188 } else {
191- if node .Level >= 0 {
192- parentIsLast [node .Level ] = false
193- }
189+ parentIsLast [node .Level ] = false
194190 }
195191 for l := node .Level + 1 ; l < len (parentIsLast ); l ++ {
196192 parentIsLast [l ] = false
197193 }
198194
199195 treePrefix := prefixBuilder .String () + treeBranch
200196
201- rawDirIndicator := ""
202- if node .IsDir {
197+ icon := node .Icon
198+ iconColor := node .IconColor
199+ if node .IsDir && icon == "" {
203200 if m .collapsed [node .Path ] {
204- rawDirIndicator = " "
201+ icon = ""
205202 } else {
206- rawDirIndicator = " "
203+ icon = ""
207204 }
205+ // Fallback to use theme directory color
206+ iconColor = ""
208207 }
209208
210209 isPartialDir := ! m .selected [node .Path ] && dirsWithSelectedChildren [node .Path ] && node .IsDir
@@ -250,7 +249,8 @@ func (m *Model) refreshViewportContent() {
250249 rendered := ui .StyleFileLine (
251250 rawCheckbox ,
252251 treePrefix ,
253- rawDirIndicator ,
252+ icon ,
253+ iconColor ,
254254 rawName ,
255255 rawSuffix ,
256256 node .IsDir ,
@@ -293,59 +293,76 @@ func (m *Model) getTotalFileCount() int {
293293 return count
294294}
295295
296+ // getSelectedFileCount calculates the effective number of selected files.
297+ // This considers explicitly selected files, files within selected directories
298+ // (respecting search results), and excludes deselected files.
296299func (m * Model ) getSelectedFileCount () int {
297- selectedCount := 0
300+ effectiveSelection := make ( map [ string ] bool )
298301
299- userSelectedFiles := make (map [string ]bool )
300- for p , sel := range m .selected {
301- if sel && ! m .isDependency [p ] {
302- userSelectedFiles [p ] = true
303- }
304- }
305- selectedDirs := make (map [string ]bool )
306- for p := range userSelectedFiles {
307- for _ , f := range m .files {
308- if f .Path == p && f .IsDir {
309- selectedDirs [p ] = true
310- break
311- }
302+ searchResultPaths := make (map [string ]bool )
303+ useSearchResults := m .isSearching && len (m .searchResults ) > 0
304+ if useSearchResults {
305+ for _ , node := range m .searchResults {
306+ searchResultPaths [node .Path ] = true
312307 }
313308 }
314309
315- for _ , file := range m .files {
316- if file . IsDir {
310+ for _ , item := range m .files {
311+ if effectiveSelection [ item . Path ] {
317312 continue
318313 }
319314
320- if m .deselected [file .Path ] {
315+ if m .deselected [item .Path ] {
321316 continue
322317 }
323318
324- if m .selected [file .Path ] {
325- selectedCount ++
326- continue
319+ if useSearchResults && ! searchResultPaths [item .Path ] {
320+ isChildOfSearchResult := false
321+ parent := filepath .Dir (item .Path )
322+ for parent != "." && parent != "/" {
323+ if searchResultPaths [parent ] {
324+ isChildOfSearchResult = true
325+ break
326+ }
327+ parent = filepath .Dir (parent )
328+ }
329+ if ! isChildOfSearchResult {
330+ continue
331+ }
327332 }
328333
329- currentDir := filepath .Dir (file .Path )
330- isInSelectedDir := false
331- for currentDir != "." && currentDir != "/" {
332- if selectedDirs [currentDir ] {
333- isInSelectedDir = true
334- break
334+ if m .selected [item .Path ] {
335+ if ! item .IsDir {
336+ effectiveSelection [item .Path ] = true
337+ } else {
338+ prefix := item .Path + string (os .PathSeparator )
339+ for _ , child := range m .files {
340+ if ! child .IsDir && strings .HasPrefix (child .Path , prefix ) && ! m .deselected [child .Path ] {
341+ if useSearchResults && ! searchResultPaths [child .Path ] {
342+ continue
343+ }
344+ effectiveSelection [child .Path ] = true
345+ }
346+ }
335347 }
336- currentDir = filepath . Dir ( currentDir )
348+ continue
337349 }
338350
339- if isInSelectedDir {
340- if m .isSearching && len (m .searchResults ) > 0 {
341- if m .isInSearchResults (file .Path ) {
342- selectedCount ++
351+ if ! item .IsDir {
352+ parent := filepath .Dir (item .Path )
353+ isInSelectedDir := false
354+ for parent != "." && parent != "/" {
355+ if m .selected [parent ] {
356+ isInSelectedDir = true
357+ break
343358 }
344- } else {
345- selectedCount ++
359+ parent = filepath .Dir (parent )
360+ }
361+ if isInSelectedDir {
362+ effectiveSelection [item .Path ] = true
346363 }
347364 }
348365 }
349366
350- return selectedCount
367+ return len ( effectiveSelection )
351368}
0 commit comments