Skip to content

highlight the current find match in amber in the pastel on dark theme - #19226

Merged
kevinushey merged 11 commits into
mainfrom
bugfix/13204-pastel-on-dark-find-highlight
Oct 23, 2026
Merged

kevinushey merged 11 commits into
mainfrom
bugfix/13204-pastel-on-dark-find-highlight

Conversation

@kevinushey

@kevinushey kevinushey commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Intent

Fixes #13204.

The latest report on that issue (a screenshot from RStudio 2026.08.1 with the Pastel On Dark theme) is not the Help pane's "Find in topic" that the 2024 fix (#14930) addressed: it shows the source editor's Find bar, where the current match was simply the editor selection. Pastel On Dark's selection colour is rgba(221, 240, 255, 0.20), about 1.8:1 against its #2C2828 background, so a short match is very easy to miss.

In Pastel On Dark, the current Find match now gets its own amber highlight. No other theme changes.

Before and after: Find for "dep" in Pastel On Dark (changed) and Twilight (unchanged)

Approach

FindReplace adds an ace_find_match text marker over the match it just revealed. The marker follows the find selection: it is replaced on the next find, and dropped as soon as the editor selection no longer equals the match (a click or cursor move elsewhere), the document changes (a replace or an edit), or the find bar closes. "Replace" and "Replace All" therefore clear it through the document change and the next find re-adds it, and "Select All" clears it through the selection change. The handlers are registered per FindReplace instance and removed with the bar in notifyClosing().

