Skip to content

Commit 0ba53a6

Browse files
committed
shrinking works
1 parent 50ca3ea commit 0ba53a6

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

packages/feedback/src/screenshot/components/ScreenshotEditorv2.tsx

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,6 @@ export function ScreenshotEditorFactoryv2({
183183
}
184184
}, [currentRect]);
185185

186-
hooks.useEffect(() => {
187-
const scaledCommands = drawCommands.map(rect => {
188-
return {
189-
action: rect.action,
190-
x: rect.x * scaleFactor,
191-
y: rect.y * scaleFactor,
192-
width: rect.width * scaleFactor,
193-
height: rect.height * scaleFactor,
194-
};
195-
});
196-
197-
setDrawCommands(scaledCommands);
198-
}, [scaleFactor]);
199-
200186
function drawBuffer(): void {
201187
const ctx = imageBuffer.getContext('2d', { alpha: false });
202188
const measurementDiv = measurementRef.current;
@@ -221,10 +207,8 @@ export function ScreenshotEditorFactoryv2({
221207
grayCtx.fillRect(0, 0, imageBuffer.width, imageBuffer.height);
222208
}
223209

224-
const scale = imageBuffer.width / measurementDiv.clientWidth;
225-
226210
drawCommands.forEach(rect => {
227-
drawRect(rect, grayCtx, scale);
211+
drawRect(rect, grayCtx);
228212
});
229213
ctx.drawImage(grayWashBufferBig, 0, 0);
230214
}
@@ -248,8 +232,13 @@ export function ScreenshotEditorFactoryv2({
248232
ctx.fillRect(0, 0, graywashCanvas.width, graywashCanvas.height);
249233
}
250234

235+
const measurementDiv = measurementRef.current;
236+
if (!measurementDiv) {
237+
return;
238+
}
239+
const scale = measurementDiv.clientWidth / imageBuffer.width;
251240
drawCommands.forEach(rect => {
252-
drawRect(rect, ctx);
241+
drawRect(rect, ctx, scale);
253242
});
254243

255244
if (currentRect) {
@@ -315,7 +304,19 @@ export function ScreenshotEditorFactoryv2({
315304
const endY = Math.max(0, Math.min(e.clientY - boundingRect.top, graywashCanvas.height / DPI));
316305
// prevent drawing rect when clicking on the canvas (ie clicking delete)
317306
if (startX != endX && startY != endY) {
318-
const rect = constructRect({ action, startX, startY, endX, endY });
307+
// scale to image buffer
308+
const measurementDiv = measurementRef.current;
309+
if (!measurementDiv) {
310+
return;
311+
}
312+
const scale = imageBuffer.width / measurementDiv.clientWidth;
313+
const rect = constructRect({
314+
action,
315+
startX: startX * scale,
316+
startY: startY * scale,
317+
endX: endX * scale,
318+
endY: endY * scale,
319+
});
319320
setDrawCommands(prev => [...prev, rect]);
320321
}
321322

0 commit comments

Comments
 (0)