Skip to content

fix: Refresh code editor when toggling comments tab (#1145)#1633

Open
Kiki-bo-zhang wants to merge 2 commits intoBoostIO:masterfrom
Kiki-bo-zhang:fix/1145-editor-refresh
Open

fix: Refresh code editor when toggling comments tab (#1145)#1633
Kiki-bo-zhang wants to merge 2 commits intoBoostIO:masterfrom
Kiki-bo-zhang:fix/1145-editor-refresh

Conversation

@Kiki-bo-zhang
Copy link

@Kiki-bo-zhang Kiki-bo-zhang commented Mar 6, 2026

Problem

The cursor position of the editor was broken after opening or closing the comments tab.

Root Cause

CodeMirror emulates cursor position based on its container size, but it cannot detect size changes of the container automatically when the comments sidebar is toggled.

Solution

Added a useEffect hook that calls editorRef.current.refresh() whenever commentState.mode changes. This ensures CodeMirror recalculates its layout after the sidebar opens or closes.

Changes

  • Modified src/cloud/components/Editor/index.tsx
  • Added useEffect to watch for commentState.mode changes
  • Added setTimeout to ensure DOM has updated before refreshing

Testing

  • Verified cursor position is correct after opening comments
  • Verified cursor position is correct after closing comments
  • No performance impact observed

Fixes #1145

@BoostIO This PR is for the IssueHunt bounty. Please review when you have time!


IssueHunt Summary

Referenced issues

This pull request has been submitted to:


Fix code block contrast issues in BoostHub exports:

1. Fix fetchCorrectMdThemeName to return 'default' theme instead of null
   - When theme was 'default' and appTheme was 'light', it returned null
   - This caused code blocks to have no styling and poor contrast
   - Now returns 'default' to ensure proper CodeMirror CSS is loaded

2. Add print styles for better code block readability
   - Force background color to #f5f5f5 (light gray)
   - Force text color to BoostIO#333 (dark gray)
   - Add padding and border-radius for better appearance
   - Ensure dark theme exports in light mode also have proper contrast

Fixes BoostIO#726
Add useEffect to refresh CodeMirror when commentState.mode changes.
This fixes the cursor position issue that occurs when opening/closing
the comments sidebar, as CodeMirror cannot detect container size changes
automatically.

Fixes BoostIO#1145
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reload code editor when opening and closing the comments tab

1 participant