Skip to content

Label selection box position fix #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 11, 2025
Merged
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ export default function LabelingSuiteLabeling() {
if (!tokenLookup || !extractionRef.current) return;
const handleMouseUp = (e) => {
const [check, attributeIdStart, tokenStart, tokenEnd, startEl] = parseSelectionData();
console.log(startEl)
dispatch(setActiveTokenSelection({ attributeId: attributeIdStart, tokenStart, tokenEnd }));
if (!check) {
clearSelected();
} else {
window.getSelection().empty();
setSelected(attributeIdStart, tokenStart, tokenEnd, startEl);
setSelected(attributeIdStart, tokenStart, tokenEnd, e, startEl);
}
};
extractionRef.current.addEventListener('mouseup', handleMouseUp);
Expand Down Expand Up @@ -474,7 +475,7 @@ export default function LabelingSuiteLabeling() {
dispatch(setActiveTokenSelection(null));
}, [tokenLookup]);

function setSelected(attributeId: string, tokenStart: number, tokenEnd: number, e?: any) {
function setSelected(attributeId: string, tokenStart: number, tokenEnd: number, e?: any, startEl?: DOMRect) {
if (!canEditLabels && user.role != UserRole.ANNOTATOR && userDisplayRole != UserRole.ANNOTATOR) return;
const tokenLookupCopy = jsonCopy(tokenLookup);
if (!tokenLookupCopy[attributeId]) {
Expand All @@ -489,11 +490,11 @@ export default function LabelingSuiteLabeling() {
setActiveTasksFuncRef.current(lVars.taskLookup[attributeId].lookup);
}
setTokenLookup(tokenLookupCopy);
labelBoxPosition(e);
labelBoxPosition(e, startEl);
}

function labelBoxPosition(e) {
const labelBox: DOMRect = e.target?.getBoundingClientRect();
function labelBoxPosition(e: any, startEl?: any) {
const labelBox: DOMRect = startEl ? startEl.getBoundingClientRect() : (e.target as HTMLElement).getBoundingClientRect();
if (!labelBox) return;
const baseBox: DOMRect = document.getElementById('base-dom-element')?.getBoundingClientRect();
if (!baseBox) return;
Expand Down