Skip to content

Commit e5e7623

Browse files
committed
Fix _handleSelectWord error
1 parent f7be8f8 commit e5e7623

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

lib/src/extended/selection_mixin.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,35 @@ class _ExtendedSelectableFragment extends _SelectableFragment {
172172
_textSelectionStart = position;
173173
}
174174
}
175+
176+
@override
177+
SelectionResult _handleSelectWord(Offset globalPosition) {
178+
final TextPosition position =
179+
paragraph.getPositionForOffset(paragraph.globalToLocal(globalPosition));
180+
if (_positionIsWithinCurrentSelection(position)) {
181+
return SelectionResult.end;
182+
}
183+
final TextRange word = paragraph.getWordBoundary(position);
184+
assert(word.isNormalized);
185+
186+
// zmtzawqlp
187+
// https://github.com/flutter/flutter/issues/127076
188+
if (!(word.start >= range.start && word.end <= range.end)) {
189+
return SelectionResult.none;
190+
}
191+
// Fragments are separated by placeholder span, the word boundary shouldn't
192+
// expand across fragments.
193+
// assert(word.start >= range.start && word.end <= range.end);
194+
late TextPosition start;
195+
late TextPosition end;
196+
if (position.offset >= word.end) {
197+
start = end = TextPosition(offset: position.offset);
198+
} else {
199+
start = TextPosition(offset: word.start);
200+
end = TextPosition(offset: word.end, affinity: TextAffinity.upstream);
201+
}
202+
_textSelectionStart = start;
203+
_textSelectionEnd = end;
204+
return SelectionResult.end;
205+
}
175206
}

pubspec.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
name: extended_text
22
description: Extended official text to build special text like inline image or @somebody quickly,it also support custom background,custom over flow and custom selection toolbar and handles.
3-
version: 11.0.0-dev
3+
version: 11.0.0-dev.1
44
homepage: https://github.com/fluttercandies/extended_text
55

66
environment:
77
sdk: '>=2.17.0 <4.0.0'
88
flutter: ">=3.10.0"
99

1010
dependencies:
11-
extended_text_library: ^11.0.0-dev
11+
extended_text_library: ^11.0.0-dev.1
12+
# version: ^11.0.0-dev.1
13+
# hosted: "https://pub.dev"
1214
flutter:
1315
sdk: flutter
1416
dependency_overrides:
15-
# extended_text_library:
17+
#extended_text_library:
1618
# git:
1719
# url: https://github.com/fluttercandies/extended_text_library.git
1820
# ref: refactor
19-
# path: ../extended_text_library
21+
#path: ../extended_text_library
2022

2123
dev_dependencies:
2224
flutter_test:

0 commit comments

Comments
 (0)