Skip to content
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

fix: LEAP-240: Prevent creating region on clicking outside selected one #5303

Merged
merged 12 commits into from
Jan 29, 2024
Merged
2 changes: 1 addition & 1 deletion label_studio/frontend/dist/lsf/js/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion label_studio/frontend/dist/lsf/js/main.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions label_studio/frontend/dist/lsf/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"message": "fix: LEAP-246: Replace overlaping MIG hotkeys",
"commit": "309d0f9451619e3c714044ddc1ff99d91613fb6f",
"branch": "master",
"date": "2024-01-17T16:09:13Z"
"message": "fix: LEAP-240: Prevent creating region on clicking outside selected one",
"commit": "4faed9ac55d7386cbd9af8a1ade66d064a13d16e",
"branch": "fb-leap-240/fix-click-outside",
"date": "2024-01-18T04:45:00Z"
}
2 changes: 1 addition & 1 deletion web/dist/libs/editor/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/dist/libs/editor/main.js.map

Large diffs are not rendered by default.

41 changes: 30 additions & 11 deletions web/libs/editor/src/components/ImageView/ImageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ export default observer(
crosshairRef = createRef();
handleDeferredMouseDown = null;
deferredClickTimeout = [];
skipMouseUp = false;
skipNextMouseDown = false;
skipNextClick = false;
skipNextMouseUp = false;
mouseDownPoint = null;

constructor(props) {
Expand All @@ -520,10 +522,10 @@ export default observer(
const { item } = this.props;

if (isFF(FF_DEV_1442)) {
this.handleDeferredMouseDown?.();
this.handleDeferredMouseDown?.(true);
}
if (this.skipMouseUp) {
this.skipMouseUp = false;
if (this.skipNextClick) {
this.skipNextClick = false;
return;
}

Expand Down Expand Up @@ -556,8 +558,8 @@ export default observer(
};

handleDeferredClick = (handleDeferredMouseDownCallback, handleDeselection, eligibleToDeselect = false) => {
this.handleDeferredMouseDown = () => {
if (eligibleToDeselect) {
this.handleDeferredMouseDown = (wasClicked) => {
if (wasClicked && eligibleToDeselect) {
handleDeselection();
}
handleDeferredMouseDownCallback();
Expand All @@ -566,7 +568,7 @@ export default observer(
};
this.resetDeferredClickTimeout();
this.deferredClickTimeout.push(setTimeout(() => {
this.handleDeferredMouseDown?.();
this.handleDeferredMouseDown?.(false);
}, this.props.item.annotation.isDrawing ? 0 : 100));
};

Expand All @@ -575,6 +577,7 @@ export default observer(
const isPanTool = item.getToolsManager().findSelectedTool()?.fullName === 'ZoomPanTool';
const isMoveTool = item.getToolsManager().findSelectedTool()?.fullName === 'MoveTool';

this.skipNextMouseDown = this.skipNextMouseUp = this.skipNextClick = false;
if (isFF(FF_LSDV_4930)) {
this.mouseDownPoint = { x: e.evt.offsetX, y: e.evt.offsetY };
}
Expand Down Expand Up @@ -626,6 +629,10 @@ export default observer(

this.canvasX = left;
this.canvasY = top;
if (this.skipNextMouseDown) {
this.skipNextMouseDown = false;
return true;
}
item.event('mousedown', e, x, y);

return true;
Expand All @@ -652,7 +659,9 @@ export default observer(

const handleDeselection = () => {
item.annotation.unselectAll();
this.skipMouseUp = true;
this.skipNextMouseDown = true;
this.skipNextMouseUp = true;
this.skipNextClick = true;
};

this.handleDeferredClick(handleMouseDown, handleDeselection, eligibleToDeselect);
Expand Down Expand Up @@ -680,7 +689,7 @@ export default observer(

item.freezeHistory();

return item.event('mouseup', e, x - this.canvasX, y - this.canvasY);
return this.triggerMouseUp(e, x - this.canvasX, y - this.canvasY);
};

handleGlobalMouseMove = e => {
Expand All @@ -705,7 +714,17 @@ export default observer(
item.freezeHistory();
item.setSkipInteractions(false);

return item.event('mouseup', e, e.evt.offsetX, e.evt.offsetY);
return this.triggerMouseUp(e, e.evt.offsetX, e.evt.offsetY);
};

triggerMouseUp = (e, x, y) => {
if (this.skipNextMouseUp) {
this.skipNextMouseUp = false;
return;
}
const { item } = this.props;

return item.event('mouseup', e, x, y);
};

handleMouseMove = e => {
Expand All @@ -721,7 +740,7 @@ export default observer(

if (isFF(FF_DEV_1442) && isDragging) {
this.resetDeferredClickTimeout();
this.handleDeferredMouseDown?.();
this.handleDeferredMouseDown?.(false);
}

if ((isMouseWheelClick || isShiftDrag) && item.zoomScale > 1) {
Expand Down
2 changes: 1 addition & 1 deletion web/libs/editor/src/tags/object/RichText/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const Model = types
// nodes count better be the same, so replace them with stubs
// we should not sanitize text tasks because we already have htmlEscape in view.js
if (isFF(FF_SAFE_TEXT) && self.type === 'text') {
self._value = String(val);
self._value = val;
} else {
self._value = sanitizeHtml(String(val));
}
Expand Down
4 changes: 2 additions & 2 deletions web/libs/editor/src/utils/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export const parseValue = (value, task) => {

// value can refer to structures, not only texts, so just replace wouldn't be enough
if (value.match(reVar)?.[0] === value) {
return get(task, value.slice(1)) ?? '';
return get(task, value.substr(1)) ?? '';
}

return value.replace(reVar, (v) => get(task, v.slice(1) ?? ''));
return value.replace(reVar, (v) => get(task, v.substr(1) ?? ''));
};

/**
Expand Down
Loading