Skip to content

Support for RTL text in find decorations#314872

Open
kamyarmg wants to merge 3 commits intomicrosoft:mainfrom
kamyarmg:bidi-find-problem
Open

Support for RTL text in find decorations#314872
kamyarmg wants to merge 3 commits intomicrosoft:mainfrom
kamyarmg:bidi-find-problem

Conversation

@kamyarmg
Copy link
Copy Markdown

@kamyarmg kamyarmg commented May 6, 2026

Summary

Fixes incorrect visual ordering when Find highlights matches inside mixed LTR/RTL text.

In lines containing RTL text, Find no longer applies inline styling that splits the rendered content into multiple bidi runs. Instead, it uses decorations that preserve the correct visual ordering of highlighted text.

Fixes #233573.

Problem

When Find highlights a match inside a line containing mixed LTR and RTL text, the highlight can split the rendered content into multiple inline segments.

In some cases, this changes the visual ordering of the RTL portion of the line, causing highlighted matches to appear with characters in the wrong order even though the underlying text is correct.

Root Cause

Find match decorations relied on inline text styling.

While this works correctly for normal LTR text, applying inline styling inside mixed bidi content can split a visual bidi run into separate segments. Once split, browser bidi layout may reorder the segments visually, making the highlighted substring appear incorrect.

Fix

This change makes Find match decorations aware of RTL content.

  • Lines containing RTL text now use decorations that avoid inline text styling.
  • LTR-only lines continue using the existing rendering behavior.
  • Current match and regular match decorations now share the same RTL-aware decoration selection logic.

This preserves Find highlighting while avoiding the bidi run splitting that caused incorrect visual ordering.

Screenshots

Original Text

Screenshot From 2026-05-07 02-05-35

Before

Screenshot From 2026-05-07 02-11-49

After

Screenshot From 2026-05-07 02-13-07

How to Test

  1. Open a file containing mixed LTR/RTL text on the same line.
  2. Search for a substring inside the RTL portion of the line.
  3. Verify that the highlighted match preserves the correct visual character order.
  4. Repeat the same test on an LTR-only line and verify that Find highlighting still behaves normally.

Copilot AI review requested due to automatic review settings May 6, 2026 22:49
@kamyarmg kamyarmg changed the title Add support for RTL text in find decorations and update tests Support for RTL text in find decorations May 6, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the editor Find match decorations to preserve correct visual ordering in mixed LTR/RTL lines by avoiding inline styling (which can split bidi runs and cause incorrect rendering). It also adds a browser-level FindModel test to validate the RTL-aware behavior.

Changes:

  • Introduces RTL-aware selection of find match decoration options (regular/current match), falling back to non-inline decorations on lines containing RTL text.
  • Adds new “bidi” decoration option variants that omit inlineClassName while keeping existing find match visuals (className/overview ruler/minimap).
  • Adds a test ensuring mixed LTR/RTL lines avoid inline styling while LTR-only lines keep the existing inline styling.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/vs/editor/contrib/find/browser/findDecorations.ts Adds RTL detection and new bidi-safe decoration options; switches find match/current match decorations based on RTL presence.
src/vs/editor/contrib/find/test/browser/findModel.test.ts Adds coverage for RTL-aware decoration selection (inline vs non-inline styling).

Comment thread src/vs/editor/contrib/find/browser/findDecorations.ts Outdated
Comment thread src/vs/editor/contrib/find/browser/findDecorations.ts Outdated
Comment thread src/vs/editor/contrib/find/browser/findDecorations.ts Outdated
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.

When searching rtl letters in Arabic using Ctrl+F the word gets reversed and disconnected

3 participants