From 668fbfb0e0a2d62312a70f782cade2a376f5e85a Mon Sep 17 00:00:00 2001 From: Bacteria <32611672+bacteriostat@users.noreply.github.com> Date: Wed, 9 Jul 2025 19:03:12 +0530 Subject: [PATCH] bugfix: Use SingleLineEditor in New Request form to add env variable highlighting (#4954) * Use SingleLineEditor in New Request form to add variable highlighting --- .../002-create-new-collection.spec.ts | 6 ++-- .../components/RequestPane/QueryUrl/index.js | 1 + .../components/Sidebar/NewRequest/index.js | 32 +++++++++++-------- .../src/components/SingleLineEditor/index.js | 4 +++ 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/e2e-tests/001-sanity-tests/002-create-new-collection.spec.ts b/e2e-tests/001-sanity-tests/002-create-new-collection.spec.ts index 4996ce580..705a2bc3b 100644 --- a/e2e-tests/001-sanity-tests/002-create-new-collection.spec.ts +++ b/e2e-tests/001-sanity-tests/002-create-new-collection.spec.ts @@ -12,10 +12,10 @@ test('Create new collection and add a simple HTTP request', async ({ page, creat await page.getByRole('button', { name: 'Save' }).click(); await page.locator('#create-new-tab').getByRole('img').click(); await page.getByPlaceholder('Request Name').fill('r1'); - await page.getByPlaceholder('Request URL').click(); - await page.getByPlaceholder('Request URL').fill('http://localhost:8081'); + await page.locator('#new-request-url .CodeMirror').click(); + await page.locator('textarea').fill('http://localhost:8081'); await page.getByRole('button', { name: 'Create' }).click(); - await page.locator('pre').filter({ hasText: 'http://localhost:' }).click(); + await page.locator('#request-url .CodeMirror').click(); await page.locator('textarea').fill('/ping'); await page.locator('#send-request').getByRole('img').nth(2).click(); diff --git a/packages/bruno-app/src/components/RequestPane/QueryUrl/index.js b/packages/bruno-app/src/components/RequestPane/QueryUrl/index.js index 321ed4fd5..2035ba00c 100644 --- a/packages/bruno-app/src/components/RequestPane/QueryUrl/index.js +++ b/packages/bruno-app/src/components/RequestPane/QueryUrl/index.js @@ -83,6 +83,7 @@ const QueryUrl = ({ item, collection, handleRun }) => {
{ const dispatch = useDispatch(); const inputRef = useRef(); + const storedTheme = useTheme(); + const collection = useSelector(state => state.collections.collections?.find(c => c.uid === collectionUid)); const { brunoConfig: { presets: collectionPresets = {} } @@ -413,20 +417,22 @@ const NewRequest = ({ collectionUid, item, isEphemeral, onClose }) => { onMethodSelect={(val) => formik.setFieldValue('requestMethod', val)} />
-
- + { + formik.handleChange({ + target: { + name: "requestUrl", + value: value + } + }); + }} + collection={collection} + variablesAutocomplete={true} />
diff --git a/packages/bruno-app/src/components/SingleLineEditor/index.js b/packages/bruno-app/src/components/SingleLineEditor/index.js index 5b15b973b..4ced64f1e 100644 --- a/packages/bruno-app/src/components/SingleLineEditor/index.js +++ b/packages/bruno-app/src/components/SingleLineEditor/index.js @@ -90,6 +90,7 @@ class SingleLineEditor extends Component { this.editor.setValue(String(this.props.value ?? '')); this.editor.on('change', this._onEdit); + this.editor.on('paste', this._onPaste); this.addOverlay(variables); this._enableMaskedEditor(this.props.isSecret); this.setState({ maskInput: this.props.isSecret }); @@ -117,6 +118,8 @@ class SingleLineEditor extends Component { } }; + _onPaste = (_, event) => this.props.onPaste?.(event); + componentDidUpdate(prevProps) { // Ensure the changes caused by this update are not interpreted as // user-input changes which could otherwise result in an infinite @@ -147,6 +150,7 @@ class SingleLineEditor extends Component { componentWillUnmount() { if (this.editor) { this.editor.off('change', this._onEdit); + this.editor.off('paste', this._onPaste); this.editor.getWrapperElement().remove(); this.editor = null; }