Fix: cursor behavior when using custom builder for anchor tags#35
Fix: cursor behavior when using custom builder for anchor tags#354rthurmonteiro wants to merge 3 commits intoforesightmobile:mainfrom
Conversation
WalkthroughThe PR changes link handling to skip default link creation when a custom 'a' element builder is registered and conditions link recognizer removal on the absence of a custom 'a' builder; minor formatting and parameter-list reshapes accompany the change. (≤50 words) Changes
Sequence Diagram(s)sequenceDiagram
participant Parser
participant Builder
participant LinkRecognizer
Parser->>Builder: encounter <a> (open)
alt custom 'a' builder exists
Builder-->>Parser: build using custom 'a' (skip default link creation)
note right of Builder `#DDEBF7`: No LinkRecognizer added
else no custom 'a' builder
Builder->>LinkRecognizer: create/add link recognizer
LinkRecognizer-->>Builder: added
end
Parser->>Builder: encounter </a> (close)
alt custom 'a' builder exists
Builder-->>Parser: close custom 'a' (no link removal)
else no custom 'a' builder
Builder->>LinkRecognizer: remove last link recognizer
LinkRecognizer-->>Builder: removed
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Updated formatting.
|
@Prototypev1 Can you merge it? 1 workflow awaiting approval |
|
This has now been released in version 1.0.6 - thanks @4rthurmonteiro |
Fix cursor behavior when using custom builder for anchor tags
Problem
When a custom
MarkdownElementBuilderis provided for anchor tags ('a'), the cursor behaves incorrectly. This happens because the code was always adding and removing_linkHandlersfor anchor tags, even when a custom builder was used.The issue occurred because:
visitElementBefore, aGestureRecognizerwas always added to_linkHandlersfor anchor tags, regardless of whether a custom builder existed.visitElementAfter, the_linkHandlerswas always removed when closing anchor tags, even when a custom builder was handling the link rendering.SelectableTextor other interactive widgets.Solution
Added checks to only manage
_linkHandlerswhen there is no custom builder for anchor tags:_linkHandlerswhen!builders.containsKey('a')_linkHandlerswhen!builders.containsKey('a')This ensures that when a custom builder is provided for anchor tags, the default link handling is skipped, preventing conflicts and cursor issues.
Changes
lib/src/builder.dart: Added builder checks before adding/removing_linkHandlersfor anchor tagsTesting
Tested with custom anchor tag builders that return interactive widgets (e.g.,
SelectableText,GestureDetector). The cursor now behaves correctly in these cases.Summary by CodeRabbit
Bug Fixes
Refactor
Chores