Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit f16371e

Browse files
authored
feat(code): improve pasted text UX (#1234)
pasted text showing up as an attachment, then getting appended to the end of the prompt, is a little disorienting adds pasted text as an inline file chip [code-paste.mp4 <span class="graphite__hidden">(uploaded via Graphite)</span> <img class="graphite__hidden" src="https://app.graphite.com/user-attachments/thumbnails/d040576c-e3ac-438c-b6eb-c087db9fc8c6.mp4" />](https://app.graphite.com/user-attachments/video/d040576c-e3ac-438c-b6eb-c087db9fc8c6.mp4)
1 parent 05fc461 commit f16371e

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

apps/code/src/renderer/features/message-editor/tiptap/useTiptapEditor.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export function useTiptapEditor(options: UseTiptapEditorOptions) {
8888
const submitRef = useRef<() => void>(() => {});
8989
const draftRef = useRef<ReturnType<typeof useDraftSync> | null>(null);
9090

91+
const pasteCountRef = useRef(0);
9192
const historyActions = usePromptHistoryStore.getState();
9293
const [isEmptyState, setIsEmptyState] = useState(true);
9394
const [isReady, setIsReady] = useState(false);
@@ -320,10 +321,22 @@ export function useTiptapEditor(options: UseTiptapEditorOptions) {
320321
text: pastedText,
321322
});
322323

323-
setAttachments((prev) => {
324-
if (prev.some((a) => a.id === result.path)) return prev;
325-
return [...prev, { id: result.path, label: result.name }];
324+
pasteCountRef.current += 1;
325+
const lineCount = pastedText.split("\n").length;
326+
const label = `Pasted text #${pasteCountRef.current} (${lineCount} lines)`;
327+
const chipNode = view.state.schema.nodes.mentionChip.create({
328+
type: "file",
329+
id: result.path,
330+
label,
326331
});
332+
const space = view.state.schema.text(" ");
333+
const { tr } = view.state;
334+
tr.replaceSelectionWith(chipNode).insert(
335+
tr.selection.from,
336+
space,
337+
);
338+
view.dispatch(tr);
339+
view.focus();
327340
} catch (_error) {
328341
toast.error("Failed to convert pasted text to attachment");
329342
}
@@ -421,6 +434,7 @@ export function useTiptapEditor(options: UseTiptapEditorOptions) {
421434
if (clearOnSubmit) {
422435
editor.commands.clearContent();
423436
prevBashModeRef.current = false;
437+
pasteCountRef.current = 0;
424438
setAttachments([]);
425439
draft.clearDraft();
426440
}

0 commit comments

Comments
 (0)