Skip to content

Commit f7fa766

Browse files
StiensWoutclaude
andcommitted
fix(web): literal Pi answers report no context references
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent fed23f4 commit f7fa766

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

‎apps/web/src/components/ComposerPromptEditorTiptap.tsx‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
904904
value,
905905
cursor: initialCursor,
906906
expandedCursor: initialExpandedCursor,
907-
contextIds: collectInlineContextIds(value),
907+
contextIds: literalText ? [] : collectInlineContextIds(value),
908908
});
909909
const selectionRangeRef = useRef({ start: initialExpandedCursor, end: initialExpandedCursor });
910910
const isApplyingControlledUpdateRef = useRef(false);
@@ -933,6 +933,8 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
933933
const handleEditorChange = useCallback(
934934
(updated: TiptapEditor) => {
935935
const map = serializeEditorDoc(updated.state.doc);
936+
// Literal answers hold no chips, so reference-shaped text is not a context.
937+
const contextIds = literalText ? [] : map.contextIds;
936938
const { from, to } = updated.state.selection;
937939
const fromFlat = pmToFlat(map, from);
938940
const toFlat = pmToFlat(map, to);
@@ -954,8 +956,8 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
954956
previousSnapshot.value === nextValue &&
955957
previousSnapshot.cursor === nextCursor &&
956958
previousSnapshot.expandedCursor === nextExpandedCursor &&
957-
previousSnapshot.contextIds.length === map.contextIds.length &&
958-
previousSnapshot.contextIds.every((id, index) => id === map.contextIds[index])
959+
previousSnapshot.contextIds.length === contextIds.length &&
960+
previousSnapshot.contextIds.every((id, index) => id === contextIds[index])
959961
);
960962
if (isApplyingControlledUpdateRef.current) return;
961963
if (!snapshotChanged) {
@@ -974,7 +976,7 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
974976
value: nextValue,
975977
cursor: nextCursor,
976978
expandedCursor: nextExpandedCursor,
977-
contextIds: map.contextIds,
979+
contextIds,
978980
};
979981
// A fence holds no chips, so nothing in it should summon the mention or
980982
// command menu: `@` in code is a decorator, not a file. Suppressing the
@@ -986,13 +988,7 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
986988
inCodeBlock ||
987989
isCollapsedCursorAdjacentToInlineToken(nextValue, nextCursor, "left") ||
988990
isCollapsedCursorAdjacentToInlineToken(nextValue, nextCursor, "right");
989-
onChangeRef.current(
990-
nextValue,
991-
nextCursor,
992-
nextExpandedCursor,
993-
suppressTrigger,
994-
map.contextIds,
995-
);
991+
onChangeRef.current(nextValue, nextCursor, nextExpandedCursor, suppressTrigger, contextIds);
996992
},
997993
[clampEditorCursor, literalText],
998994
);
@@ -1500,7 +1496,7 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
15001496
value: map.value,
15011497
cursor: clampEditorCursor(map.value, flatToCollapsed(map, fromFlat)),
15021498
expandedCursor: Math.max(0, Math.min(map.value.length, flatToMarkdown(map, fromFlat))),
1503-
contextIds: map.contextIds,
1499+
contextIds: literalText ? [] : map.contextIds,
15041500
};
15051501
const toFlat = pmToFlat(map, to);
15061502
selectionRangeRef.current = {
@@ -1509,7 +1505,7 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
15091505
};
15101506
snapshotRef.current = next;
15111507
return next;
1512-
}, [clampEditorCursor, editor]);
1508+
}, [clampEditorCursor, editor, literalText]);
15131509

15141510
// Controlled value/cursor from the store (history recall, chip insertion…).
15151511
useLayoutEffect(() => {

0 commit comments

Comments
 (0)