Skip to content

editorFind: fix swapped findMatch foreground colors (#228782) - #270395

Merged
Dmitriy Vasyura (dmitrivMS) merged 4 commits into
microsoft:mainfrom
hirossan4049:fix/228782
Oct 29, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 4 commits into
microsoft:mainfrom
hirossan4049:fix/228782

Conversation

@hirossan4049

@hirossan4049 hirose (hirossan4049) commented Oct 8, 2025 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #228782

Fixes an issue where the editor.findMatchForeground and editor.findMatchHighlightForeground color settings were swapped.

Problem

The find match foreground colors were incorrectly assigned:

  • editor.findMatchForeground (documented as “current search match”) was applied to other matches.
  • editor.findMatchHighlightForeground (documented as “other search matches”) was applied to the current match.

Solution

Swapped the CSS class selectors in findWidget.ts:

  • editor.findMatchForeground now correctly targets .currentFindMatchInline (current match)
  • editor.findMatchHighlightForeground now correctly targets .findMatchInline (other matches)

Before

Before screenshot

After

After screenshot

Test Plan

  • Set editor.findMatchForeground to a distinct color and verify it colors the current match.
  • Set editor.findMatchHighlightForeground to a distinct color and verify it colors other matches.

Copilot AI review requested due to automatic review settings October 8, 2025 15:51

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.

Pull Request Overview

This PR fixes a bug where the editor.findMatchForeground and editor.findMatchHighlightForeground color settings were incorrectly swapped in the find widget implementation. The fix ensures that the documented color semantics are properly applied to their intended elements.

  • Corrected assignment of editor.findMatchForeground to target the current search match
  • Corrected assignment of editor.findMatchHighlightForeground to target other search matches

@dmitrivMS

Copy link
Copy Markdown
Collaborator

The corrected token mapping looks right, but could we also preserve current-match precedence when changing these rules?

Both selectors have equal specificity. With this patch, .findMatchInline is emitted after .currentFindMatchInline, so the other-matches foreground wins whenever a span has both classes.

Notebook repro to verify with this PR applied

  1. Set:
    "workbench.colorCustomizations": {
        "editor.findMatchForeground": "#000000",
        "editor.findMatchHighlightForeground": "#ff0000"
    }
  2. Open a notebook with a code cell containing print("needle needle"). No execution is needed.
  3. Open the notebook Find widget, search for needle in cell input, and navigate between the matches.

Expected: the current match has black text; the other match has red text.

With the PR's rule order: the current match also resolves to red, so the foreground distinction between current and other matches is lost.

The notebook path makes the overlap concrete: setAllFindMatchesDecorations adds the ordinary decoration to every match, and highlightCurrentFindMatchDecorationInCell adds a separate current decoration without removing the ordinary one. Overlapping inline decorations combine their class names on the same text span. A similar overlap can occur with the Search view visible while using editor Find.

Suggested fix

Keep the corrected mapping, but emit the ordinary-match rule first and the current-match rule last:

const findMatchHighlightForeground = theme.getColor(editorFindMatchHighlightForeground);
if (findMatchHighlightForeground) {
	collector.addRule(`.monaco-editor .findMatchInline { color: ${findMatchHighlightForeground}; }`);
}
const findMatchForeground = theme.getColor(editorFindMatchForeground);
if (findMatchForeground) {
	collector.addRule(`.monaco-editor .currentFindMatchInline { color: ${findMatchForeground}; }`);
}

This fixes the swapped mapping while retaining the original current-class priority. Please also cover a span with both classes and distinct foreground colors in regression testing; testing the selectors separately misses this case.

Validation: I traced the decoration producers and verified the CSS cascade in Chromium: with the PR's rules, current-only is black, other-only is red, and overlapping is red; emitting the current rule last makes overlapping black. I have not run the notebook scenario end to end.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please consider feedback in the comment

@dmitrivMS Dmitriy Vasyura (dmitrivMS) changed the title Fix swapped findMatch foreground colors (#228782) editorFind: fix swapped findMatch foreground colors (#228782) Oct 5, 2026
@hirossan4049

hirose (hirossan4049) commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Good catch, fixed in 9344871.

Verified with the notebook repro that a span with both classes now resolves to findMatchForeground.

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.

🟢 Approval recommended

No active review issues were identified for the find-match foreground color mapping change.

No open issues 🎉

Review effort: Max

@dmitrivMS

Copy link
Copy Markdown
Collaborator

hirose (@hirossan4049) Thank you!

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 8010597 into microsoft:main Oct 29, 2026
51 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.145.0 milestone Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

editor-find Editor find operations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swapped findMatch Foreground Colors

6 participants