@@ -512,12 +512,16 @@ class LinkViewController extends PlatformViewController {
512
512
}
513
513
}
514
514
515
+ late LinkTarget _target;
516
+ String get _htmlTargetAttribute => _getHtmlTargetAttribute (_target);
517
+
515
518
/// Set the [LinkTarget] value for this link.
516
519
void setTarget (LinkTarget target) {
517
- _element.setAttribute ('target' , _getHtmlTarget (target));
520
+ _target = target;
521
+ _element.setAttribute ('target' , _htmlTargetAttribute);
518
522
}
519
523
520
- String _getHtmlTarget (LinkTarget target) {
524
+ String _getHtmlTargetAttribute (LinkTarget target) {
521
525
switch (target) {
522
526
case LinkTarget .defaultTarget:
523
527
case LinkTarget .self:
@@ -537,18 +541,30 @@ class LinkViewController extends PlatformViewController {
537
541
///
538
542
/// Returns null if [target] is not a semantics element for one of our Links.
539
543
static int ? _getViewIdFromSemanticLink (html.Element ? target) {
540
- // TODO: what if ` target` IS the <a> semantic element?
541
- if (target != null && _isWithinSemanticTree (target)) {
542
- final html. Element ? semanticLink = _getClosestSemanticLink (target);
543
- if (semanticLink != null ) {
544
- // TODO: Find out the view ID of semantic link.
545
- final String ? semanticIdentifier = semanticLink. getAttribute ( 'semantic-identifier' );
546
- if (semanticIdentifier != null ) {
547
- return _instancesBySemanticIdentifier[semanticIdentifier] ? .viewId ;
548
- }
549
- }
544
+ if ( target == null ) {
545
+ return null ;
546
+ }
547
+ if (! _isWithinSemanticTree (target) ) {
548
+ return null ;
549
+ }
550
+
551
+ final html. Element ? semanticLink = _getClosestSemanticLink (target) ;
552
+ if (semanticLink == null ) {
553
+ return null ;
550
554
}
551
- return null ;
555
+
556
+ final String ? semanticIdentifier = semanticLink.getAttribute ('semantic-identifier' );
557
+ if (semanticIdentifier == null ) {
558
+ return null ;
559
+ }
560
+
561
+ final LinkViewController ? controller = _instancesBySemanticIdentifier[semanticIdentifier];
562
+ if (controller == null ) {
563
+ return null ;
564
+ }
565
+
566
+ semanticLink.setAttribute ('target' , controller._htmlTargetAttribute);
567
+ return controller.viewId;
552
568
}
553
569
554
570
@override
0 commit comments