Skip to content

Allow text selection inside code blocks - #362

Merged
wingleeio merged 1 commit into
zeronsh:mainfrom
dcdyouget:fix/code-block-text-selection
Sep 15, 2026
Merged

wingleeio merged 1 commit into
zeronsh:mainfrom
dcdyouget:fix/code-block-text-selection

Conversation

@dcdyouget

@dcdyouget dcdyouget commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Register syntax-highlighted code lines with the shared Markdown selection system.
  • Support partial, multi-line, and prose-to-code selections in transcripts and Markdown Preview.
  • Preserve blank code lines when copying a selection across them.
  • Keep syntax highlighting, horizontal scrolling, Fit Content, and whole-block Copy behavior unchanged.

This is a focused extraction and adaptation of the code-selection work from the closed #331. It intentionally excludes the unrelated settings and task-group changes from that PR.

Fixes #332

中文说明

问题

聊天记录和 Markdown 预览中的代码块只能通过右上角的 Copy 按钮复制全部内容,无法像普通 Markdown 文本一样拖选并复制其中某一行或部分代码,也无法从普通文本连续选择到代码块内容。

修复内容

  • 将带语法高亮的每一行代码接入现有 Markdown 文本选择系统。
  • 支持单行、跨多行以及普通文本与代码块之间的连续选择。
  • 跨越空白代码行时保留原有换行,避免复制结果丢失空行。
  • 保持语法高亮、横向滚动、Fit Content 和整块复制按钮的原有行为不变。

本 PR 从已关闭的 #331 中提取并适配代码块选择相关实现,未包含其中无关的设置和任务分组改动;用于修复 #332

Testing

  • cargo test -p zeron-ui --lib (960 passed)
  • rustfmt --edition 2024 --check crates/ui/src/markdown/render.rs crates/ui/src/markdown/selection.rs
  • git diff --check

@wingleeio wingleeio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Security audit of 65fda35: approved. No malicious code or new merge-blocking security issue found in the reviewed changes.

Reviewed the complete commit and two-file diff, plus surrounding Markdown selection, text-layout geometry, preview scopes, clipboard actions, code rendering/caching, and transcript selection behavior. The production change registers syntax-highlighted source lines with the existing selection machinery and preserves interior empty lines when joining selected spans. Rendering and copy use the same source text; no code evaluation, clipboard substitution, network access, credential handling, file access, new dependency, CI modification, binary asset, executable mode or symlink is introduced. New code-line keys preserve the Markdown Preview scope prefix. Selection listeners and Linux primary-selection behavior reuse the existing user-gesture-driven path.

Validation:

  • Combined the PR with current main 9601a24 in an isolated worktree. The resulting local merge ff3b3ec64f5c8c1e98cba10e7688ac8e1a7dd368 differs from main only in the two intended Markdown files.
  • cargo test --locked -p zeron-ui --lib -- --test-threads=1: 1001 passed, zero failures, including code-line selection, blank-line preservation, preview isolation, scrolling, copy and Fit Content regressions.
  • An independent harness importing the exact production selection.rs passed 1444 valid-character-boundary Unicode/empty-line/reverse-direction cases. This is additional coverage, not exhaustive fuzzing or a GPUI mouse-geometry test.
  • rustfmt checks and git diff --check passed; added-line hidden/control-character scan found none.
  • Existing head CI is green for desktop UI, session synchronization, iOS, Linux browser and macOS native/frame recovery. Those remote runs predate the latest main merge; current-main compatibility was tested locally as described above.

The assessment is scoped to this PR and its affected paths; source review cannot prove contributor intent or guarantee zero vulnerabilities. No new manual native-platform test was performed beyond existing CI and the local headless desktop suite.

@wingleeio
wingleeio merged commit d353ebb into zeronsh:main Sep 15, 2026
6 checks passed
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.

Allow text selection inside code blocks

2 participants