Skip to content

Commit

Permalink
Fix wrong postion of Magnifier
Browse files Browse the repository at this point in the history
  • Loading branch information
zmtzawqlp committed Feb 19, 2024
1 parent d7741ac commit 8f960d0
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 12.0.2

* Fix wrong postion of Magnifier


## 12.0.1

* Fix issue that wrong cursor position on macos. (https://github.com/fluttercandies/extended_text_field/issues/210)
Expand Down
4 changes: 2 additions & 2 deletions lib/src/extended/material/selectable_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ExtendedSelectableText extends _SelectableText {
'Use `contextMenuBuilder` instead. '
'This feature was deprecated after v3.3.0-0.5.pre.',
)
super.toolbarOptions,
super.toolbarOptions,
super.minLines,
super.maxLines,
super.cursorWidth = 2.0,
Expand Down Expand Up @@ -57,7 +57,7 @@ class ExtendedSelectableText extends _SelectableText {
'Use `contextMenuBuilder` instead. '
'This feature was deprecated after v3.3.0-0.5.pre.',
)
super.toolbarOptions,
super.toolbarOptions,
super.minLines,
super.maxLines,
super.cursorWidth = 2.0,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/extended/widgets/editable_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ExtendedEditableText extends _EditableText {
'Use `contextMenuBuilder` instead. '
'This feature was deprecated after v3.3.0-0.5.pre.',
)
ToolbarOptions? toolbarOptions,
ToolbarOptions? toolbarOptions,
super.autofillHints = const <String>[],
super.autofillClient,
super.clipBehavior = Clip.hardEdge,
Expand Down
3 changes: 2 additions & 1 deletion lib/src/extended/widgets/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ExtendedTextField extends _TextField {
'Use `contextMenuBuilder` instead. '
'This feature was deprecated after v3.3.0-0.5.pre.',
)
super.toolbarOptions,
super.toolbarOptions,
super.showCursor,
super.autofocus = false,
super.obscuringCharacter = '•',
Expand Down Expand Up @@ -98,6 +98,7 @@ class ExtendedTextField extends _TextField {
// super.spellCheckConfiguration,
this.extendedSpellCheckConfiguration,
this.specialTextSpanBuilder,
super.magnifierConfiguration,
});

