Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 48 additions & 0 deletions src/web-ui/src/flow_chat/components/RichTextInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,54 @@ describeWithJsdom('RichTextInput external sync', () => {
return editor as HTMLDivElement;
}

it('disables native text correction and smart punctuation in the composer', async () => {
const editor = await renderHarness(createRef<HarnessHandle>());

expect(editor.getAttribute('spellcheck')).toBe('false');
expect(editor.getAttribute('autocorrect')).toBe('off');
expect(editor.getAttribute('autocapitalize')).toBe('off');
});

it('preserves ASCII apostrophes when a contraction is completed and followed by a space', async () => {
const onChange = vi.fn();
await act(async () => root.render(<RichTextInput value="" onChange={onChange} contexts={emptyContexts} onRemoveContext={() => {}} />));
const editor = container.querySelector('.rich-text-input') as HTMLDivElement;

for (const text of ["don'", "don't", "don't "]) {
editor.textContent = text;
setCaret(editor, text.length);
await act(async () => editor.dispatchEvent(new window.InputEvent('input', {
bubbles: true, inputType: 'insertText', data: text.slice(-1),
})));

expect(editor.textContent).toBe(text);
expect(onChange).toHaveBeenLastCalledWith(text.trim(), []);
}
});

it.each(['input', 'paste'] as const)('preserves explicitly authored straight and typographic quotes on %s', async (method) => {
const onChange = vi.fn();
await act(async () => root.render(<RichTextInput value="" onChange={onChange} contexts={emptyContexts} onRemoveContext={() => {}} />));
const editor = container.querySelector('.rich-text-input') as HTMLDivElement;
const text = `"literal" 'literal' \u2018quoted\u2019 \u201Cquoted\u201D`;

await act(async () => {
if (method === 'paste') {
setCaret(editor, 0);
paste(editor, { text });
} else {
editor.textContent = text;
}
// The execCommand fixture inserts DOM text without the browser's input event.
editor.dispatchEvent(new window.InputEvent('input', {
bubbles: true, inputType: method === 'paste' ? 'insertFromPaste' : 'insertText', data: text,
}));
});

expect(editor.textContent).toBe(text);
expect(onChange).toHaveBeenLastCalledWith(text, []);
});

it('rejects native arrow/function key text without changing the composer selection', async () => {
const ref = createRef<HarnessHandle>();
const editor = await renderHarness(ref);
Expand Down
5 changes: 5 additions & 0 deletions src/web-ui/src/flow_chat/components/RichTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,8 @@ export const RichTextInput = React.forwardRef<HTMLDivElement, RichTextInputProps
}
}, [activeLargePaste]);

// WebKit also gates smart quote and dash substitution on spellcheck.
// Keep prompt text literal by disabling native text correction below.
return (
<>
<div
Expand All @@ -1733,6 +1735,9 @@ export const RichTextInput = React.forwardRef<HTMLDivElement, RichTextInputProps
ref={internalRef}
className={`rich-text-input ${isFocused ? 'rich-text-input--focused' : ''} ${className}`}
contentEditable={!disabled}
spellCheck={false}
autoCorrect="off"
autoCapitalize="off"
onInput={handleInput}
onPaste={handlePaste}
onCopy={handleCopy}
Expand Down
Loading