Skip to content

Commit 4448f33

Browse files
committed
Fix page range bug: clamp end_index >= start_index
When consecutive sections start on the same page, end_index could become less than start_index (e.g. pages 10-9), resulting in empty context text. Clamp end_index to at least start_index so every section has at least one page of content.
1 parent c99bfde commit 4448f33

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

src/tree-builder.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ function assignRanges(nodes: TreeNode[], boundaryEnd: number): void {
5353
node.end_index = boundaryEnd;
5454
}
5555

56+
// Clamp: end must be >= start (sections on the same page)
57+
if (node.end_index < node.start_index) {
58+
node.end_index = node.start_index;
59+
}
60+
5661
if (node.nodes.length > 0) {
5762
assignRanges(node.nodes, node.end_index);
5863
}

treedex/tree_builder.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def _assign_ranges(nodes: list[dict], boundary_end: int):
3737
else:
3838
node["end_index"] = boundary_end
3939

40+
# Clamp: end must be >= start (sections on the same page)
41+
if node["end_index"] < node["start_index"]:
42+
node["end_index"] = node["start_index"]
43+
4044
if node.get("nodes"):
4145
_assign_ranges(node["nodes"], node["end_index"])
4246

0 commit comments

Comments
 (0)