Skip to content

fix: autosave#6392

Merged
sid-bruno merged 2 commits intousebruno:mainfrom
pooja-bruno:fix/autosave
Dec 23, 2025
Merged

fix: autosave#6392
sid-bruno merged 2 commits intousebruno:mainfrom
pooja-bruno:fix/autosave

Conversation

@pooja-bruno
Copy link
Collaborator

@pooja-bruno pooja-bruno commented Dec 12, 2025

Description

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

Bug Fixes

  • Cursor Position Preservation: Fixed cursor jumping when editing request details and code—cursor position now remains stable during programmatic updates.
  • Autosave Expansion: Autosave now triggers for additional request properties including query parameters, headers, and form data modifications.
  • Draft Content Protection: Improved handling of draft content preservation—user-entered data is no longer lost when file updates occur unless the content genuinely changes.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 12, 2025

Walkthrough

PR enhances editor cursor position preservation during programmatic value updates across three editor components and extends autosave/draft middleware to intercept additional setter actions while refining draft clearing logic during file synchronization.

Changes

Cohort / File(s) Summary
Editor Cursor Preservation
packages/bruno-app/src/components/CodeEditor/index.js, packages/bruno-app/src/components/MultiLineEditor/index.js, packages/bruno-app/src/components/SingleLineEditor/index.js
Captures cursor position before programmatic value updates and restores it after, preventing cursor jump-to-start or -to-end issues across all three editor components.
Autosave Middleware Expansion
packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js
Adds eight new setter action types (setQueryParams, setRequestHeaders, setFormUrlEncodedParams, setMultipartFormParams, setFolderHeaders, setFolderVars, setCollectionHeaders, setCollectionVars) to actionsToIntercept to trigger autosave on bulk-set operations.
Draft Middleware Action Interception
packages/bruno-app/src/providers/ReduxStore/middlewares/draft/middleware.js
Registers the same eight setter action types in draft middleware's actionsToIntercept list for draft state handling.
Conditional Draft Clearing Logic
packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
Changes draft clearing in collectionChangeFileEvent from unconditional to conditional—only clears item.draft if it exists and differs from incoming file data beyond sequence-only updates, preserving user-typed autosave content when substantive changes occur.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–25 minutes

  • Cursor preservation in editors — repetitive pattern applied consistently across three similar components; straightforward logic but verify correctness in each context
  • Middleware action expansion — simple list additions with no control flow changes, but confirm all added actions properly route to existing handlers
  • Draft clearing refactor — requires careful validation of areItemsTheSameExceptSeqUpdate logic to ensure user-typed content is preserved correctly when file changes are non-trivial

