Upload folder using huggingface_hub
Browse files
client/src/components/Refinity.tsx
CHANGED
|
@@ -1643,6 +1643,36 @@ const EditorPane: React.FC<{ source: string; initialTranslation: string; onBack:
|
|
| 1643 |
if (pos < textValue.length) html += escapeHtml(textValue.slice(pos));
|
| 1644 |
return html;
|
| 1645 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1646 |
function offsetsToClientRect(container: HTMLElement, start: number, end: number): DOMRect | null {
|
| 1647 |
const walker = document.createTreeWalker(container, NodeFilter.SHOW_TEXT, null);
|
| 1648 |
let charCount = 0;
|
|
@@ -1822,6 +1852,7 @@ const EditorPane: React.FC<{ source: string; initialTranslation: string; onBack:
|
|
| 1822 |
const val = e.target.value;
|
| 1823 |
if (!commentsSaved) return; // locked
|
| 1824 |
setDirty(true);
|
|
|
|
| 1825 |
setText(val);
|
| 1826 |
}}
|
| 1827 |
onMouseUp={()=>{
|
|
|
|
| 1643 |
if (pos < textValue.length) html += escapeHtml(textValue.slice(pos));
|
| 1644 |
return html;
|
| 1645 |
}
|
| 1646 |
+
// Adjust annotations when text changes so highlights track or are removed
|
| 1647 |
+
const adjustAnnotationsForEdit = React.useCallback((oldText: string, newText: string) => {
|
| 1648 |
+
if (oldText === newText) return;
|
| 1649 |
+
const oldLen = oldText.length, newLen = newText.length;
|
| 1650 |
+
let i = 0;
|
| 1651 |
+
while (i < oldLen && i < newLen && oldText[i] === newText[i]) i++;
|
| 1652 |
+
let a = oldLen - 1, b = newLen - 1;
|
| 1653 |
+
while (a >= i && b >= i && oldText[a] === newText[b]) { a--; b--; }
|
| 1654 |
+
const oldEditStart = i;
|
| 1655 |
+
const oldEditEnd = a + 1; // [oldEditStart, oldEditEnd) replaced
|
| 1656 |
+
const delta = (b + 1) - (a + 1); // change in length
|
| 1657 |
+
setAnnotations(prev => {
|
| 1658 |
+
const others = prev.filter(p => p.versionId !== versionId);
|
| 1659 |
+
const mine = prev.filter(p => p.versionId === versionId);
|
| 1660 |
+
const adjusted: Ann[] = [];
|
| 1661 |
+
mine.forEach(ann => {
|
| 1662 |
+
if (ann.end <= oldEditStart) {
|
| 1663 |
+
// entirely before edit region
|
| 1664 |
+
adjusted.push(ann);
|
| 1665 |
+
} else if (ann.start >= oldEditEnd) {
|
| 1666 |
+
// entirely after edit region → shift by delta
|
| 1667 |
+
adjusted.push({ ...ann, start: ann.start + delta, end: ann.end + delta });
|
| 1668 |
+
} else {
|
| 1669 |
+
// overlaps the edited region → remove (treat highlight as deleted with text)
|
| 1670 |
+
// do nothing (drop this annotation)
|
| 1671 |
+
}
|
| 1672 |
+
});
|
| 1673 |
+
return [...others, ...adjusted];
|
| 1674 |
+
});
|
| 1675 |
+
}, [versionId, setAnnotations]);
|
| 1676 |
function offsetsToClientRect(container: HTMLElement, start: number, end: number): DOMRect | null {
|
| 1677 |
const walker = document.createTreeWalker(container, NodeFilter.SHOW_TEXT, null);
|
| 1678 |
let charCount = 0;
|
|
|
|
| 1852 |
const val = e.target.value;
|
| 1853 |
if (!commentsSaved) return; // locked
|
| 1854 |
setDirty(true);
|
| 1855 |
+
adjustAnnotationsForEdit(text, val);
|
| 1856 |
setText(val);
|
| 1857 |
}}
|
| 1858 |
onMouseUp={()=>{
|