Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
ec1bd32
fix(web): editing a queued message keeps its attachment chips resolved
smirea-ai Nov 22, 2026
448597f
fix(web): reconcile deleted queued file chips and preserve snapshot s…
smirea-ai Nov 22, 2026
30401dd
fix(web): restore removed queued attachments on undo and same-edit paste
smirea-ai Nov 22, 2026
b712a45
fix(web): remove restored queued images on redo and unit-test paste m…
smirea-ai Nov 22, 2026
eb93331
fix(web): gate queued image redo removal on editor history transactions
smirea-ai Nov 22, 2026
e34e312
fix(web): retain restored queued image history tracking across typing
smirea-ai Nov 22, 2026
27d82b0
fix(web): track queued image paste and row-removal depths in editor h…
smirea-ai Nov 22, 2026
b29eb9c
fix(web): model queued image attachment state per editor history depth
smirea-ai Nov 22, 2026
416c576
fix(web): track queued image history with monotonic ProseMirror revis…
smirea-ai Nov 22, 2026
5f8773d
fix(web): preserve history direction across stale skill chip replacement
smirea-ai Nov 22, 2026
145f1b3
fix(web): scope queued edit restoration and stale skill history direc…
smirea-ai Nov 22, 2026
252f4d8
fix(web): isolate question answer editor undo history from queued edits
smirea-ai Nov 22, 2026
056fecf
Merge origin/main into fix/edit-message-pasted-image
juliusmarminge Nov 22, 2026
f8db0f1
refactor(web): drop the editor history mirror from queued attachment …
juliusmarminge Nov 22, 2026
bd0f199
fix(web): redo of a queued image removal takes the image off the shel…
juliusmarminge Nov 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3946,9 +3946,15 @@ export default function ChatView(props: ChatViewProps) {
onExpandImage={onExpandTimelineImageStable}
onFileOpen={openFileAttachmentStable}
editingQueuedAttachments={queuedRunEdit.editingAttachments}
removedEditingQueuedAttachments={
queuedRunEdit.removedEditingAttachments
}
onRemoveEditingQueuedAttachment={
queuedRunEdit.removeEditingAttachment
}
onRestoreEditingQueuedAttachment={
queuedRunEdit.restoreEditingAttachment
}
/>
)}
</div>
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/components/ComposerPromptEditorTiptap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ export interface ComposerPromptEditorProps {
contextIds: string[],
/** False when only the caret or selection moved. */
textChanged: boolean,
/** True when the change came from undo or redo. */
fromHistory?: boolean,
) => void;
onVisibleSelectionChange?: () => void;
onCommandKeyDown?: (key: string, event: KeyboardEvent, isTaskItem?: boolean) => boolean;
Expand Down Expand Up @@ -1127,6 +1129,7 @@ function ComposerPromptEditorTiptapInner(
suppressTrigger,
contextIds,
previousSnapshot.value !== nextValue,
isHistoryTransaction(transaction),
);
};

