Spaces:
Running
Running
Commit ·
90bbe5b
1
Parent(s): ee9aaf3
fix: integrate system clipboard paste into existing handleKeyDown to avoid hotkey conflicts
Browse files1309 unmodified lines1310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114025 unmodified lines1408140914101411141214131309 unmodified linesupdateProjectMetadata} = useCanvasLogic(id, user);// Keyboard and Global Event HandlersuseEffect(() => {const handlePasteEvent = (event) => {if (permission === 'Read') return;// Don't paste if user is typing in an input/textareaconst targetTag = event.target.tagName;const isInput = targetTag === 'INPUT' || targetTag === 'TEXTAREA' || event.target.isContentEditable;if (isInput) return;const clipboardData = event.clipboardData || window.clipboardData;if (!clipboardData) return;const items = clipboardData.items;let imageFound = false;// Log for debuggingconsole.log('[Paste] Event triggered', { items: items.length });// First check for imagesfor (const item of items) {if (item.type.indexOf('image') !== -1) {imageFound = true;event.preventDefault(); // Stop standard paste earlyconst blob = item.getAsFile();const reader = new FileReader();reader.onload = (e) => {const img = new Image();img.onload = () => {const canvas = document.createElement('canvas');let width = img.width;let height = img.height;const MAX_SIZE = 1200;if (width > height && width > MAX_SIZE) {height *= MAX_SIZE / width;width = MAX_SIZE;} else if (height > MAX_SIZE) {width *= MAX_SIZE / height;height = MAX_SIZE;}canvas.width = width;canvas.height = height;const ctx = canvas.getContext('2d');ctx.drawImage(img, 0, 0, width, height);const compressedBase64 = canvas.toDataURL('image/jpeg', 0.8);const x = window.__lastMouseX || window.innerWidth / 2;const y = window.__lastMouseY || window.innerHeight / 2;console.log('[Paste] Adding image node at', { x, y });addNewNodeAt(x, y, 'image', { url: compressedBase64 });};img.src = e.target.result;};reader.readAsDataURL(blob);break;}}// If no image, try to paste textif (!imageFound) {const text = clipboardData.getData('text/plain');if (text && text.trim()) {event.preventDefault();const x = window.__lastMouseX || window.innerWidth / 2;const y = window.__lastMouseY || window.innerHeight / 2;console.log('[Paste] Adding text node at', { x, y });addNewNodeAt(x, y, 'text', { label: text });}}};const handleMouseMoveGlobal = (e) => {window.__lastMouseX = e.clientX;window.__lastMouseY = e.clientY;};window.addEventListener('paste', handlePasteEvent);window.addEventListener('mousemove', handleMouseMoveGlobal);return () => {window.removeEventListener('paste', handlePasteEvent);window.removeEventListener('mousemove', handleMouseMoveGlobal);};}, [permission, addNewNodeAt]); const lastCursorSendRef = useRef(0);const broadcastRef = useRef(broadcastMessage);useEffect(() => {5 unmodified linesconst handleWindowMouseMove = (event) => {mousePosRef.current = { x: event.clientX, y: event.clientY };if (!reactFlowWrapper.current) return;const rect = reactFlowWrapper.current.getBoundingClientRect();1309 unmodified lines13101311131213131314131513165 unmodified lines132213231324132513261327132813291309 unmodified linesupdateProjectMetadata} = useCanvasLogic(id, user);const lastCursorSendRef = useRef(0);const broadcastRef = useRef(broadcastMessage);useEffect(() => {5 unmodified linesconst handleWindowMouseMove = (event) => {mousePosRef.current = { x: event.clientX, y: event.clientY };window.__lastMouseX = event.clientX;window.__lastMouseY = event.clientY;if (!reactFlowWrapper.current) return;const rect = reactFlowWrapper.current.getBoundingClientRect();
src/pages/CanvasPage.jsx+3-87