feat: split pasted env assignments#2075
Conversation
Greptile SummaryThis PR adds dotenv-style paste splitting to env var forms in the MCP modal and provider settings modal. When a user pastes multi-line env assignment content, the new
Confidence Score: 4/5Safe to merge; the paste feature is additive and falls back to the browser default on any non-env content, so existing behaviour is unchanged for users who do not paste dotenv blocks. The core parser and splice helper are well-tested and the integration is clean. Two quality gaps exist: inline src/renderer/lib/env-paste.ts (inline comment stripping) and src/renderer/features/mcp/components/KeyValueSection.tsx (value-field paste behaviour)
|
| Filename | Overview |
|---|---|
| src/renderer/lib/env-paste.ts | New parser for dotenv-style paste content; correctly rejects non-env blocks but does not strip inline # comments from values |
| src/renderer/lib/env-paste.test.ts | New test file with good coverage of parsing and replacement; no issues found |
| src/renderer/features/mcp/components/KeyValueSection.tsx | Adds paste split behaviour via handlePaste; both key and value inputs share identical paste logic which can overwrite an existing key when pasting into the value field |
| src/renderer/features/mcp/components/McpModal.tsx | One-line change enabling splitEnvPaste on the existing KeyValueSection; straightforward and correct |
| src/renderer/features/settings/components/CustomCommandModal.tsx | handleEnvPaste added correctly; EnvEntry type is structurally identical to EnvPasteEntry so no type unsoundness; same key-overwrite caveat as KeyValueSection applies |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User pastes text into key or value input] --> B{splitEnvPaste enabled?}
B -- No --> Z[Browser default paste]
B -- Yes --> C[parseEnvAssignmentPaste]
C --> D{All non-comment lines\nmatch assignment regex?}
D -- No or empty --> Z
D -- Yes --> E[e.preventDefault]
E --> F[Build pastedEntries with row IDs]
F --> G[replaceEnvEntryWithPaste\nslice + insert + slice]
G --> H[onChange or setForm\nwith new entries array]
H --> I[Rows expanded in UI]
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
src/renderer/lib/env-paste.ts:6-24
**Inline `#` comments not stripped from values**
Standard dotenv parsers treat anything after an unquoted `#` (preceded by whitespace) as a comment and exclude it from the value. The current regex captures everything after `=` and passes it to `normalizeEnvValue`, which only strips surrounding quotes but leaves trailing comments intact. A user pasting from a real `.env` file where a line ends with a comment will get the comment text appended to the stored value.
### Issue 2 of 2
src/renderer/features/mcp/components/KeyValueSection.tsx:63-80
**Value field paste replaces the row's key**
Both the key and value inputs share the same `handlePaste` path, so a paste into the value input is treated identically to a paste into the key input. If the user has already typed a key name and then pastes a single `NAME=content` string (e.g. copied from a config tool) into the value field, the parser matches it as an env assignment and overwrites the user's existing key name with the parsed key, discarding the value the user intended to set.
Reviews (1): Last reviewed commit: "feat: split pasted env assignments" | Re-trigger Greptile
Summary
Tests