Expand Down
116 changes: 89 additions & 27 deletions apps/web/src/components/chat/ChatComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import type {
KeybindingCommand,
AssistantCitation,
ComposerContextId,
ResponseContextRecord,
ChatAttachment as ContractChatAttachment,
ChatFileAttachment,
Expand Down Expand Up @@ -120,6 +121,7 @@ import { useComposerTriggerState } from "./useComposerTriggerState";
import { useComposerMenuItems } from "./useComposerMenuItems";
import { useComposerMultilinePrompt } from "./useComposerMultilinePrompt";
import {
type QueuedAttachmentContextBinding,
reconcileAttachmentContextReferences,
useRetainedContextPayloads,
} from "./composerContextUndo";
Expand Down Expand Up @@ -287,6 +289,7 @@ import { useComposerImageGroups } from "./useComposerImageGroups";
import { useComposerStash } from "./useComposerStash";
import { useComposerContextImport } from "./useComposerContextImport";
import { useComposerAttachmentIntake } from "./useComposerAttachmentIntake";
import { isQueuedFileAttachment, isQueuedImageAttachment } from "./queuedMessageEdit";
import {
cancelHeldComposerSend,
countPreparingComposerImages,
Expand Down Expand Up @@ -457,8 +460,11 @@ export interface ChatComposerProps {
editingQueuedAttachments: ReadonlyArray<{
readonly attachment: ContractChatAttachment;
readonly url: string | null;
readonly contextIds?: ReadonlyArray<ComposerContextId> | undefined;
}> | null;
removedEditingQueuedAttachments?: ReadonlyArray<QueuedAttachmentContextBinding> | undefined;
onRemoveEditingQueuedAttachment: (attachmentId: string) => void;
onRestoreEditingQueuedAttachment?: ((attachment: ContractChatAttachment) => void) | undefined;

onCompactContext: () => void;
onSend: (
Expand Down Expand Up @@ -599,7 +605,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
onExpandImage,
onFileOpen,
editingQueuedAttachments,
removedEditingQueuedAttachments,
onRemoveEditingQueuedAttachment,
onRestoreEditingQueuedAttachment,
} = props;
const {
activePendingProgress: incomingPendingProgress,
Expand Down Expand Up @@ -657,6 +665,12 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
activePendingProgress.activeQuestion.id,
)
: null;
const queuedEditOwnsComposer =
questionAttachmentTarget === null && pendingUserInputs.length === 0;
const activeEditingQueuedAttachments = queuedEditOwnsComposer ? editingQueuedAttachments : null;
const activeRemovedEditingQueuedAttachments = queuedEditOwnsComposer
? removedEditingQueuedAttachments
: undefined;
const attachmentDraftTarget = questionAttachmentTarget ?? composerDraftTarget;
const attachmentDraft = useComposerThreadDraft(attachmentDraftTarget);
const questionTakesSnapShots =
Expand Down Expand Up @@ -757,33 +771,55 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
cwd: gitCwd ?? undefined,
projectId: activeProjectId ?? undefined,
expandImage: (imageId: string) => {
const preview = buildExpandedImagePreview(
composerImages,
imageId,
copyComposerSnapshotStable,
);
const preview =
buildExpandedImagePreview(composerImages, imageId, copyComposerSnapshotStable) ??
buildExpandedImagePreview(
(activeEditingQueuedAttachments ?? []).flatMap(({ attachment, url }) =>
isQueuedImageAttachment(attachment) && url ? [{ ...attachment, previewUrl: url }] : [],
),
imageId,
);
if (preview) onExpandImage(preview);
},
openFile: setPreviewFileId,
openFile: (fileId: string) => {
if (composerFiles.some((file) => file.id === fileId)) {
setPreviewFileId(fileId);
return;
}
const queuedFile = activeEditingQueuedAttachments?.find(
({ attachment }) => isQueuedFileAttachment(attachment) && attachment.id === fileId,
)?.attachment;
if (queuedFile && isQueuedFileAttachment(queuedFile)) onFileOpen(queuedFile);
},
openMention: (path: string) => useRightPanelStore.getState().openFile(routeThreadRef, path),
expandVideo: (fileId: string) => {
const file = composerFiles.find((candidate) => candidate.id === fileId);
if (!file || !isVideoAttachment(file)) return;
const localPreview = buildExpandedImagePreview([file], file.id);
if (localPreview) {
onExpandImage(localPreview);
if (file && isVideoAttachment(file)) {
const localPreview = buildExpandedImagePreview([file], file.id);
if (localPreview) {
onExpandImage(localPreview);
return;
}
if (file.uploadedAttachmentId === undefined || file.uploadEnvironmentId !== environmentId) {
return;
}
const persistedPreview = buildAttachmentVideoPreview(environmentId, {
type: "file",
id: file.uploadedAttachmentId,
name: file.name,
mimeType: file.mimeType,
sizeBytes: file.sizeBytes,
});
if (persistedPreview) onExpandImage(persistedPreview);
return;
}
if (file.uploadedAttachmentId === undefined || file.uploadEnvironmentId !== environmentId) {
const queuedFile = activeEditingQueuedAttachments?.find(
({ attachment }) => isQueuedFileAttachment(attachment) && attachment.id === fileId,
)?.attachment;
if (!queuedFile || !isQueuedFileAttachment(queuedFile) || !isVideoAttachment(queuedFile)) {
return;
}
const persistedPreview = buildAttachmentVideoPreview(environmentId, {
type: "file",
id: file.uploadedAttachmentId,
name: file.name,
mimeType: file.mimeType,
sizeBytes: file.sizeBytes,
});
const persistedPreview = buildAttachmentVideoPreview(environmentId, queuedFile);
if (persistedPreview) onExpandImage(persistedPreview);
},
openPullRequest: (event: React.MouseEvent<HTMLElement>, url: string) => {
Expand All @@ -798,6 +834,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
environmentContexts: composerEnvironmentContexts,
images: composerImages,
files: composerFiles,
existingAttachments: activeEditingQueuedAttachments ?? undefined,
environmentId,
uploadsByImageId,
});
const needsReattachFileCount = composerFiles.filter(composerFileNeedsReattach).length;
Expand Down Expand Up @@ -1393,12 +1431,20 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
: null);
if (!record) return [];
if (attachment.file) copiedFiles.set(record.attachmentId, attachment.file);
return [
record.kind === "image" && attachment.type === "image" && attachment.source
? { ...record, source: attachment.source }
: record,
];
return [record];
}),
...(activeEditingQueuedAttachments ?? []).flatMap(({ attachment, contextIds }) => {
if (!isQueuedImageAttachment(attachment) && !isQueuedFileAttachment(attachment)) return [];
return (contextIds ?? [])
.filter((contextId) => wanted.has(contextId))
.map((contextId) =>
attachmentContextRecord({
attachment,
attachmentId: attachment.id,
contextId,
}),
);
}),
];
if (records.length === 0) return null;
const fragment = encodeComposerContextFragment({
Expand Down Expand Up @@ -1447,6 +1493,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
promptRef,
pendingThreadImportsRef,
addComposerFilesToDraft,
removedQueuedAttachments: activeRemovedEditingQueuedAttachments,
onRestoreQueuedAttachment: onRestoreEditingQueuedAttachment,
});

// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- keeps the shared prompt ref in step with the committed draft prompt for imperative handlers
Expand Down Expand Up @@ -1652,6 +1700,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
cursorAdjacentToMention: boolean,
contextIds: string[],
textChanged: boolean,
fromHistory = false,
) => {
refreshWorkspaceSnapshotOnTyping();
const trigger = cursorAdjacentToMention
Expand Down Expand Up @@ -1762,6 +1811,14 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
const attachmentChanges = reconcileAttachmentContextReferences({
referencedContextIds: referenced,
files: composerFiles,
queuedAttachments: (activeEditingQueuedAttachments ?? []).map(
({ attachment, contextIds }) => ({
attachment,
contextIds: contextIds ?? [],
}),
),
removedQueuedAttachments: activeRemovedEditingQueuedAttachments ?? [],
fromHistory,
images: composerImages,
previewAnnotations: composerPreviewAnnotations,
retained: retainedContextPayloads,
Expand All @@ -1781,6 +1838,12 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
if (attachmentChanges.filesToRestore.length > 0) {
addComposerDraftFiles(attachmentDraftTarget, attachmentChanges.filesToRestore);
}
for (const attachmentId of attachmentChanges.queuedAttachmentIdsToRemove) {
onRemoveEditingQueuedAttachment(attachmentId);
}
for (const attachment of attachmentChanges.queuedAttachmentsToRestore) {
onRestoreEditingQueuedAttachment?.(attachment);
}
setComposerCursor(nextCursor);
updateTrigger(trigger);
};
Expand Down Expand Up @@ -3814,11 +3877,10 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
)}

{!isComposerCollapsedMobile &&
pendingUserInputs.length === 0 &&
editingQueuedAttachments !== null &&
editingQueuedAttachments.length > 0 && (
activeEditingQueuedAttachments !== null &&
activeEditingQueuedAttachments.length > 0 && (
<ComposerQueuedAttachmentRow
attachments={editingQueuedAttachments}
attachments={activeEditingQueuedAttachments}
onRemove={onRemoveEditingQueuedAttachment}
/>
)}
Expand Down
69 changes: 67 additions & 2 deletions apps/web/src/components/chat/composerContextUndo.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { PreviewAnnotationPayload } from "@t3tools/contracts";
import {
ChatAttachmentId,
ComposerContextId,
type PreviewAnnotationPayload,
} from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";

import type { ComposerImageAttachment } from "../../composerDraftStore";
Expand Down Expand Up @@ -37,7 +41,7 @@ const annotation = {
} satisfies PreviewAnnotationPayload;

function retention(): RetainedAttachmentContextPayloads {
return { files: new Map(), previewAnnotations: new Map() };
return { files: new Map(), previewAnnotations: new Map(), restoredQueuedImageIds: new Set() };
}

describe("reconcileAttachmentContextReferences", () => {
Expand Down Expand Up @@ -88,4 +92,65 @@ describe("reconcileAttachmentContextReferences", () => {
}),
]);
});

it("drops a queued file with its chip, keeps a queued image, and lets undo and redo restore and remove either", () => {
const file = {
attachment: {
type: "file" as const,
id: ChatAttachmentId.make("server-file"),
name: "notes.txt",
mimeType: "text/plain",
sizeBytes: 12,
},
contextIds: [ComposerContextId.make("file_local")],
};
const queuedImage = {
attachment: {
type: "image" as const,
id: ChatAttachmentId.make("server-image"),
name: "image.png",
mimeType: "image/png",
sizeBytes: 67,
},
contextIds: [ComposerContextId.make("image_local")],
};
const base = { files: [], images: [], previewAnnotations: [], retained: retention() };

const deleted = reconcileAttachmentContextReferences({
...base,
referencedContextIds: new Set(),
queuedAttachments: [file, queuedImage],
});
expect(deleted.queuedAttachmentIdsToRemove).toEqual([file.attachment.id]);

const undone = reconcileAttachmentContextReferences({
...base,
referencedContextIds: new Set(["file_local", "image_local"]),
removedQueuedAttachments: [file, queuedImage],
});
expect(undone.queuedAttachmentsToRestore).toEqual([file.attachment, queuedImage.attachment]);

const redone = reconcileAttachmentContextReferences({
...base,
referencedContextIds: new Set(),
queuedAttachments: [file, queuedImage],
fromHistory: true,
});
expect(redone.queuedAttachmentIdsToRemove).toEqual([
file.attachment.id,
queuedImage.attachment.id,
]);

reconcileAttachmentContextReferences({
...base,
referencedContextIds: new Set(["image_local"]),
removedQueuedAttachments: [queuedImage],
});
const backspaced = reconcileAttachmentContextReferences({
...base,
referencedContextIds: new Set(),
queuedAttachments: [queuedImage],
});
expect(backspaced.queuedAttachmentIdsToRemove).toEqual([]);
});
});
Loading
Loading