Skip to content

Show the hand cursor when hovering links (RichTextArea renderer)#8

Merged
koppor merged 1 commit into
mainfrom
fix-link-cursor
Jul 7, 2026
Merged

Show the hand cursor when hovering links (RichTextArea renderer)#8
koppor merged 1 commit into
mainfrom
fix-link-cursor

Conversation

@koppor

@koppor koppor commented Jul 7, 2026

Copy link
Copy Markdown
Member

🤖 PR Description

Problem

Fixes #5.

In the RichTextArea-based renderer (RichHtmlView / RichTextRenderer), hovering a link shows the default text (I-beam) cursor, so a link looks no different from ordinary selectable text. The TextFlow-based FxRenderer already sets Cursor.HAND on its link runs, so the two renderers were inconsistent.

RichTextArea (JavaFX incubator) has no built-in concept of a link cursor — confirmed by the control's author on openjdk/jfx#2196 (comment), who recommended reacting to a custom character StyleAttribute via the control's style-handler registry.

Fix

New rich/HtmlRichTextArea subclass overriding getStyleHandlerRegistry() to return the control's default registry extended with a segment handler for the existing custom HREF attribute. The handler appends -fx-cursor: hand to the run's node through the CellContext — the same mechanism the built-in bold/italic/underline/color handlers use.

  • StyleHandlerRegistry.builder(RichTextArea.styleHandlerRegistry) seeds the new registry with all of the control's default handlers, so bold/italic/color/… keep working.
  • The skin iterates every attribute on a segment (including custom ones) and calls registry.process(...), so HREF reliably reaches the handler.
  • The skin replaces each segment node's whole inline style on every layout, so a recycled node reused for a non-link run does not keep a stale hand cursor — no manual cleanup needed.

Wired into the two construction sites: RichTextRenderer.render(...) and RichHtmlView.

Testing

  • ./gradlew build (headless) — green.
  • xvfb-run ./gradlew guiTest — green, including the new HtmlRichTextAreaTest, which drives the same StyleHandlerRegistry.process(...) path the skin uses and asserts that a link run requests -fx-cursor:hand, that inherited handlers (bold) still apply, and that a non-link run does not get the hand cursor.

To see it manually: render any HTML containing an <a href> into a RichHtmlView and hover the link — the pointer becomes a hand. (No cursor-on-hover screenshot is attached because screen capture omits the OS cursor.)

🤖 Generated with Claude Code

RichTextArea gives every text segment the default I-beam cursor, so links
were indistinguishable from ordinary selectable text on hover — unlike
FxRenderer, whose link runs already carry Cursor.HAND.

The control has no built-in link support, but its rendering is driven by an
overridable StyleHandlerRegistry. HtmlRichTextArea overrides
getStyleHandlerRegistry() to extend the control's default registry with a
segment handler for the custom HREF attribute that appends `-fx-cursor: hand`
through the CellContext — the same mechanism the built-in bold/italic/color
handlers use. Because the skin replaces each segment node's inline style on
every layout, a recycled node reused for a non-link run does not keep a stale
hand cursor.

Wired into RichTextRenderer.render and RichHtmlView; covered by a gui-tagged
test that drives the same StyleHandlerRegistry.process path the skin uses.

Fixes #5

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@koppor koppor merged commit 350248f into main Jul 7, 2026
2 checks passed
@koppor koppor deleted the fix-link-cursor branch July 7, 2026 22:58
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.

Mouse hover on links should change from text cursor to link cursor

1 participant