Skip to content

🐛 fix(code-editor): align highlight layer with textarea layout - #643

Merged
Innei merged 2 commits into
lobehub:masterfrom
CrazyBucket:fix/code-editor-selection-alignment
Sep 8, 2026
Merged

Innei merged 2 commits into
lobehub:masterfrom
CrazyBucket:fix/code-editor-selection-alignment

Conversation

@CrazyBucket

Copy link
Copy Markdown
Contributor

💻 变更类型 | Change Type

  • 🐛 fix

🔀 变更说明 | Description of Change

修复 CodeEditor 多行编辑时光标、选区与高亮文本错位的问题。

高亮镜像层原有的 flex 行布局会引入额外间距并折叠空行,导致其与 textarea 的文本位置不一致。本次仅调整 CodeEditor 内部样式:

  • 使用与 textarea 一致的文本流,保留空行及末尾换行高度。
  • 统一 token 字形,避免粗体、斜体改变文本度量。

保留语法高亮颜色,不影响 SyntaxHighlighter 的公共展示样式。

📝 补充信息 | Additional Information

关联 Issue:#534

已验证多行及空行、Enter 换行、鼠标拖选、Shift + 方向键选择和长文本自动换行。

Before

修复前:选区与高亮文本错位

After

修复后:选区与高亮文本对齐

@vercel

vercel Bot commented Sep 8, 2026

Copy link
Copy Markdown

@CrazyBucket is attempting to deploy a commit to the LobeHub OSS Team on Vercel.

A member of the Team first needs to authorize it.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d6fdeb8355

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/CodeEditor/style.ts Outdated
/* Token emphasis must not change glyph metrics relative to the textarea. */
span {
font-weight: inherit !important;
font-style: normal !important;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Inherit the editor's font style in the mirror

When CodeEditor is placed in an italicized container or receives style={{ fontStyle: 'italic' }}, the textarea inherits that style while every highlighted span is now forced to normal. This changes the highlighted glyph metrics relative to the caret and selection layer, reintroducing the alignment problem this change addresses; override token italics by inheriting the mirror's base font style instead.

Useful? React with 👍 / 👎.

@Innei
Innei merged commit 384b444 into lobehub:master Sep 8, 2026
1 check failed
github-actions Bot pushed a commit that referenced this pull request Sep 8, 2026
## [5.40.2](v5.40.1...v5.40.2) (2026-09-08)

### 🎫 Chores

* **deps**: Upgrade @base-ui/react to 1.8.0, closes [#644](#644) [mui/base-ui#5442](mui/base-ui#5442) ([ca25fd6](ca25fd6))
* **release**: [email protected] [skip ci] ([930f623](930f623))

### 🐛 Bug Fixes

* **code-editor**: Align highlight layer with textarea layout, closes [#643](#643) ([384b444](384b444))
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