fix(muya): highlight regexp newline search matches (#3261) by Jocs · Pull Request #5650 · marktext/marktext · GitHub
Skip to content

fix(muya): highlight regexp newline search matches (#3261) - #5650

Merged
Jocs merged 4 commits into
developfrom
fix/3261-regexp-newline-highlight
Oct 8, 2026
Merged

Jocs merged 4 commits into
developfrom
fix/3261-regexp-newline-highlight

Conversation

@Jocs

@Jocs Jocs commented Oct 7, 2026

Copy link
Copy Markdown
Member

Closes #3261

Summary

A regexp \n search found its matches — the find bar counted them (1/4) — but drew no highlight: muya's soft and hard line-break renderers never applied the search highlight.

A match on a line break can't be wrapped like ordinary text. The \n must stay a bare text node or the line stops breaking, and a background on an inline box whose only content is a forced break paints nothing. So the line-break renderers now emit an empty highlight band just before the break, giving \n matches the end-of-line marker VS Code draws while leaving the line breaks intact.

Type of change

  • Bug fix (non-breaking, fixes an issue)
  • New feature (non-breaking, adds functionality)
  • Breaking change (causes existing functionality to change)
  • Documentation update

Test plan

  • New tests added (or explain why not needed)

  • Manually tested on:

  • Unit: search.spec.ts asserts a regexp \n search bands every soft and hard line break and that the \n text (hence the line split) survives; softLineBreak.spec.ts asserts the emitted band shape.

  • E2E: search-replace.spec.ts verifies in a real browser that both breaks are drawn and the content stays on three rows.

  • pnpm -C packages/muya exec vitest run — 2431 passing; lint / lint:types clean.

Notes for reviewers [optional]

Paragraph breaks (separate blocks) carry no \n in the model, so \n still does not match across blocks — only line breaks inside a block, which is what #3261 reports.


By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

A regexp `\n` search found its matches — the find bar counted them — but
drew nothing, because the soft/hard line-break renderers never applied
the search highlight.

A match on a line break can't be wrapped like ordinary text: the `\n`
must stay a bare text node or the line stops breaking, and a background
on an inline box whose only content is a forced break paints nothing.
So render an empty highlight band just before the break, giving the
match a visible end-of-line marker and leaving the line breaks intact.
@Jocs Jocs changed the title fix(muya): highlight regexp \n search matches (#3261) fix(muya): highlight regexp newline search matches (#3261) Oct 7, 2026
@Jocs
Jocs requested a balanced review from Copilot October 7, 2026 17:40

Copilot AI 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.

🟡 Changes recommended

The in-flow highlight band can wrap onto an extra visual line and alter document layout.

1 open finding
What changed in this PR

Fixes missing search highlights for regex newline matches in Muya while preserving line breaks.

Changes:

  • Adds highlight bands for soft and hard line breaks.
  • Preserves raw newline text during rendering.
  • Adds unit and browser regression coverage.
File Description
packages/​muya/​src/​search/​__tests__/​search.spec.ts Tests newline search matches.
packages/​muya/​src/​inlineRenderer/​renderer/​softLineBreak.ts Renders soft-break highlight bands.
packages/​muya/​src/​inlineRenderer/​renderer/​highlight.ts Adds shared line-break highlight generation.
packages/​muya/​src/​inlineRenderer/​renderer/​hardLineBreak.ts Renders hard-break highlight bands.
packages/​muya/​src/​inlineRenderer/​renderer/​__tests__/​softLineBreak.spec.ts Tests soft-break vnode structure.
packages/​muya/​e2e/​tests/​editing/​search-replace.spec.ts Adds browser-level regression coverage.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Jocs added 3 commits October 8, 2026 01:49
Copilot review: the band was an in-flow box with ~4px width, so a line
that already filled the content width wrapped it — and the text after
it — onto a row of its own. The band is now out of flow, positioned
against the line-break span; the hard-break band sits before the hanging
trailing spaces so it does not revoke the hang (#2094). The new E2E case
measures row geometry, which the earlier `textContent` check missed.

Also trims the comments this PR added to the ones the code cannot state.
Out of flow the inactive band is blockified, and `.mu-selection` carried no
height of its own — it took it from the line box — so the non-active `\n`
matches collapsed to a zero-height, invisible box. Pin the band height the
way the active `.mu-highlight` already does, and assert both bands have a
non-zero box in the E2E case.
Match how the other renderer helpers are wired (`this.highlight`,
`this.backlashInToken`): a default-exported module registered in the
`inlineSyntaxRenderer` map, instead of a named export called with `.call`.
@Jocs
Jocs merged commit 4d15c81 into develop Oct 8, 2026
7 checks passed
@Jocs
Jocs deleted the fix/3261-regexp-newline-highlight branch October 8, 2026 06:11
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.

Regex search doesn't highlight newlines

2 participants