Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/builder/Digitized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ export async function getAnnotationPage(item: RootItem, text: Text): Promise<Ann
const resource = Resource.createTextResource(word.content, text.language);
const annotation = new Annotation(annoUri(item.id, childItem.id, word.idx), resource, 'supplementing');

annotation.setTextGranularity('word');
if (word.content.split(/\s+/).filter(w => w.length > 0).length > 1){

annotation.setTextGranularity('line');
}else{
annotation.setTextGranularity('word');
}

annotation.setCanvas(canvas, {x: word.x, y: word.y, w: word.width, h: word.height});

annotations.push(annotation);
Expand Down
15 changes: 13 additions & 2 deletions src/search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,21 @@ function mapMatches(text: Text, hl: string, matchExact: string | null): SearchRe
.split(/[\t\r\n\s]+/)
.filter(token => token.length > 0);

let id = 0;
const extractedWords: TextWord[] = [];
for (const word of words) {
const splitAttempt = word.content.split(/\s+/).filter(w => w.length > 0);
if (splitAttempt.length > 1) {
extractedWords.push(...splitAttempt.map(w => <TextWord>{ ...word, idx: id++, content: w, isHyphenated: false }));
} else {
extractedWords.push(<TextWord>{ ...word, idx: id++ });
}
}

let tokenIdx = 0, wordIdx = 0, curMatch: SearchResultMatch | null = null;
while (tokenIdx < tokens.length) {
const token = tokens[tokenIdx];
const word = wordIdx < words.length ? words[wordIdx] : null;
const word = wordIdx < extractedWords.length ? extractedWords[wordIdx] : null;

if (token.startsWith(PRE_TAG)) {
if (curMatch == null)
Expand All @@ -159,7 +170,7 @@ function mapMatches(text: Text, hl: string, matchExact: string | null): SearchRe

if (word?.isHyphenated) {
wordIdx++;
curMatch?.words.push(words[wordIdx]);
curMatch?.words.push(extractedWords[wordIdx]);
}

if (curMatch && (!matchExact || matchExact === curMatch.match)) {
Expand Down