Skip to content

Commit 16f1b3e

Browse files
committed
Fix: range selection offset
1 parent 8adb041 commit 16f1b3e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/components/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ const Designer: React.FC<ISTKProps> = (props) => {
1515
return (
1616
<>
1717
<div
18-
className={twMerge("bg-white h-full min-h-[85vh] flex flex-col", props.styles?.root?.className)}
18+
className={twMerge(
19+
"bg-white h-full min-h-[85vh] flex flex-col overflow-x-hidden",
20+
props.styles?.root?.className
21+
)}
1922
style={props?.styles?.root?.properties}
2023
>
2124
<Operations {...props} />

src/hooks/events/selection.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ const useSelection = () => {
99
useLayoutEffect(() => {
1010
const svg = d3Extended.selectById(ids.workspace);
1111
if (svg.node()) {
12-
const toolbarWidth = document.getElementById(ids.toolbar)?.clientWidth ?? 0;
13-
const operationBarHeight = document.getElementById(ids.operationBar)?.clientHeight ?? 0;
12+
const { top: workspaceTop, left: workspaceLeft } = d3Extended.selectionBounds(
13+
d3Extended.selectById(ids.workspace)
14+
);
1415
const selectionRect = {
1516
element: null,
1617
currentY: 0,
@@ -59,8 +60,8 @@ const useSelection = () => {
5960
this.update(newX, newY);
6061
},
6162
update: function (newX: number, newY: number) {
62-
this.currentX = newX - (+this.element?.attr("width") > 2 ? toolbarWidth : 0);
63-
this.currentY = newY - (+this.element?.attr("height") > 2 ? operationBarHeight : 0);
63+
this.currentX = newX - (+this.element?.attr("width") > 2 ? workspaceLeft : 0);
64+
this.currentY = newY - (+this.element?.attr("height") > 2 ? workspaceTop : 0);
6465
const attributes = this.getNewAttributes();
6566
Object.keys(attributes).forEach((key) => {
6667
this.element.attr(key, attributes[key]);

0 commit comments

Comments
 (0)