Skip to content

Commit

Permalink
fix: better Toc navigation
Browse files Browse the repository at this point in the history
* when searching a reference in the Table-Of-Content navigation screen, the full text of the refereence will show. (before, you could some time  get סימן א, סימן א, סימן א. now you will get חושן משפט סימן א, אבן העזר סימן א, etc.)
  • Loading branch information
Sivan22 committed Jan 11, 2025
1 parent 7a81aaa commit d2a44ca
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/data/data_providers/file_system_data_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,14 @@ class FileSystemData {
final int level = int.parse(line[2]); // Extract heading level
final String text = stripHtmlIfNeeded(line);

TocEntry entry = TocEntry(text: text, index: i, level: level);

if (level == 1) {
// Add h1 headings as root nodes
TocEntry entry = TocEntry(text: text, index: i, level: level);
toc.add(entry);
parents[level] = entry;
} else {
TocEntry entry = TocEntry(
text: text, index: i, level: level, parent: parents[level - 1]);
// Add other headings under their parent
final TocEntry? parent = parents[level - 1];
if (parent != null) {
Expand Down
11 changes: 11 additions & 0 deletions lib/models/books.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,24 @@ class TocEntry {
String text;
final int index;
final int level;
final TocEntry? parent;
List<TocEntry> children = [];
String get fullText => () {
TocEntry? parent = this.parent;
String text = this.text;
while (parent != null && parent.level > 1) {
text = '${parent!.text}, $text';
parent = parent.parent;
}
return text;
}();

///creats [TocEntry]
TocEntry({
required this.text,
required this.index,
this.level = 1,
this.parent,
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/screens/reading/text/toc_navigator_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class _TocViewerState extends State<TocViewer>
padding: EdgeInsets.fromLTRB(
0, 0, 10 * allEntries[index].level.toDouble(), 0),
child: ListTile(
title: Text(allEntries[index].text),
title: Text(allEntries[index].fullText),
onTap: () {
widget.scrollController.scrollTo(
index: allEntries[index].index,
Expand Down

0 comments on commit d2a44ca

Please sign in to comment.