/// build your ccustom text span
Expand Down
44 changes: 41 additions & 3 deletions lib/src/extended/widgets/text_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class ExtendedTextSelectionOverlay extends _TextSelectionOverlay {
TextPosition position = renderObject.getPositionForPoint(adjustedOffset);

/// zmtzawqlp
if ((renderObject as ExtendedRenderEditable).hasSpecialInlineSpanBase) {
final bool hasSpecialInlineSpanBase =
(renderObject as ExtendedRenderEditable).hasSpecialInlineSpanBase;
if (hasSpecialInlineSpanBase) {
position =
ExtendedTextLibraryUtils.convertTextPainterPostionToTextInputPostion(
renderObject.text!, position)!;
Expand All @@ -46,6 +48,7 @@ class ExtendedTextSelectionOverlay extends _TextSelectionOverlay {
currentTextPosition: position,
globalGesturePosition: details.globalPosition,
renderEditable: renderObject,
hasSpecialInlineSpanBase: hasSpecialInlineSpanBase,
));

final TextSelection currentSelection =
Expand Down Expand Up @@ -86,6 +89,7 @@ class ExtendedTextSelectionOverlay extends _TextSelectionOverlay {
: newSelection.base,
globalGesturePosition: details.globalPosition,
renderEditable: renderObject,
hasSpecialInlineSpanBase: hasSpecialInlineSpanBase,
));

_handleSelectionHandleChanged(newSelection);
Expand All @@ -106,8 +110,10 @@ class ExtendedTextSelectionOverlay extends _TextSelectionOverlay {

TextPosition position = renderObject.getPositionForPoint(adjustedOffset);

/// zmtzawqlp
if ((renderObject as ExtendedRenderEditable).hasSpecialInlineSpanBase) {
// zmtzawqlp
final bool hasSpecialInlineSpanBase =
(renderObject as ExtendedRenderEditable).hasSpecialInlineSpanBase;
if (hasSpecialInlineSpanBase) {
position =
ExtendedTextLibraryUtils.convertTextPainterPostionToTextInputPostion(
renderObject.text!, position)!;
Expand All @@ -118,6 +124,7 @@ class ExtendedTextSelectionOverlay extends _TextSelectionOverlay {
currentTextPosition: position,
globalGesturePosition: details.globalPosition,
renderEditable: renderObject,
hasSpecialInlineSpanBase: hasSpecialInlineSpanBase,
));

final TextSelection currentSelection =
Expand Down Expand Up @@ -158,6 +165,37 @@ class ExtendedTextSelectionOverlay extends _TextSelectionOverlay {
currentTextPosition: newSelection.extent,
globalGesturePosition: details.globalPosition,
renderEditable: renderObject,
hasSpecialInlineSpanBase: hasSpecialInlineSpanBase,
));
}

@override
MagnifierInfo _buildMagnifier({
required _RenderEditable renderEditable,
required ui.Offset globalGesturePosition,
required ui.TextPosition currentTextPosition,
bool hasSpecialInlineSpanBase = false,
}) {
// zmtzawqlp
if (hasSpecialInlineSpanBase) {
currentTextPosition =
ExtendedTextLibraryUtils.convertTextInputPostionToTextPainterPostion(
renderObject.text!, currentTextPosition);
}
return super._buildMagnifier(
renderEditable: renderEditable,
globalGesturePosition: globalGesturePosition,
currentTextPosition: currentTextPosition);
}

// @override
// void _handleSelectionHandleChanged(TextSelection newSelection) {
// // zmtzawqlp
// if ((renderObject as ExtendedRenderEditable).hasSpecialInlineSpanBase) {
// newSelection = ExtendedTextLibraryUtils
// .convertTextPainterSelectionToTextInputSelection(
// renderObject.text!, newSelection);
// }
// super._handleSelectionHandleChanged(newSelection);
// }
}
4 changes: 2 additions & 2 deletions lib/src/official/material/selectable_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class _SelectableText extends StatefulWidget {
'Use `contextMenuBuilder` instead. '
'This feature was deprecated after v3.3.0-0.5.pre.',
)
this.toolbarOptions,
this.toolbarOptions,
this.minLines,
this.maxLines,
this.cursorWidth = 2.0,
Expand Down Expand Up @@ -235,7 +235,7 @@ class _SelectableText extends StatefulWidget {
'Use `contextMenuBuilder` instead. '
'This feature was deprecated after v3.3.0-0.5.pre.',
)
this.toolbarOptions,
this.toolbarOptions,
this.minLines,
this.maxLines,
this.cursorWidth = 2.0,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/official/widgets/editable_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ class _EditableText extends StatefulWidget {
'Use `contextMenuBuilder` instead. '
'This feature was deprecated after v3.3.0-0.5.pre.',
)
ToolbarOptions? toolbarOptions,
ToolbarOptions? toolbarOptions,
this.autofillHints = const <String>[],
this.autofillClient,
this.clipBehavior = Clip.hardEdge,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/official/widgets/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class _TextField extends StatefulWidget {
'Use `contextMenuBuilder` instead. '
'This feature was deprecated after v3.3.0-0.5.pre.',
)
this.toolbarOptions,
this.toolbarOptions,
this.showCursor,
this.autofocus = false,
this.obscuringCharacter = '•',
Expand Down
4 changes: 2 additions & 2 deletions lib/src/official/widgets/text_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ class _SelectionOverlay {
'Use `contextMenuBuilder` in `showToolbar` instead. '
'This feature was deprecated after v3.3.0-0.5.pre.',
)
required this.selectionDelegate,
required this.selectionDelegate,
required this.clipboardStatus,
required this.startHandleLayerLink,
required this.endHandleLayerLink,
Expand All @@ -691,7 +691,7 @@ class _SelectionOverlay {
'Use `contextMenuBuilder` in `showToolbar` instead. '
'This feature was deprecated after v3.3.0-0.5.pre.',
)
Offset? toolbarLocation,
Offset? toolbarLocation,
this.magnifierConfiguration = TextMagnifierConfiguration.disabled,
}) : _startHandleType = startHandleType,
_lineHeightAtStart = lineHeightAtStart,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: extended_text_field
description: Extended official text field to build special text like inline image, @somebody, custom background etc quickly.It also support to build custom seleciton toolbar and handles.
version: 12.0.1
version: 12.0.2
homepage: https://github.com/fluttercandies/extended_text_field

environment:
Expand Down

0 comments on commit 8f960d0

Please sign in to comment.