themeStyles.css only places the marker (absolute, above the selection marker at z-index: 6 versus Ace's 5) and gives it no colour, so it is invisible in every theme that does not colour it; without that base rule an unstyled marker sits in normal flow at the layer's origin, which the e2e geometry check caught. Pastel On Dark colours it: a new fixup in applyFixups.pastel_on_dark (src/gwt/tools/compile-themes.R) appends an .ace_marker-layer .ace_find_match { background-color: #8D6414 } rule, and the same rule is appended to the compiled pastel_on_dark.rstheme, so the committed theme matches what a regeneration would produce. Any other theme (bundled or custom) can opt in the same way.

For the record, the editor selection in most of the bundled dark themes is similarly faint (Clouds Midnight 1.2:1, Solarized Dark 1.3, Material 1.4, Tomorrow Night 1.5, Dracula 1.6, Monokai 1.6, Twilight 1.8, Merbivore 1.9), which is why the other reports on the thread name Twilight, Merbivore, and Dracula. Two broader revisions of this PR (a fixed amber for every theme, and a colour derived from each theme's selection by shifting its lightness in CIE Lab) were tried and reverted in favour of scoping the change to the theme in the report; they are in the branch history if wanted later.

Automated Tests

editor.test.ts gains a test that opens the Find bar, types a term, and checks that the marker appears over exactly the selection's box; that moving the cursor removes it and Find Next brings it back; that closing the bar removes the marker while leaving the selection in place; and that the served Pastel On Dark stylesheet carries the amber rule. Passes locally in test:server-dev, together with the two existing Find tests in that file.

QA Notes

Switch to Pastel On Dark, open any R file, press Cmd+F / Ctrl+F and type a short word: the current match is highlighted in amber as you type and as you step through matches with Enter / Shift+Enter. Click into the editor: the highlight goes away and the selection colour is back to normal. Also worth checking "In selection", Replace, and Replace All there, and that another theme (e.g. Twilight or TextMate) looks exactly as before.

The match stays visible on the active debug line, whose highlight in dark themes is a nearby olive (rgb(54, 50, 8)): the marker draws above it (z-index: 6 versus the debug marker's -1), and #8D6414 is about 2.5:1 against the olive versus 3:1 against the plain background. Checked with a browser() stop:

Find match on the active debug line in Pastel On Dark

Documentation

None needed.

Checklist

  • If this PR adds a new feature, or fixes a bug in a previously released version, it includes an entry in NEWS.md
  • If this PR adds or changes UI, the updated UI meets accessibility standards
  • A reviewer is assigned to this PR (if unsure who to assign, check Area Owners list)
  • This PR passes all local unit tests

The theme's selection colour, rgba(221, 240, 255, 0.20), composites to
about 1.8:1 against the #2C2828 editor background, so the current Find
match (which is just the editor selection) is easy to miss. Raise the
alpha to 0.40 (about 3.3:1) for both the selection and the selected-word
border, in the compile-themes fixup and the compiled theme.

Addresses #13204
@kevinushey kevinushey added this to the 2026.11 (Montauk Daisy) milestone Oct 22, 2026
The Find bar selected its match and left the theme's selection colour to
show it, which in Pastel On Dark, Twilight, Merbivore and several other
dark themes is too faint to pick a short match out by. Add an
"ace_find_match" marker over the current match (amber on dark themes,
yellow on light ones) that follows the find selection and clears when the
selection or document changes or the bar closes.

This replaces the earlier Pastel On Dark selection alpha change, which
also made strings inside an ordinary selection harder to read.

Addresses #13204
@kevinushey kevinushey changed the title make the selection highlight more visible in the pastel on dark theme highlight the current find match independently of the editor theme Oct 22, 2026
Replace the fixed amber/yellow with the theme's selection colour moved
in lightness only: FindMatchHighlight samples the editor background,
foreground and selection colour when a theme stylesheet loads, and
ColorUtil.separateFromBackground shifts L* in CIE Lab until the colour
is a CIE76 distance of 35 from the background, keeping hue and chroma
and never passing the lightness midway to the foreground. The result
is published as --rstudio-find-match-background and read by the marker
rule (through literal(), as the CssResource compiler drops var()).

Addresses #13204
@kevinushey kevinushey changed the title highlight the current find match independently of the editor theme highlight the current find match in a lighter shade of the theme's selection colour Oct 22, 2026
Drop the theme-derived colour (FindMatchHighlight, the Lab helpers in
ColorUtil and the themeStyles rules) and style the ace_find_match marker
from the Pastel On Dark theme alone, via a compile-themes fixup mirrored
into the compiled theme. Other themes keep their current look.

Addresses #13204
An unstyled marker sits in normal flow at the marker layer's origin, so
give ace_find_match its geometry (absolute, above the selection marker)
in themeStyles.css with no colour, and leave Pastel On Dark to supply
only the background colour.

Addresses #13204
@kevinushey kevinushey changed the title highlight the current find match in a lighter shade of the theme's selection colour highlight the current find match in amber in the pastel on dark theme Oct 22, 2026
#9E6A03 desaturated to 0.75 (same hue and lightness): #8D6414.

Addresses #13204
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
4110 0 214 2
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 14 0
✅ desktop-linux 1028 0 42 0
✅ desktop-macos 1033 0 37 1
✅ desktop-windows 1027 0 49 0
✅ server-linux 984 0 44 1
✅ setup 36 0 28 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit 92fc7dcef8c1f821b73b7cd7818faeea4cec45ce - Run #1655

On desktop, rsession rejects requests without the shared-secret header
that Electron adds to the renderer's requests. Playwright's page.request
bypasses the renderer, so the theme fetch came back 403 with an empty
body and the test failed on macOS and Windows.

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two things to fix before this goes in: matched text is harder to read on the amber than on the old selection, and Select All can leave the highlight on. The rest are smaller.

".ace_marker-layer .ace_find_match {",
" background-color: %s;",
"}",
replace = "#8D6414"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The amber marker is opaque and sits under the matched text, so the match is easier to spot but harder to read. WCAG contrast of Pastel On Dark tokens, old selection (blended rgb(79, 80, 83)) → #8D6414:

Token Old selection Amber
keyword #757AD8 2.12 1.39
string #66A968 2.86 1.88
TRUE/FALSE #DE8E30 3.08 2.02
numeric #CCCCCC 5.02 3.30
plain text #EAEAEA 6.70 4.40

Searching for function or if leaves the match at 1.39:1, and plain text drops below AA's 4.5:1. The contrast numbers in the PR body compare the amber to the background, not to the text drawn on it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, and the numbers reproduce. Any fill bright enough to spot pushes the keyword colour under 1.4:1, so 0238c12 keeps the amber for a 1px outline and fills at 45% alpha: plain text 5.6:1, keyword 1.8:1, above the stock selection on every token except plain text, while the outline still marks the match at 2.75:1 against the background.

// the selection or the document moves on for any other reason
matchHandlers_.add(editor_.addSelectionChangedHandler(event ->
{
if (matchRange_ != null && !matchRange_.isEqualTo(editor_.getSelectionRange()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Select All doesn't clear the marker when the current match is the first occurrence. Ace's findAll calls toSingleRange(ranges[0]) and then addRange(r, true) for the rest; the blocked addRange never calls fromOrientedRange, and $onAddRange/$onMultiSelect emit no changeSelection. So the one changeSelection that does fire sees a primary range equal to matchRange_, and the marker stays.

Reproduced with the repo's ace-uncompressed.js and this handler logic on alpha beta\nalpha gamma\nalpha delta: current match = 1st alpha → Select All gives 3 selections and the amber stays on the first. Current match = 2nd alpha → cleared as expected.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Right, toSingleRange(ranges[0]) is the only selection change that fires. 61df0cc clears the marker explicitly before findAll, and the e2e test now covers Select All with the current match as the first occurrence (it fails without the fix).

termBgLine <- grep(".xtermInvertBgColor( *){", content, perl = TRUE)
content[termBgLine] <- paste0(".xtermInvertBgColor { background-color: #EAEAEA; }")

# Find's current match is the editor selection, which this theme draws too

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The defect is this theme's faint .ace_selection, and applyFixups.pastel_on_dark already overrides colours with .rs.updateSetting (ace_find_line, ace_foreign_line, ...). The first commit on this branch (910cf50) did the selection override in a few lines, with no Java and covering non-Find selections too. The trade-off is that it recolours every selection in the theme. If the marker approach stays, every Find in every theme adds an invisible marker and checks selection equality on each cursor move while the bar is open. Did you consider going back to the selection override?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I did consider it; that was the first commit. Two reasons for the marker: the alpha-0.40 selection override scores worse on the text-contrast point above (keyword 1.17:1, plain text 3.7:1), and recolouring every selection changes more than the match. With a marker the theme can use an outline, which keeps the matched text readable. The per-find cost is one marker plus one range comparison per selection change while the bar is open.

throw new Error(`${url}: HTTP ${response.status}`);
return response.text();
}, pastelUrl.toString());
expect(pastelCss).toMatch(/\.ace_marker-layer \.ace_find_match \{[^}]*background-color: #8D6414/);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This checks the rule text in the stylesheet but never applies Pastel On Dark, so it doesn't show the marker is drawn amber. If the rule loses the cascade in the live page, the test still passes. Checking getComputedStyle(marker).backgroundColor with the theme active would cover the visible effect.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

8be8f8c applies Pastel On Dark in the session (.rs.api.applyTheme, restored in a finally) and asserts the marker's computed colours, so the stylesheet fetch is gone. It also covers the Select All case from the other thread.

// the shared-secret header Electron adds to the renderer's requests, which
// page.request does not carry.
const pastelUrl = new URL(await getThemeStylesheetHref(page), page.url());
pastelUrl.pathname = pastelUrl.pathname.replace(/[^/]+\.rstheme$/, 'pastel_on_dark.rstheme');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor: this assumes the active theme is served from theme/default/. Custom themes come from theme/custom/global/ or theme/custom/local/ (SessionThemes.cpp), so with one active this becomes a 404. Unlikely with the dev server's default Textmate, but building the path from theme/default/ directly would avoid it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Gone with 8be8f8c; the test no longer fetches the stylesheet at all.

targetSelection_ = null;
}

// Mark the current match independently of the theme's selection colour,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: this reads as if several dark themes get a visible match highlight, but only Pastel On Dark colours .ace_find_match; in every other theme the marker is invisible.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reworded in 61df0cc.

Ace's findAll makes the first match the primary selection and adds the
rest without firing a selection change, so when the current match was
that first occurrence the selection handler saw an unchanged range and
left the marker on. Clear it explicitly before selecting all matches.
Also say in the highlightMatch comment that only themes styling
ace_find_match show the marker, which today is Pastel On Dark alone.
Apply the theme in the session and assert the marker's computed
background instead of fetching the stylesheet and matching its text,
which also drops the assumption that the active theme is served from
theme/default/. Cover Select All with the current match as the first
occurrence, and close the test's file in afterEach like the others.
An opaque amber under the matched text left Pastel On Dark's keyword
colour at 1.4:1 and its plain text under 4.5:1 against it. Keep the
amber for a 1px outline, which is what makes the match easy to spot,
and fill at 45% alpha so the text keeps its contrast (plain text 5.6:1,
keyword 1.8:1, both above the theme's stock selection on every token
except plain text).
@kevinushey
kevinushey merged commit 83d7a34 into main Oct 23, 2026
1 of 6 checks passed
@kevinushey
kevinushey deleted the bugfix/13204-pastel-on-dark-find-highlight branch October 23, 2026 19:15
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.

Better highlighting of the "find in topic" search results

2 participants