Skip to content

Commit 9a32e17

Browse files
committed
Fix some cross-browser inconsistencies, selection range deletion cursor positioning and prevented pasting arbitrary HTML content, extended insertText to handle multiline content
1 parent e22b10e commit 9a32e17

File tree

11 files changed

+807
-108
lines changed

11 files changed

+807
-108
lines changed

src/prompt-input/__tests__/event-handlers.test.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,20 +2059,31 @@ describe('handleReferenceTokenDeletion - non-collapsed selection cleanup', () =>
20592059
expect(event.isDefaultPrevented()).toBe(true);
20602060
});
20612061

2062-
test('merges remaining content from end paragraph into start paragraph', () => {
2062+
test('non-collapsed selection emits state change via emitChange', () => {
20632063
const firstP = addParagraph(el, 'Line A');
20642064
addParagraph(el, 'Line B');
20652065
const lastP = addParagraph(el, 'Line C');
20662066
// Select from middle of first to middle of last: "e A\nLine B\nLin"
20672067
setSelection(firstP.firstChild!, 3, lastP.firstChild!, 3);
20682068
const event = makeKeyboardEvent('Backspace');
20692069
const state = { skipNextZeroWidthUpdate: false, menuSelectionTokenId: null };
2070-
handleReferenceTokenDeletion(event, true, el, state, undefined, undefined, null);
2070+
const cc = new CaretController(el);
2071+
const emitChange = jest.fn();
2072+
const tokens: PromptInputProps.InputToken[] = [
2073+
{ type: 'text', value: 'Line A' },
2074+
{ type: 'break', value: '\n' },
2075+
{ type: 'text', value: 'Line B' },
2076+
{ type: 'break', value: '\n' },
2077+
{ type: 'text', value: 'Line C' },
2078+
];
2079+
handleReferenceTokenDeletion(event, true, el, state, undefined, undefined, cc, tokens, emitChange);
20712080
expect(event.isDefaultPrevented()).toBe(true);
2072-
// Should merge: "Lin" + "e C" = "Line C" in one paragraph
2073-
const paragraphs = el.querySelectorAll('p');
2074-
expect(paragraphs).toHaveLength(1);
2075-
expect(paragraphs[0].textContent).toBe('Line C');
2081+
expect(emitChange).toHaveBeenCalled();
2082+
const [newTokens, caretPos] = emitChange.mock.calls[0];
2083+
// "Lin" + "e C" → remaining text after removing positions 3..17
2084+
expect(caretPos).toBe(3);
2085+
const textValues = newTokens.filter((t: any) => t.type === 'text').map((t: any) => t.value);
2086+
expect(textValues.join('')).toBe('Line C');
20762087
});
20772088

20782089
test('preserves paragraphs outside the selection range', () => {

0 commit comments

Comments
 (0)