Skip to content

Commit 5bcc2e0

Browse files
authored
Replace newlines with spaces when switching from Duck.ai to Search tab. (#1894)
This matches how SERP behaves
1 parent 87686e1 commit 5bcc2e0

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

special-pages/pages/new-tab/app/omnibar/components/SearchForm.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function SearchForm({ autoFocus, onOpenSuggestion, onSubmit }) {
2727
const platformName = usePlatformName();
2828

2929
const {
30-
term,
30+
term: _term,
3131
setTerm,
3232
suggestionsListId,
3333
suggestions,
@@ -39,6 +39,9 @@ export function SearchForm({ autoFocus, onOpenSuggestion, onSubmit }) {
3939
hideSuggestions,
4040
} = useSearchFormContext();
4141

42+
// When switching from Duck.ai to Search, there may be newlines in the term. Remove these.
43+
const term = _term.replace(/\n/g, ' ');
44+
4245
let inputBase, inputCompletion;
4346
if (selectedSuggestion) {
4447
const completionString = getSuggestionCompletionString(selectedSuggestion, term);
@@ -153,8 +156,7 @@ export function SearchForm({ autoFocus, onOpenSuggestion, onSubmit }) {
153156
{inputSuffix && (
154157
<>
155158
<span class={styles.suffixSpacer} inert>
156-
{/* Strip newlines to match <input> behaviour which doesn't render them */}
157-
{(inputBase + inputCompletion).replace(/\n/g, '') || t('omnibar_searchFormPlaceholder')}
159+
{inputBase + inputCompletion || t('omnibar_searchFormPlaceholder')}
158160
</span>
159161
<span class={styles.suffix} inert>
160162
{inputSuffixText}

special-pages/pages/new-tab/app/omnibar/integration-tests/omnibar.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,31 @@ test.describe('omnibar widget', () => {
206206
await expect(omnibar.searchInput()).toHaveValue('pizza');
207207
});
208208

209+
test('mode switching preserves multiline text with proper formatting', async ({ page }, workerInfo) => {
210+
const ntp = NewtabPage.create(page, workerInfo);
211+
const omnibar = new OmnibarPage(ntp);
212+
await ntp.reducedMotion();
213+
214+
await ntp.openPage({ additional: { omnibar: true } });
215+
await omnibar.ready();
216+
217+
// Start in Duck.ai mode, type multiline text
218+
await omnibar.aiTab().click();
219+
await omnibar.expectMode('ai');
220+
await omnibar.chatInput().fill('hello\nworld');
221+
await expect(omnibar.chatInput()).toHaveValue('hello\nworld');
222+
223+
// Switch to Search mode - newlines should become spaces
224+
await omnibar.searchTab().click();
225+
await omnibar.expectMode('search');
226+
await expect(omnibar.searchInput()).toHaveValue('hello world');
227+
228+
// Switch back to Duck.ai mode - newlines should be restored
229+
await omnibar.aiTab().click();
230+
await omnibar.expectMode('ai');
231+
await expect(omnibar.chatInput()).toHaveValue('hello\nworld');
232+
});
233+
209234
test('omnibar without AI enabled does not show tab list', async ({ page }, workerInfo) => {
210235
const ntp = NewtabPage.create(page, workerInfo);
211236
const omnibar = new OmnibarPage(ntp);

0 commit comments

Comments
 (0)