Skip to content

Caret contrasts with the page colour, shading or highlight under it (#299) - #1137

Merged
echelon merged 4 commits into
storytold:mainfrom
dkhlapov:issue-299-caret-contrast
Oct 14, 2026
Merged

echelon merged 4 commits into
storytold:mainfrom
dkhlapov:issue-299-caret-contrast

Conversation

@dkhlapov

@dkhlapov dkhlapov commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

#299: the caret contrasts with what lies under it

Fixes #299. The caret is now black or white, whichever contrasts more with what lies under it: the paper, the page colour, a dark page, shading or a highlight. This is similar to Word's inverted caret. Before, it was always black (white only on Switch Modes' dark page), so it disappeared on dark page colours, shading and highlights. The equation caret and IME preedit text use the same rule.

What changed:

  • wordcraft_render::background_at returns the on-screen colour behind a page point. It works from the page's draw list, blended in drawing order.
  • canvas::caret_contrast picks the caret colour. The result is cached per layout, view, page and point, so the blink doesn't rebuild the page.

Tests:

  • render::tests::background_at_caret_follows_page_colour_highlight_and_dark_mode
  • canvas::tests::caret_contrasts_with_what_lies_under_it
  • cargo xtask ci passes.

Limitations: pictures behind text and rotated content aren't considered; the caret falls back to the paper colour there. The mouse I-beam is the OS cursor and is unchanged.

🤖 Generated with Claude Code

…r highlight under it

The caret was black (white only in Switch Modes' dark page), so it vanished
on a dark page colour, dark shading or a dark highlight. It now takes black
or white by WCAG contrast with the background at the caret
(wordcraft_render::background_at), cached per layout/view/position.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dkhlapov
dkhlapov force-pushed the issue-299-caret-contrast branch from 242cd61 to c679c06 Compare October 12, 2026 23:36
@dkhlapov dkhlapov changed the title WIP: Cursor corlor not changin, is not visible. PDF EDITOR and WORDCRAFT // no languaje changes (#299) Caret contrasts with the page colour, shading or highlight under it (#299) Oct 12, 2026
@dkhlapov
dkhlapov marked this pull request as ready for review October 12, 2026 23:36
dkhlapov and others added 2 commits October 13, 2026 14:06
… outline; look up only when drawn

background_at hit-tests a filled shape's real outline (shape_path), so an ellipse's corner
shows what lies beneath. The caret's colour is worked out only when the caret (or IME text)
is drawn, and the unused Tokens::caret is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dkhlapov

Copy link
Copy Markdown
Contributor Author

Review follow-ups (d64327e):

  • Shapes count only inside their outline: a filled shape now counts only inside its real outline, so the caret near an ellipse's corner uses the colour behind the shape. Shape fills are fully opaque in the model and on screen, so treating them as opaque is right. Test: background_follows_a_shapes_outline_not_its_box.
  • Only when the caret is drawn: the caret colour is worked out only then, not during a selection. Test: caret_colour_is_not_worked_out_while_the_caret_is_hidden.
  • Cleanup: removed the unused Tokens::caret.

Full CI passed.

# Conflicts:
#	ROADMAP.md
#	docs/ui-parity.md
@echelon
echelon merged commit 9fd3490 into storytold:main Oct 14, 2026
3 checks passed
@echelon

echelon commented Oct 14, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution, @dkhlapov! This has landed in main. If you haven't already, come join us on Discord: https://discord.gg/artcraft

@dkhlapov
dkhlapov deleted the issue-299-caret-contrast branch October 15, 2026 19:27
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.

Cursor corlor not changin, is not visible. PDF EDITOR and WORDCRAFT // no languaje changes

2 participants