-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
27 lines (23 loc) · 967 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* Automatically creates all the text regions containing all instances of the selected text.
*/
// It will be triggered when a text selection happens
LSI.on('entityCreate', region => {
if (window.BULK_REGIONS) return;
window.BULK_REGIONS = true;
setTimeout(() => window.BULK_REGIONS = false, 1000);
setTimeout(() => {
// Find all the text regions matching the selection
region.object._value.matchAll(new RegExp(region.text, "gi")).forEach(m => {
if (m.index === region.startOffset) return;
// Include them in the results as new selections
Htx.annotationStore.selected.createResult(
{ text: region.text, start: "/span[1]/text()[1]", startOffset: m.index, end: "/span[1]/text()[1]", endOffset: m.index + region.text.length },
{ labels: [...region.labeling.value.labels] },
region.labeling.from_name,
region.object,
)
})
Htx.annotationStore.selected.updateObjects()
}, 100);
});