Skip to content

Commit dc90588

Browse files
make page title highlighting work
1 parent 5dd90d1 commit dc90588

3 files changed

Lines changed: 38 additions & 117 deletions

File tree

typescript/src/renderer/utils/blockMapping.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

typescript/src/renderer/utils/highlightUtils.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export interface Backref {
22
end_idx: number;
33
start_idx: number;
44
block_id?: string;
5+
page_id?: string;
56
}
67

78
export interface HighlightElement {
@@ -88,9 +89,15 @@ export function highlightTextNode(
8889
}
8990

9091
/**
91-
* Processes a single backref and applies highlighting to the target block
92+
* Processes a single backref and applies highlighting to the target block or page title
9293
*/
9394
export function processBackref(backref: Backref): HTMLSpanElement | null {
95+
// If page_id is provided, target the page title
96+
if (backref.page_id) {
97+
return processPageTitleBackref(backref);
98+
}
99+
100+
// Otherwise, handle block highlighting as before
94101
if (!backref.block_id) {
95102
return null;
96103
}
@@ -120,6 +127,36 @@ export function processBackref(backref: Backref): HTMLSpanElement | null {
120127
return firstSpanForThisBackref;
121128
}
122129

130+
/**
131+
* Processes a backref that targets a page title
132+
*/
133+
export function processPageTitleBackref(backref: Backref): HTMLSpanElement | null {
134+
// Find the specific page title element using data-page-id
135+
const pageTitleElement = document.querySelector(
136+
`[data-page-id="${backref.page_id}"]`
137+
);
138+
139+
if (!pageTitleElement) {
140+
return null;
141+
}
142+
143+
const textNodes = getTextNodes(pageTitleElement);
144+
let currentIndex = 0;
145+
let firstSpanForThisBackref: HTMLSpanElement | null = null;
146+
147+
for (const textNode of textNodes) {
148+
const highlightSpan = highlightTextNode(textNode, backref, currentIndex);
149+
150+
if (highlightSpan && !firstSpanForThisBackref) {
151+
firstSpanForThisBackref = highlightSpan;
152+
}
153+
154+
currentIndex += textNode.textContent?.length || 0;
155+
}
156+
157+
return firstSpanForThisBackref;
158+
}
159+
123160
/**
124161
* Sorts highlight elements by their DOM position (reading order)
125162
*/

typescript/src/renderer/utils/richTextRenderer.js

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)