From 88afa0551c6741ba1018671eb8b818701a81dbae Mon Sep 17 00:00:00 2001 From: 134 Date: Fri, 12 Jun 2026 14:49:51 +0800 Subject: [PATCH] improve generation placeholder placement --- components/canvas/CanvasChatPanel.tsx | 51 ++++++++++++++++------- components/generation-dot-placeholder.tsx | 10 ++--- components/image-generation-loading.tsx | 6 ++- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/components/canvas/CanvasChatPanel.tsx b/components/canvas/CanvasChatPanel.tsx index a1f52100f..56024d202 100644 --- a/components/canvas/CanvasChatPanel.tsx +++ b/components/canvas/CanvasChatPanel.tsx @@ -1521,6 +1521,7 @@ export function CanvasChatPanel({ [nodes, selectedNodeIds] ); const selectedImageNodesRef = useRef([]); + const generationAnchorNodesRef = useRef([]); useEffect(() => { selectedImageNodesRef.current = selectedImageNodes; @@ -3489,7 +3490,10 @@ export function CanvasChatPanel({ const currentNodes = useCanvasStore.getState().nodes; const anchorNode = findCanvasImageAnchorNode(currentNodes, { - selectedNodes: selectedImageNodesRef.current, + selectedNodes: + generationAnchorNodesRef.current.length > 0 + ? generationAnchorNodesRef.current + : selectedImageNodesRef.current, sourceImageUrls, }); const size = { width: dimensions.width, height: dimensions.height }; @@ -4687,7 +4691,10 @@ export function CanvasChatPanel({ const currentNodes = useCanvasStore.getState().nodes; const anchorNode = findCanvasImageAnchorNode(currentNodes, { - selectedNodes: selectedImageNodesRef.current, + selectedNodes: + generationAnchorNodesRef.current.length > 0 + ? generationAnchorNodesRef.current + : selectedImageNodesRef.current, sourceImageUrls: nearestUserImageUrls, }); const size = { width: dimensions.width, height: dimensions.height }; @@ -4918,7 +4925,10 @@ export function CanvasChatPanel({ isValidChatHttpUrl(String((node.data as any)?.src || "").trim()), ); - if (imageNodes.length === 0) return undefined; + if (imageNodes.length === 0) { + generationAnchorNodesRef.current = []; + return undefined; + } const effectiveComposerMode = activeComposerModeRef.current || activeComposerMode; const shouldIsolateDirectModeContext = effectiveComposerMode !== "agent"; @@ -4927,11 +4937,13 @@ export function CanvasChatPanel({ ); if (shouldIsolateDirectModeContext && selectedImageNodesForContext.length === 0) { + generationAnchorNodesRef.current = []; return undefined; } const MAX_CONTEXT_IMAGES = 12; const selectedContextNodes = selectedImageNodesForContext.slice(0, 20); + generationAnchorNodesRef.current = selectedContextNodes.slice(0, 4); const selectedIds = new Set(selectedContextNodes.map((node) => node.id)); const prioritizedNodes = shouldIsolateDirectModeContext @@ -8101,6 +8113,13 @@ export function CanvasChatPanel({ ? "生成失败" : "正在创建图片"; const status = phase === "failed" ? "failed" : "generating"; + const currentNodes = useCanvasStore.getState().nodes; + const anchorNode = findCanvasImageAnchorNode(currentNodes, { + selectedNodes: + generationAnchorNodesRef.current.length > 0 + ? generationAnchorNodesRef.current + : selectedImageNodesRef.current, + }); const imageParamSnapshot = imageParamsRef.current || imageParams; const aspectRatio = imageParamSnapshot.aspectRatio && imageParamSnapshot.aspectRatio !== "auto" @@ -8110,7 +8129,7 @@ export function CanvasChatPanel({ const ratioWidth = Number.isFinite(ratioWidthRaw) && ratioWidthRaw > 0 ? ratioWidthRaw : 1; const ratioHeight = Number.isFinite(ratioHeightRaw) && ratioHeightRaw > 0 ? ratioHeightRaw : 1; const baseSide = 340; - const placeholderSize = + const ratioPlaceholderSize = ratioWidth >= ratioHeight ? { width: baseSide, @@ -8120,6 +8139,18 @@ export function CanvasChatPanel({ width: Math.max(190, Math.round((baseSide * ratioWidth) / ratioHeight)), height: baseSide, }; + const placeholderSize = anchorNode + ? { + width: Math.max(180, Math.round(Number(anchorNode.size?.width || ratioPlaceholderSize.width))), + height: Math.max(180, Math.round(Number(anchorNode.size?.height || ratioPlaceholderSize.height))), + } + : ratioPlaceholderSize; + const position = getAnchoredGenerationPosition({ + anchorNode, + fallbackNodeCount: currentNodes.length, + size: placeholderSize, + viewport: useCanvasStore.getState().viewport, + }); const metadata = { canvasGenerationPlaceholder: true, chatId: activeChatId, @@ -8149,23 +8180,15 @@ export function CanvasChatPanel({ ...metadata, }, }, + position, size: placeholderSize, }); + focusCanvasOnNode({ position, size: placeholderSize }); return; } delete canvasGenerationPlaceholderByChatIdRef.current[activeChatId]; } - const currentNodes = useCanvasStore.getState().nodes; - const anchorNode = findCanvasImageAnchorNode(currentNodes, { - selectedNodes: selectedImageNodesRef.current, - }); - const position = getAnchoredGenerationPosition({ - anchorNode, - fallbackNodeCount: currentNodes.length, - size: placeholderSize, - viewport: useCanvasStore.getState().viewport, - }); const nodeId = addNode({ type: "image", position, diff --git a/components/generation-dot-placeholder.tsx b/components/generation-dot-placeholder.tsx index 049fa067f..f3778a829 100644 --- a/components/generation-dot-placeholder.tsx +++ b/components/generation-dot-placeholder.tsx @@ -131,7 +131,7 @@ function ScatterParticleLayer({ const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera(34, 1, 0.1, 1000); - camera.position.set(0, 0, compact ? 46 : 42); + camera.position.set(0, 0, compact ? 48 : 44); camera.lookAt(0, 0, 0); const renderer = new THREE.WebGLRenderer({ @@ -184,8 +184,8 @@ function ScatterParticleLayer({ const points = new THREE.Points(geometry, material); points.rotation.x = -0.06; - const baseX = compact ? -5.2 : -5.8; - const baseY = compact ? 0.15 : -0.05; + const baseX = 0; + const baseY = 0; points.position.set(baseX, baseY, 0); scene.add(points); @@ -209,8 +209,8 @@ function ScatterParticleLayer({ points.rotation.y += 0.0048; points.rotation.z += 0.0015; points.rotation.x = -0.08 + Math.sin(time * 0.17) * 0.18; - points.position.x = baseX + Math.sin(time * 0.16) * 0.18; - points.position.y = baseY + Math.sin(time * 0.22) * 0.16; + points.position.x = baseX + Math.sin(time * 0.16) * 0.04; + points.position.y = baseY + Math.sin(time * 0.22) * 0.04; material.uniforms.uTime.value = time; renderer.render(scene, camera); frameId = window.requestAnimationFrame(animate); diff --git a/components/image-generation-loading.tsx b/components/image-generation-loading.tsx index 980314932..469564688 100644 --- a/components/image-generation-loading.tsx +++ b/components/image-generation-loading.tsx @@ -109,7 +109,11 @@ export const ImageGenerationLoading = memo( 1} phase={phase} />