Repository navigation
highlight the current find match in amber in the pastel on dark theme - #19226
Conversation
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
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
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
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
#9E6A03 desaturated to 0.75 (same hue and lightness): #8D6414. Addresses #13204
RStudio E2E - all platformsAll tests passed!
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
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
left a comment
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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())) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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/); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
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).
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#2C2828background, 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.
Approach
FindReplaceadds anace_find_matchtext 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 perFindReplaceinstance and removed with the bar innotifyClosing().themeStyles.cssonly places the marker (absolute, above the selection marker atz-index: 6versus 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 inapplyFixups.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 compiledpastel_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.tsgains 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 intest: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: 6versus the debug marker's -1), and#8D6414is about 2.5:1 against the olive versus 3:1 against the plain background. Checked with abrowser()stop:Documentation
None needed.
Checklist
NEWS.md