Skip to content

Extract link resolution into hrefAt and test image clicks#9

Merged
koppor merged 1 commit into
mainfrom
image-click-regression-test
Jul 7, 2026
Merged

Extract link resolution into hrefAt and test image clicks#9
koppor merged 1 commit into
mainfrom
image-click-regression-test

Conversation

@koppor

@koppor koppor commented Jul 7, 2026

Copy link
Copy Markdown
Member

🤖 PR Description

Clicking an embedded image (e.g. the ISBN book-cover shown in JabRef's entry preview) resolves to a node segment, for which StyledTextModel.getStyleAttributeMap(...) returns null — only text runs carry character attributes. The link-click handler's lookup getStyleAttributeMap(...).get(HREF) therefore used to throw a NullPointerException on image clicks.

The inline guard added in #7 already tolerates this, so this PR does not change runtime behavior. It adds the regression coverage that was missing and makes the guard directly testable:

  • Refactor — extracts the guarded lookup into a public RichTextRenderer.hrefAt(model, position) helper. It resolves the link target at a text position (or null when there is none, including node-segment positions), so the guard is unit-testable without the JavaFX toolkit, and callers that install their own click handler get a supported resolution entry point.
  • Regression tests (headless) — hrefAt returns null without throwing at an inline image's position, and still resolves the target for a real link run.

Steps to test

  1. ./gradlew build — the two new tests in RichTextRendererTest (hrefAtImagePositionIsNullAndDoesNotThrow, hrefAtLinkPositionReturnsTarget) run headless and pass.

No visible UI change (link clicks and image clicks behave exactly as before), so no screenshot.

🤖 Generated with Claude Code

The click handler resolves a link via getStyleAttributeMap(...).get(HREF).
Node segments (embedded images, tables) have no character attributes, so
the model returns a null attribute map at their position — clicking a
book-cover image therefore lands on a null map. The inline guard added in
#7 already tolerates this; extracting it into a public
hrefAt(model, position) helper makes the guard unit-testable without the
JavaFX toolkit and gives callers that install their own click handler a
supported way to resolve the target at a position.

Adds headless regression tests: hrefAt returns null (no throw) at an
inline image's position, and still resolves the target for a real link run.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@koppor koppor merged commit 170595f into main Jul 7, 2026
2 checks passed
@koppor koppor deleted the image-click-regression-test branch July 7, 2026 23:37
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.

1 participant