Extract link resolution into hrefAt and test image clicks#9
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 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(...)returnsnull— only text runs carry character attributes. The link-click handler's lookupgetStyleAttributeMap(...).get(HREF)therefore used to throw aNullPointerExceptionon 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:
RichTextRenderer.hrefAt(model, position)helper. It resolves the link target at a text position (ornullwhen 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.hrefAtreturnsnullwithout throwing at an inline image's position, and still resolves the target for a real link run.Steps to test
./gradlew build— the two new tests inRichTextRendererTest(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