fix(library): preserve leading articles in title sorting for natural alphabetical order

This commit is contained in:
Sobhan 2026-07-27 19:09:05 +05:30
parent 88d3cbdfac
commit cfa49a2cda
2 changed files with 3 additions and 7 deletions

View file

@ -227,12 +227,8 @@ private val LibraryDisplaySettingsJson = Json {
encodeDefaults = true
}
private val LeadingLibraryTitleArticle = Regex("^(the|an|a)\\s+", RegexOption.IGNORE_CASE)
private fun libraryTitleSortKey(item: LibraryItem): String =
libraryTitleTieBreakKey(item)
.trim()
.replace(LeadingLibraryTitleArticle, "")
private fun libraryTitleTieBreakKey(item: LibraryItem): String =
item.name

View file

@ -51,7 +51,7 @@ class LibraryDisplaySettingsTest {
}
@Test
fun `title sorting ignores leading English articles`() {
fun `title sorting preserves leading articles for literal alphabetical order`() {
val input = listOf(
item("batman", name = "The Batman"),
item("arrival", name = "Arrival"),
@ -59,11 +59,11 @@ class LibraryDisplaySettingsTest {
)
assertEquals(
listOf("arrival", "batman", "quiet"),
listOf("quiet", "arrival", "batman"),
sortLibraryItems(input, LibrarySortOption.TITLE_ASC, LibrarySourceMode.LOCAL).map { it.id },
)
assertEquals(
listOf("quiet", "batman", "arrival"),
listOf("batman", "arrival", "quiet"),
sortLibraryItems(input, LibrarySortOption.TITLE_DESC, LibrarySourceMode.LOCAL).map { it.id },
)
}