Improved TOC scrolling behavior and fixed incorrect content indentation logic. Added test for image-only sections.
This commit is contained in:
1 parent
7681590992
commit
9f54c0aca0
3 files changed
+63
-1
No files matched your search
@@ -1551,7 +1551,7 @@ internal fun buildReaderContentPlan(book: Fb2Book): ReaderContentPlan {
|
||||
}
|
||||
}
|
||||
}
|
||||
val childDepth = if (blocks.isEmpty()) readerDepth else readerDepth + 1
|
||||
val childDepth = if (blocks.hasIndentBearingContent()) readerDepth + 1 else readerDepth
|
||||
addSections(section.sections, childDepth)
|
||||
}
|
||||
|
||||
@@ -1811,6 +1811,19 @@ private fun Fb2Section.readableBlocks(): List<Fb2Block> =
|
||||
images.map(Fb2Block::Image) + paragraphs.map { Fb2Block.Paragraph(Fb2Text(listOf(Fb2TextSpan(it)))) }
|
||||
}
|
||||
|
||||
private fun List<Fb2Block>.hasIndentBearingContent(): Boolean =
|
||||
any { block ->
|
||||
when (block) {
|
||||
Fb2Block.EmptyLine,
|
||||
is Fb2Block.Image,
|
||||
is Fb2Block.Subtitle -> false
|
||||
is Fb2Block.Cite,
|
||||
is Fb2Block.Epigraph,
|
||||
is Fb2Block.Paragraph,
|
||||
is Fb2Block.Poem -> true
|
||||
}
|
||||
}
|
||||
|
||||
private data class ChapterEntry(
|
||||
val title: String,
|
||||
val section: Fb2Section,
|
||||
|
||||
@@ -693,11 +693,23 @@ private fun TableOfContentsDialog(
|
||||
onOpenEntry: (ReaderTocEntry) -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
val selectedEntryIndex = currentItemIndex?.let { itemIndex ->
|
||||
contentPlan.tocEntries.indexOfFirst { it.itemIndex == itemIndex }.takeIf { it >= 0 }
|
||||
}
|
||||
val listState = rememberLazyListState(
|
||||
initialFirstVisibleItemIndex = selectedEntryIndex?.let { it + 1 } ?: 0,
|
||||
)
|
||||
|
||||
LaunchedEffect(contentPlan, selectedEntryIndex) {
|
||||
selectedEntryIndex?.let { listState.scrollToItem(it + 1) }
|
||||
}
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(strings.tableOfContents) },
|
||||
text = {
|
||||
LazyColumn(
|
||||
state = listState,
|
||||
modifier = Modifier.fillMaxWidth().heightIn(max = 480.dp),
|
||||
) {
|
||||
item(key = "back") {
|
||||
|
||||
Reference in new issue
Block a user