@@ -82,6 +82,38 @@ func TestModelFollowUsesMostRecentChangedPath(t *testing.T) {
8282 }
8383}
8484
85+ // TestModelFollowPrefersLatestHighlightedPath verifies active follow mode uses
86+ // the last file with a newly highlighted hunk over a later changed path that
87+ // produced no new diff hunk.
88+ func TestModelFollowPrefersLatestHighlightedPath (t * testing.T ) {
89+ model := NewModel ("repo" , "/tmp/repo" , "sha" , []internal.FileDiff {
90+ fileWithHunks ("a.txt" , addHunk (10 , "stable" )),
91+ fileWithHunks ("b.txt" , addHunk (10 , "old" )),
92+ })
93+ model .Width = 80
94+ model .Height = 5
95+
96+ updated , _ := model .Update (FilesUpdatedMsg {
97+ BaselineSHA : "sha" ,
98+ Files : []internal.FileDiff {
99+ fileWithHunks ("a.txt" , addHunk (10 , "stable" )),
100+ fileWithHunks ("b.txt" ,
101+ addHunk (10 , "old" ),
102+ addHunk (20 , "latest" ),
103+ ),
104+ },
105+ ChangedPaths : []string {"b.txt" , "a.txt" },
106+ })
107+
108+ got := updated .(Model )
109+ if got .CurrentIdx != 1 {
110+ t .Fatalf ("CurrentIdx = %d, want 1 for highlighted path b.txt" , got .CurrentIdx )
111+ }
112+ if got .ScrollOffset == 0 {
113+ t .Fatalf ("ScrollOffset = %d, want non-zero for latest highlighted hunk" , got .ScrollOffset )
114+ }
115+ }
116+
85117// TestModelPausedFollowTracksLastChangedPath verifies paused follow keeps the
86118// current file selected and records the latest changed path without +N state.
87119func TestModelPausedFollowTracksLastChangedPath (t * testing.T ) {
0 commit comments