Skip to content

CanvasAnvil is an open source AI diagram maker and flowchart generator - an infinite-canvas diagram editor and self-hosted drawio alternative that writes editable .drawio files. Text to diagram, then fix nodes, layout and labels in place. Also AI presentations, interior design CAD/BOM, posters and infographics.

feat(ppt): let the user pick edit or redraw instead of the router

codingFeng10189866ec0cc8f
diff --git a/client/shared/chat/chat-input.tsx b/client/shared/chat/chat-input.tsx
index 65235a2..51d8412 100644
--- a/client/shared/chat/chat-input.tsx
+++ b/client/shared/chat/chat-input.tsx
@@ -23,6 +23,8 @@ interface ChatInputProps {
files?: File[]; // Controlled files
placeholder?: string;
topChips?: React.ReactNode;
+ /** Workspace-specific controls, shown beside the toolbar's own buttons. */
+ toolbarExtras?: React.ReactNode;
bottomChips?: React.ReactNode;
focusKey?: string | number;
richSegments?: RichInputSegment[];
@@ -53,6 +55,7 @@ export function ChatInput({
files: controlledFiles,
placeholder,
topChips,
+ toolbarExtras,
bottomChips,
focusKey,
richSegments,
@@ -566,6 +569,7 @@ export function ChatInput({
<div className="flex items-center justify-between px-3 py-2 border-t border-border/50">
<div className="flex items-center gap-1">
+ {toolbarExtras}
{onClearChat && (
<ButtonWithTooltip
tooltipContent={t(uiLang, "chat.clearChatTitle")}
diff --git a/client/workspaces/ppt/canvas/PptCanvas.tsx b/client/workspaces/ppt/canvas/PptCanvas.tsx
index e5dbce3..505c686 100644
--- a/client/workspaces/ppt/canvas/PptCanvas.tsx
+++ b/client/workspaces/ppt/canvas/PptCanvas.tsx
@@ -668,6 +668,21 @@ export function PptCanvas({
url,
label: uploadedImageLabel(i + 1, uiLang as MaterialLang),
}));
+ /**
+ * Which image call a slide takes.
+ *
+ * The router picks by itself unless the user pinned a mode in the chat
+ * panel. Editing needs something to edit, so a pinned "edit" still redraws
+ * a slide that has no image yet -- otherwise the message would silently do
+ * nothing.
+ */
+ const pinnedImageMode: "auto" | "edit" | "regenerate" =
+ parsed?.imageMode === "edit" || parsed?.imageMode === "regenerate" ? parsed.imageMode : "auto";
+ const shouldRedraw = (routerWantsRedraw: boolean, currentUrl: string) => {
+ if (pinnedImageMode === "regenerate") return true;
+ if (pinnedImageMode === "edit") return !String(currentUrl || "").trim();
+ return routerWantsRedraw;
+ };
const uploadedImageInstruction = uploadedImageRefs.length > 0
? tr(
`用户在对话中上传了这些参考图:${uploadedImageRefs.map((x) => x.label).join("、")}。请把它们放进画面并保持原貌,不要重画、改色或替换。`,
@@ -846,7 +861,7 @@ export function PptCanvas({
continue;
}
- if (editType === "text_only" || editType === "text_relayout") {
+ if ((editType === "text_only" || editType === "text_relayout") && pinnedImageMode !== "edit") {
routedEditTasks.push(async () => {
const rendered = await pptService.generatePageImage(
page,
@@ -870,7 +885,10 @@ export function PptCanvas({
const versions = imageVersions[id] || [];
const currentVersion = currentImageVersionId[id];
const currentUrl = currentVersion ? versions.find((v) => v.id === currentVersion)?.url : generatedImages[id];
- const shouldRegenerate = isNewSlide || !currentUrl || changedByPatch;
+ const shouldRegenerate = shouldRedraw(
+ isNewSlide || !currentUrl || changedByPatch,
+ currentUrl || "",
+ );
if (shouldRegenerate) {
const rendered = await pptService.generatePageImage(
page,
@@ -996,7 +1014,16 @@ export function PptCanvas({
);
const isNewSlide = !before;
- if (kind === "content" || kind === "both" || (!kind && (changedByPatch || isNewSlide))) {
+ // The same pin applies on the fallback path, which decides by `kind`.
+ const fallbackWantsRedraw = kind === "content" || kind === "both" || (!kind && (changedByPatch || isNewSlide));
+ const fallbackCurrentUrl = (() => {
+ const versions = imageVersions[id] || [];
+ const currentVersion = currentImageVersionId[id];
+ return String(
+ (currentVersion ? versions.find((v) => v.id === currentVersion)?.url : generatedImages[id]) || "",
+ );
+ })();
+ if (shouldRedraw(fallbackWantsRedraw, fallbackCurrentUrl)) {
editTasks.push(async () => {
const page: PptPage = {
id,
@@ -1037,7 +1064,7 @@ export function PptCanvas({
await pushImageVersionAndProcess(slide, rendered, "generated", kind === "both" ? instruction : undefined);
}
});
- if (kind === "content" || kind === "both") continue;
+ if (pinnedImageMode === "regenerate" || kind === "content" || kind === "both") continue;
}
if (!instruction.trim()) continue;
diff --git a/client/workspaces/ppt/chat/ChatPanel.tsx b/client/workspaces/ppt/chat/ChatPanel.tsx
index 0dfc87f..7c2241e 100644
--- a/client/workspaces/ppt/chat/ChatPanel.tsx
+++ b/client/workspaces/ppt/chat/ChatPanel.tsx
@@ -1,5 +1,5 @@
import { useState, useRef, useEffect, useCallback } from 'react';
-import { PanelRightClose, PanelRightOpen } from 'lucide-react';
+import { PanelRightClose, PanelRightOpen, Pencil, RefreshCw } from 'lucide-react';
import { cn } from '@/shared/lib/utils';
import { streamChatMessage, generatePptProxyChatMessage, ChatMessage, getAIConfig } from '@/ai/client';
@@ -110,6 +110,17 @@ export function ChatPanel({
const pptInsertBusyRef = useRef(false);
const [pptClearTick, setPptClearTick] = useState(0);
const lastUploadedImagesRef = useRef<string[]>([]);
+ /**
+ * Which image call the next message should take.
+ *
+ * "auto" leaves it to the router, which is right most of the time and wrong
+ * in the two ways a user notices: a wording tweak that redraws the whole
+ * slide and loses a picture they liked, and a request to change the picture
+ * that edits the old one instead of drawing a new one.
+ */
+ const [imageMode, setImageMode] = useState<"auto" | "edit" | "regenerate">("auto");
+ const imageModeRef = useRef(imageMode);
+ imageModeRef.current = imageMode;
const getPptLabel = (slideId: string, title: string) => {
const m = String(slideId || "").match(/(\d+)/);
@@ -223,12 +234,16 @@ const getPptTag = (slideId: string, title: string, kind: "outline" | "slide_imag
// any {{image:...}} references the model emitted.
try {
const parsed = JSON.parse(jsonText);
+ let changed = false;
if (lastUploadedImagesRef.current.length > 0) {
parsed.uploadedImages = lastUploadedImagesRef.current;
- await runCodeAction(JSON.stringify(parsed), 'ppt');
- } else {
- await runCodeAction(jsonText, 'ppt');
+ changed = true;
+ }
+ if (imageModeRef.current !== 'auto') {
+ parsed.imageMode = imageModeRef.current;
+ changed = true;
}
+ await runCodeAction(changed ? JSON.stringify(parsed) : jsonText, 'ppt');
} catch {
await runCodeAction(jsonText, 'ppt');
}
@@ -682,6 +697,44 @@ const getPptTag = (slideId: string, title: string, kind: "outline" | "slide_imag
historyDisabled={history.length === 0}
onFilesChange={setFiles}
files={files}
+ toolbarExtras={
+ <>
+ <ButtonWithTooltip
+ tooltipContent={trText(
+ "改图:在当前这版画面上修改,保留原有构图",
+ "Edit: change the current image, keeping its composition",
+ )}
+ variant="ghost"
+ size="sm"
+ onClick={() => setImageMode((m) => (m === "edit" ? "auto" : "edit"))}
+ className={cn(
+ "h-8 w-8 p-0",
+ imageMode === "edit"
+ ? "bg-primary/10 text-primary hover:bg-primary/15"
+ : "text-muted-foreground hover:text-foreground",
+ )}
+ >
+ <Pencil className="h-4 w-4" />
+ </ButtonWithTooltip>
+ <ButtonWithTooltip
+ tooltipContent={trText(
+ "重画:整页重新生成,构图可以大改",
+ "Redraw: generate the slide again from scratch",
+ )}
+ variant="ghost"
+ size="sm"
+ onClick={() => setImageMode((m) => (m === "regenerate" ? "auto" : "regenerate"))}
+ className={cn(
+ "h-8 w-8 p-0",
+ imageMode === "regenerate"
+ ? "bg-primary/10 text-primary hover:bg-primary/15"
+ : "text-muted-foreground hover:text-foreground",
+ )}
+ >
+ <RefreshCw className="h-4 w-4" />
+ </ButtonWithTooltip>
+ </>
+ }
uploadMode="imagesOnly"
placeholder={inputPlaceholder}
focusKey={pptInputFocusTick}