Possibly related PRs

  • feature/autoSave (#582) #6225 — Introduces the autosave and draft middleware foundation that this PR extends with additional setter action interceptions.
  • feature/autoSave (#582) #6211 — Modifies the same Redux middleware and collections slice logic for autosave and draft behavior refinement.

Suggested labels

size/L

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno
  • bijin-bruno
  • sid-bruno

Poem

Cursors held steady, through updates they stay,
No jumps to the end of the line today,
Drafts preserved when the files align,
Middleware catches each action in time,
Editors smooth—everything's fine! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'fix: autosave' is vague and doesn't clearly convey the specific changes made across multiple editor components and middleware configurations. Consider a more descriptive title like 'fix: preserve cursor position in editors and enhance autosave/draft middleware' to better reflect the scope of changes.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6652cca and 84ac092.

📒 Files selected for processing (6)
  • packages/bruno-app/src/components/CodeEditor/index.js (1 hunks)
  • packages/bruno-app/src/components/MultiLineEditor/index.js (1 hunks)
  • packages/bruno-app/src/components/SingleLineEditor/index.js (1 hunks)
  • packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js (3 hunks)
  • packages/bruno-app/src/providers/ReduxStore/middlewares/draft/middleware.js (3 hunks)
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CODING_STANDARDS.md)

**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation. No tabs, just spaces
Stick to single quotes for strings. For JSX/TSX attributes, use double quotes (e.g., )
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single params
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses
Space before and after the arrow in arrow functions. () => {} is good
No space between function name and parentheses. func() not func ()
Semicolons go at the end of the line, not on a new line
Names for functions need to be concise and descriptive
Add in JSDoc comments to add more details to the abstractions if needed
Add in meaningful comments instead of obvious ones where complex code flow is explained properly

Files:

  • packages/bruno-app/src/providers/ReduxStore/middlewares/draft/middleware.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
  • packages/bruno-app/src/components/CodeEditor/index.js
  • packages/bruno-app/src/components/MultiLineEditor/index.js
  • packages/bruno-app/src/components/SingleLineEditor/index.js
  • packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js
🧬 Code graph analysis (3)
packages/bruno-app/src/components/CodeEditor/index.js (2)
packages/bruno-app/src/utils/codemirror/autocomplete.js (2)
  • cursor (337-337)
  • cursor (593-593)
packages/bruno-app/src/utils/codemirror/mock-data-hints.js (1)
  • cursor (6-6)
packages/bruno-app/src/components/MultiLineEditor/index.js (1)
packages/bruno-app/src/utils/codemirror/autocomplete.js (2)
  • cursor (337-337)
  • cursor (593-593)
packages/bruno-app/src/components/SingleLineEditor/index.js (2)
packages/bruno-app/src/utils/codemirror/autocomplete.js (2)
  • cursor (337-337)
  • cursor (593-593)
packages/bruno-app/src/utils/codemirror/mock-data-hints.js (1)
  • cursor (6-6)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: SSL Tests - macOS
  • GitHub Check: SSL Tests - Windows
  • GitHub Check: SSL Tests - Linux
  • GitHub Check: Playwright E2E Tests
  • GitHub Check: CLI Tests
  • GitHub Check: Unit Tests
🔇 Additional comments (6)
packages/bruno-app/src/components/MultiLineEditor/index.js (1)

156-161: Cursor preservation pattern looks good.

The approach of capturing cursor position before setValue and restoring after is the standard CodeMirror pattern. CodeMirror's setCursor gracefully clamps out-of-bounds positions, so if the new value is shorter than the original cursor position, the cursor will be placed at the nearest valid position.

This is consistent with the same fix applied across SingleLineEditor and CodeEditor.

packages/bruno-app/src/providers/ReduxStore/middlewares/draft/middleware.js (1)

3-82: Consistent additions to draft interception list.

The new set* actions correctly complement the existing individual CRUD actions for query params, headers, form params, and vars at request/folder/collection levels. This ensures draft state detection covers bulk operations that may be triggered programmatically.

The list aligns with the autosave middleware additions.

packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js (1)

2657-2662: Core autosave fix: conditional draft clearing.

This is the key change that prevents losing user-typed characters during autosave. By only clearing item.draft when it matches the incoming file data, you avoid the race condition where:

  1. User types → draft updated
  2. Autosave writes to disk
  3. File watcher triggers collectionChangeFileEvent
  4. Draft would have been cleared, losing any characters typed between steps 1 and 2

The use of areItemsTheSameExceptSeqUpdate is appropriate here since it's already employed earlier in this reducer for similar comparison logic.

packages/bruno-app/src/components/SingleLineEditor/index.js (1)

171-175: Cursor preservation consistent with MultiLineEditor.

Same pattern applied correctly. This ensures a smooth editing experience when autosave triggers value updates from external sources.

packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js (1)

4-83: Autosave interception list expanded consistently.

The new set* actions are correctly added to trigger autosave. The middleware's existing logic at lines 152-170 will route saves appropriately based on the presence of itemUid, folderUid, or collectionUid in the action payload, which all these new actions include.

This mirrors the draft middleware additions exactly, maintaining consistency between the two interception lists.

packages/bruno-app/src/components/CodeEditor/index.js (1)

231-236: LGTM! Cursor preservation implemented correctly.

The cursor capture and restore around setValue prevents the cursor from jumping during programmatic value updates. CodeMirror handles bounds checking automatically in setCursor, so this is safe even when the new value differs significantly in length or structure.


Comment @coderabbitai help to get the list of available commands and usage tips.

@pooja-bruno pooja-bruno marked this pull request as draft December 12, 2025 11:00
@pooja-bruno pooja-bruno marked this pull request as ready for review December 17, 2025 06:53
@sid-bruno sid-bruno merged commit ce33cee into usebruno:main Dec 23, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants