Spaces:
Running
Running
Commit ·
90bbe5b
1
Parent(s): ee9aaf3
fix: integrate system clipboard paste into existing handleKeyDown to avoid hotkey conflicts
Browse files- src/pages/CanvasPage.jsx +3 -87
src/pages/CanvasPage.jsx
CHANGED
|
@@ -1310,93 +1310,7 @@ const CanvasInner = () => {
|
|
| 1310 |
updateProjectMetadata
|
| 1311 |
} = useCanvasLogic(id, user);
|
| 1312 |
|
| 1313 |
-
|
| 1314 |
-
useEffect(() => {
|
| 1315 |
-
const handlePasteEvent = (event) => {
|
| 1316 |
-
if (permission === 'Read') return;
|
| 1317 |
-
|
| 1318 |
-
// Don't paste if user is typing in an input/textarea
|
| 1319 |
-
const targetTag = event.target.tagName;
|
| 1320 |
-
const isInput = targetTag === 'INPUT' || targetTag === 'TEXTAREA' || event.target.isContentEditable;
|
| 1321 |
-
if (isInput) return;
|
| 1322 |
-
|
| 1323 |
-
const clipboardData = event.clipboardData || window.clipboardData;
|
| 1324 |
-
if (!clipboardData) return;
|
| 1325 |
-
|
| 1326 |
-
const items = clipboardData.items;
|
| 1327 |
-
let imageFound = false;
|
| 1328 |
-
|
| 1329 |
-
// Log for debugging
|
| 1330 |
-
console.log('[Paste] Event triggered', { items: items.length });
|
| 1331 |
-
|
| 1332 |
-
// First check for images
|
| 1333 |
-
for (const item of items) {
|
| 1334 |
-
if (item.type.indexOf('image') !== -1) {
|
| 1335 |
-
imageFound = true;
|
| 1336 |
-
event.preventDefault(); // Stop standard paste early
|
| 1337 |
-
|
| 1338 |
-
const blob = item.getAsFile();
|
| 1339 |
-
const reader = new FileReader();
|
| 1340 |
-
reader.onload = (e) => {
|
| 1341 |
-
const img = new Image();
|
| 1342 |
-
img.onload = () => {
|
| 1343 |
-
const canvas = document.createElement('canvas');
|
| 1344 |
-
let width = img.width;
|
| 1345 |
-
let height = img.height;
|
| 1346 |
-
const MAX_SIZE = 1200;
|
| 1347 |
-
|
| 1348 |
-
if (width > height && width > MAX_SIZE) {
|
| 1349 |
-
height *= MAX_SIZE / width;
|
| 1350 |
-
width = MAX_SIZE;
|
| 1351 |
-
} else if (height > MAX_SIZE) {
|
| 1352 |
-
width *= MAX_SIZE / height;
|
| 1353 |
-
height = MAX_SIZE;
|
| 1354 |
-
}
|
| 1355 |
-
|
| 1356 |
-
canvas.width = width;
|
| 1357 |
-
canvas.height = height;
|
| 1358 |
-
const ctx = canvas.getContext('2d');
|
| 1359 |
-
ctx.drawImage(img, 0, 0, width, height);
|
| 1360 |
-
const compressedBase64 = canvas.toDataURL('image/jpeg', 0.8);
|
| 1361 |
-
|
| 1362 |
-
const x = window.__lastMouseX || window.innerWidth / 2;
|
| 1363 |
-
const y = window.__lastMouseY || window.innerHeight / 2;
|
| 1364 |
-
console.log('[Paste] Adding image node at', { x, y });
|
| 1365 |
-
addNewNodeAt(x, y, 'image', { url: compressedBase64 });
|
| 1366 |
-
};
|
| 1367 |
-
img.src = e.target.result;
|
| 1368 |
-
};
|
| 1369 |
-
reader.readAsDataURL(blob);
|
| 1370 |
-
break;
|
| 1371 |
-
}
|
| 1372 |
-
}
|
| 1373 |
-
|
| 1374 |
-
// If no image, try to paste text
|
| 1375 |
-
if (!imageFound) {
|
| 1376 |
-
const text = clipboardData.getData('text/plain');
|
| 1377 |
-
if (text && text.trim()) {
|
| 1378 |
-
event.preventDefault();
|
| 1379 |
-
const x = window.__lastMouseX || window.innerWidth / 2;
|
| 1380 |
-
const y = window.__lastMouseY || window.innerHeight / 2;
|
| 1381 |
-
console.log('[Paste] Adding text node at', { x, y });
|
| 1382 |
-
addNewNodeAt(x, y, 'text', { label: text });
|
| 1383 |
-
}
|
| 1384 |
-
}
|
| 1385 |
-
};
|
| 1386 |
-
|
| 1387 |
-
const handleMouseMoveGlobal = (e) => {
|
| 1388 |
-
window.__lastMouseX = e.clientX;
|
| 1389 |
-
window.__lastMouseY = e.clientY;
|
| 1390 |
-
};
|
| 1391 |
-
|
| 1392 |
-
window.addEventListener('paste', handlePasteEvent);
|
| 1393 |
-
window.addEventListener('mousemove', handleMouseMoveGlobal);
|
| 1394 |
-
|
| 1395 |
-
return () => {
|
| 1396 |
-
window.removeEventListener('paste', handlePasteEvent);
|
| 1397 |
-
window.removeEventListener('mousemove', handleMouseMoveGlobal);
|
| 1398 |
-
};
|
| 1399 |
-
}, [permission, addNewNodeAt]); const lastCursorSendRef = useRef(0);
|
| 1400 |
const broadcastRef = useRef(broadcastMessage);
|
| 1401 |
|
| 1402 |
useEffect(() => {
|
|
@@ -1408,6 +1322,8 @@ const CanvasInner = () => {
|
|
| 1408 |
|
| 1409 |
const handleWindowMouseMove = (event) => {
|
| 1410 |
mousePosRef.current = { x: event.clientX, y: event.clientY };
|
|
|
|
|
|
|
| 1411 |
if (!reactFlowWrapper.current) return;
|
| 1412 |
|
| 1413 |
const rect = reactFlowWrapper.current.getBoundingClientRect();
|
|
|
|
| 1310 |
updateProjectMetadata
|
| 1311 |
} = useCanvasLogic(id, user);
|
| 1312 |
|
| 1313 |
+
const lastCursorSendRef = useRef(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1314 |
const broadcastRef = useRef(broadcastMessage);
|
| 1315 |
|
| 1316 |
useEffect(() => {
|
|
|
|
| 1322 |
|
| 1323 |
const handleWindowMouseMove = (event) => {
|
| 1324 |
mousePosRef.current = { x: event.clientX, y: event.clientY };
|
| 1325 |
+
window.__lastMouseX = event.clientX;
|
| 1326 |
+
window.__lastMouseY = event.clientY;
|
| 1327 |
if (!reactFlowWrapper.current) return;
|
| 1328 |
|
| 1329 |
const rect = reactFlowWrapper.current.getBoundingClientRect();
|