Fix alphabet highlight for names starting with "The " (#1788)

## Description
The alphabet scroll bar highlighted the letter of an item's *display*
name while the grid sorted by the server's article-stripped `SortName`,
so "The Beatles" sat under **B** but highlighted **T**.

- **Artists:** the Artists tab never requested `SortName`, so the
highlight silently fell back to `Name`. It now asks for `SlimItemFields`
(which already includes `SORT_NAME`), matching the sibling `/Items`
branch. The count-only query used for letter positions passes `fields =
null`, since a `limit = 0` request has no use for them.
- **Genres and studios:** these grids bucketed on the display name
unconditionally. The sort-name fallback is extracted as
`BaseItemDto.alphabetSortName` (`sortName ?: name ?: ""`) and carried
onto the `Genre` and `Studio` grid items, so all three grids now derive
the letter from one value.

### Related issues
https://github.com/damontecres/Wholphin/issues/1787

### Testing
Two unit tests added:
- `CollectionFolderViewModelTest` pins that the artist pager actually
requests `SORT_NAME` — the field whose absence caused the bug.
- `AlphabetSortNameTest` covers both branches of the `alphabetSortName`
fallback.

Manually: select a music library → Artists tab → put the cursor on an
artist starting with "The " and confirm the highlighted letter matches
the grid position. Same check on the genre and studio grids.

## AI or LLM usage
I used Cursor for debugging and implementing the fix, and Claude Code
for a follow-up cleanup pass over the diff.
This commit is contained in:
Stefan Bullones 2026-08-11 03:52:43 +02:00 • committed by GitHub
parent 454c0212b6
commit a0966dd05a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 73 additions and 5 deletions

View file

@ -0,0 +1,36 @@
package com.github.damontecres.wholphin.data.model
import org.jellyfin.sdk.model.api.BaseItemDto
import org.jellyfin.sdk.model.api.BaseItemKind
import org.junit.Assert.assertEquals
import org.junit.Test
import java.util.UUID
class AlphabetSortNameTest {
@Test
fun prefersSortNameOverName() {
val dto =
BaseItemDto(
id = UUID.randomUUID(),
type = BaseItemKind.MUSIC_ARTIST,
name = "The Beatles",
sortName = "beatles",
)
assertEquals("beatles", dto.alphabetSortName)
assertEquals("beatles", BaseItem(dto).sortName)
}
@Test
fun fallsBackToNameWhenSortNameMissing() {
val dto =
BaseItemDto(
id = UUID.randomUUID(),
type = BaseItemKind.STUDIO,
name = "The Walt Disney Company",
sortName = null,
)
assertEquals("The Walt Disney Company", dto.alphabetSortName)
}
}

View file

@ -33,10 +33,12 @@ import org.jellyfin.sdk.api.operations.UserLibraryApi
import org.jellyfin.sdk.model.api.BaseItemDto
import org.jellyfin.sdk.model.api.BaseItemKind
import org.jellyfin.sdk.model.api.CollectionType
import org.jellyfin.sdk.model.api.ItemFields
import org.jellyfin.sdk.model.api.request.GetArtistsRequest
import org.jellyfin.sdk.model.api.request.GetItemsRequest
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import java.util.UUID
@ -141,6 +143,19 @@ class CollectionFolderViewModelTest {
coVerify(exactly = 0) { GetItemsRequestHandler.execute(any(), any<GetItemsRequest>()) }
}
/**
* Without SortName, the alphabet highlight falls back to Name and highlights "T" for artists
* like "The Beatles" even though the grid sorts them under "B".
*/
@Test
fun `artist pager requests SortName for alphabet highlighting`() =
runTest(testDispatcher) {
createViewModel(GetItemsFilter(override = GetItemsFilterOverride.ARTIST))
advanceUntilIdle()
assertTrue(ItemFields.SORT_NAME in artistsRequest.captured.fields.orEmpty())
}
/**
* /Persons has no nameLessThan or startIndex, so counting up to a letter is not expressible.
* Falling back to /Items would count media rather than people, ie the same defect as the artist