Skip to content

Commit 0a14702

Browse files
committed
apply review
1 parent f2bc837 commit 0a14702

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

site/lib/src/components/common/client/api_link_tooltip.dart

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,19 @@ class _InteractiveApiLinkState extends State<ApiLinkTooltip> {
7171
void ensureVisible() {
7272
final tooltip = tooltipKey.currentNode;
7373
if (tooltip == null) return;
74-
final containerRect = tooltip.closest('.content')!.getBoundingClientRect();
74+
7575
final tooltipRect = tooltip.getBoundingClientRect();
76+
final containerRect = tooltip.closest('.content')?.getBoundingClientRect();
7677

7778
final tooltipLeft = tooltipRect.left - tooltipOffset;
7879
final tooltipRight = tooltipRect.right - tooltipOffset;
80+
final containerLeft = containerRect?.left ?? 0.0;
81+
final containerRight = containerRect?.right ?? web.window.innerWidth;
7982

80-
if (tooltipLeft < containerRect.left) {
81-
setState(() => tooltipOffset = containerRect.left - tooltipLeft);
82-
} else if (tooltipRight > containerRect.right) {
83-
setState(() => tooltipOffset = containerRect.right - tooltipRight);
83+
if (tooltipLeft < containerLeft) {
84+
setState(() => tooltipOffset = containerLeft - tooltipLeft);
85+
} else if (tooltipRight > containerRight) {
86+
setState(() => tooltipOffset = containerRight - tooltipRight);
8487
} else {
8588
setState(() => tooltipOffset = 0.0);
8689
}
@@ -130,8 +133,10 @@ class _InteractiveApiLinkState extends State<ApiLinkTooltip> {
130133
events: {
131134
if (isTouchscreen)
132135
'click': (event) {
133-
setState(() => isVisible = !isVisible);
134-
event.preventDefault();
136+
if (!isVisible) {
137+
setState(() => isVisible = true);
138+
event.preventDefault();
139+
}
135140
},
136141
},
137142
[
@@ -154,9 +159,14 @@ Future<(String?, String?)> scrapeApiDocs(String url) async {
154159
final response = await http.get(Uri.parse(url));
155160
var content = response.body;
156161

157-
content = content.substring(
158-
content.indexOf(RegExp('<div\\s+id="$contentId"')),
159-
);
162+
final startIndex = content.indexOf(RegExp('<div\\s+id="$contentId"'));
163+
if (startIndex == -1) {
164+
print(
165+
'Error fetching API docs for $url: content id "$contentId" not found.',
166+
);
167+
return (null, null);
168+
}
169+
content = content.substring(startIndex);
160170

161171
final element =
162172
web.document.createElement('template') as web.HTMLTemplateElement;

0 commit comments

Comments
 (0)