@@ -625,42 +625,41 @@ func (m aiModel) View() string {
625625}
626626
627627// calcVisibleRange calculates the visible file range for auto-scrolling.
628- // It prioritizes showing running files in the visible window.
628+ // It keeps the last running file at the bottom of the visible window,
629+ // with completed files scrolling upward as more files complete.
629630func (m aiModel ) calcVisibleRange (maxVisible int ) (start , end int ) {
630631 total := len (m .files )
631632 if total <= maxVisible {
632633 return 0 , total
633634 }
634635
635- // Find the first running file
636- firstRunning := - 1
636+ // Find the last running file to keep it visible at the bottom
637+ lastRunning := - 1
637638 for i , status := range m .fileStatus {
638639 if status == 1 { // running
639- firstRunning = i
640- break
640+ lastRunning = i
641641 }
642642 }
643643
644- // If no running file, show from the first pending or from start
645- if firstRunning < 0 {
646- // Find first pending
644+ // If no running file, find the first pending file
645+ if lastRunning < 0 {
647646 for i , status := range m .fileStatus {
648647 if status == 0 { // pending
649- firstRunning = i
648+ lastRunning = i
650649 break
651650 }
652651 }
653652 }
654653
655- // If still not found, show from start
656- if firstRunning < 0 {
657- return 0 , maxVisible
654+ // If still not found (all done) , show the last window
655+ if lastRunning < 0 {
656+ return total - maxVisible , total
658657 }
659658
660- // Center the running file in the visible window
661- // But keep some context (show a few completed files above)
662- contextAbove := 2
663- start = firstRunning - contextAbove
659+ // Position the window so the last running file is near the bottom
660+ // Leave 1-2 slots at the bottom for pending files to appear
661+ bottomMargin := 2
662+ start = lastRunning - ( maxVisible - 1 - bottomMargin )
664663 if start < 0 {
665664 start = 0
666665 }
0 commit comments