Skip to content

Commit

Permalink
Solve the problem of screen appearing at critical positions when ther…
Browse files Browse the repository at this point in the history
…e is a URL in the link menu (#346)
  • Loading branch information
q200892907 authored Aug 8, 2023
1 parent 2ab0074 commit 4dd8544
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/src/editor/toolbar/desktop/items/link/link_toolbar_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ void showLinkMenu(
// the first rect(also the only rect) is used as the starting reference point for the [overlay] position
final rect = editorState.selectionRects().first;

// get link address if the selection is already a link
String? linkText;
if (isHref) {
linkText = editorState.getDeltaAttributeValueInSelection(
BuiltInAttributeKey.href,
selection,
);
}

// should abstract this logic to a method
// ----
final left = rect.left + 10;
Expand All @@ -45,7 +54,7 @@ void showLinkMenu(
final offset = rect.center;
final editorOffset = editorState.renderBox!.localToGlobal(Offset.zero);
final editorHeight = editorState.renderBox!.size.height;
final threshold = editorOffset.dy + editorHeight - 150;
final threshold = editorOffset.dy + editorHeight - (linkText != null ? 244 : 150);
if (offset.dy > threshold) {
bottom = editorOffset.dy + editorHeight - rect.top - 5;
} else {
Expand All @@ -61,14 +70,6 @@ void showLinkMenu(
final index = selection.normalized.startIndex;
final length = selection.length;

// get link address if the selection is already a link
String? linkText;
if (isHref) {
linkText = editorState.getDeltaAttributeValueInSelection(
BuiltInAttributeKey.href,
selection,
);
}
OverlayEntry? overlay;

void dismissOverlay() {
Expand Down

0 comments on commit 4dd8544

Please sign in to comment.