|
@@ -158,6 +158,7 @@ ToolbarShowValidator _showInTextSelection = (editorState) {
|
|
|
|
|
|
OverlayEntry? _linkMenuOverlay;
|
|
OverlayEntry? _linkMenuOverlay;
|
|
EditorState? _editorState;
|
|
EditorState? _editorState;
|
|
|
|
+bool _changeSelectionInner = false;
|
|
void showLinkMenu(
|
|
void showLinkMenu(
|
|
BuildContext context,
|
|
BuildContext context,
|
|
EditorState editorState, {
|
|
EditorState editorState, {
|
|
@@ -180,17 +181,17 @@ void showLinkMenu(
|
|
// We get the text node directly instead of judging details again.
|
|
// We get the text node directly instead of judging details again.
|
|
final selection = customSelection ??
|
|
final selection = customSelection ??
|
|
editorState.service.selectionService.currentSelection.value;
|
|
editorState.service.selectionService.currentSelection.value;
|
|
- if (selection == null) {
|
|
|
|
|
|
+ final node = editorState.service.selectionService.currentSelectedNodes;
|
|
|
|
+ if (selection == null || node.isEmpty || node.first is! TextNode) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
final index =
|
|
final index =
|
|
selection.isBackward ? selection.start.offset : selection.end.offset;
|
|
selection.isBackward ? selection.start.offset : selection.end.offset;
|
|
final length = (selection.start.offset - selection.end.offset).abs();
|
|
final length = (selection.start.offset - selection.end.offset).abs();
|
|
- final node = editorState.service.selectionService.currentSelectedNodes.first
|
|
|
|
- as TextNode;
|
|
|
|
|
|
+ final textNode = node.first as TextNode;
|
|
String? linkText;
|
|
String? linkText;
|
|
- if (node.allSatisfyLinkInSelection(selection)) {
|
|
|
|
- linkText = node.getAttributeInSelection(selection, StyleKey.href);
|
|
|
|
|
|
+ if (textNode.allSatisfyLinkInSelection(selection)) {
|
|
|
|
+ linkText = textNode.getAttributeInSelection(selection, StyleKey.href);
|
|
}
|
|
}
|
|
_linkMenuOverlay = OverlayEntry(builder: (context) {
|
|
_linkMenuOverlay = OverlayEntry(builder: (context) {
|
|
return Positioned(
|
|
return Positioned(
|
|
@@ -204,7 +205,7 @@ void showLinkMenu(
|
|
},
|
|
},
|
|
onSubmitted: (text) {
|
|
onSubmitted: (text) {
|
|
TransactionBuilder(editorState)
|
|
TransactionBuilder(editorState)
|
|
- ..formatText(node, index, length, {StyleKey.href: text})
|
|
|
|
|
|
+ ..formatText(textNode, index, length, {StyleKey.href: text})
|
|
..commit();
|
|
..commit();
|
|
_dismissLinkMenu();
|
|
_dismissLinkMenu();
|
|
},
|
|
},
|
|
@@ -214,10 +215,17 @@ void showLinkMenu(
|
|
},
|
|
},
|
|
onRemoveLink: () {
|
|
onRemoveLink: () {
|
|
TransactionBuilder(editorState)
|
|
TransactionBuilder(editorState)
|
|
- ..formatText(node, index, length, {StyleKey.href: null})
|
|
|
|
|
|
+ ..formatText(textNode, index, length, {StyleKey.href: null})
|
|
..commit();
|
|
..commit();
|
|
_dismissLinkMenu();
|
|
_dismissLinkMenu();
|
|
},
|
|
},
|
|
|
|
+ onFocusChange: (value) {
|
|
|
|
+ if (value && customSelection != null) {
|
|
|
|
+ _changeSelectionInner = true;
|
|
|
|
+ editorState.service.selectionService
|
|
|
|
+ .updateSelection(customSelection);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
);
|
|
@@ -230,6 +238,13 @@ void showLinkMenu(
|
|
}
|
|
}
|
|
|
|
|
|
void _dismissLinkMenu() {
|
|
void _dismissLinkMenu() {
|
|
|
|
+ if (_editorState?.service.selectionService.currentSelection.value == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (_changeSelectionInner) {
|
|
|
|
+ _changeSelectionInner = false;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
_linkMenuOverlay?.remove();
|
|
_linkMenuOverlay?.remove();
|
|
_linkMenuOverlay = null;
|
|
_linkMenuOverlay = null;
|
|
|
|
|