* chore: revert "fix: word boundary regards white space as a word (#1157)"
This reverts commit a1f1c6708a.
* chore: remove test
---------
Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
This commit is contained in:
parent
cf0907738c
commit
2dbc203b14
2 changed files with 2 additions and 86 deletions
|
|
@ -277,13 +277,11 @@ class _AppFlowyRichTextState extends State<AppFlowyRichText>
|
|||
|
||||
@override
|
||||
Selection? getWordBoundaryInOffset(Offset offset) {
|
||||
final renderParagraph = _renderParagraph;
|
||||
final localOffset = _renderParagraph?.globalToLocal(offset) ?? Offset.zero;
|
||||
final textPosition = _renderParagraph?.getPositionForOffset(localOffset) ??
|
||||
const TextPosition(offset: 0);
|
||||
final textRange = renderParagraph == null
|
||||
? TextRange.empty
|
||||
: _getNonSpaceWordBoundary(renderParagraph, textPosition);
|
||||
final textRange =
|
||||
_renderParagraph?.getWordBoundary(textPosition) ?? TextRange.empty;
|
||||
final start = Position(path: widget.node.path, offset: textRange.start);
|
||||
final end = Position(path: widget.node.path, offset: textRange.end);
|
||||
return Selection(start: start, end: end);
|
||||
|
|
@ -299,56 +297,6 @@ class _AppFlowyRichTextState extends State<AppFlowyRichText>
|
|||
return Selection(start: start, end: end);
|
||||
}
|
||||
|
||||
TextRange _getNonSpaceWordBoundary(
|
||||
RenderParagraph renderParagraph,
|
||||
TextPosition textPosition,
|
||||
) {
|
||||
bool isSpace(String string) => string.trim().isEmpty;
|
||||
|
||||
final text = renderParagraph.text.toPlainText();
|
||||
final boundary = renderParagraph.getWordBoundary(textPosition);
|
||||
|
||||
if (!boundary.isValid) {
|
||||
return TextRange.empty;
|
||||
}
|
||||
|
||||
final wordText = text.substring(boundary.start, boundary.end);
|
||||
|
||||
if (!isSpace(wordText)) {
|
||||
return boundary;
|
||||
}
|
||||
|
||||
int currentOffset = boundary.start - 1;
|
||||
while (currentOffset >= 0 && isSpace(text[currentOffset])) {
|
||||
currentOffset--;
|
||||
}
|
||||
if (currentOffset >= 0) {
|
||||
final prevWordBoundary =
|
||||
renderParagraph.getWordBoundary(TextPosition(offset: currentOffset));
|
||||
if (!isSpace(
|
||||
text.substring(prevWordBoundary.start, prevWordBoundary.end),
|
||||
)) {
|
||||
return prevWordBoundary;
|
||||
}
|
||||
}
|
||||
|
||||
currentOffset = boundary.end;
|
||||
while (currentOffset < text.length && isSpace(text[currentOffset])) {
|
||||
currentOffset++;
|
||||
}
|
||||
if (currentOffset < text.length) {
|
||||
final nextWordBoundary =
|
||||
renderParagraph.getWordBoundary(TextPosition(offset: currentOffset));
|
||||
if (!isSpace(
|
||||
text.substring(nextWordBoundary.start, nextWordBoundary.end),
|
||||
)) {
|
||||
return nextWordBoundary;
|
||||
}
|
||||
}
|
||||
|
||||
return TextRange.empty;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Rect> getRectsInSelection(
|
||||
Selection selection, {
|
||||
|
|
|
|||
|
|
@ -54,38 +54,6 @@ void main() async {
|
|||
await editor.dispose();
|
||||
});
|
||||
|
||||
testWidgets('context menu cut test ', (tester) async {
|
||||
const text = 'Welcome to AppFlowy';
|
||||
final editor = tester.editor..addParagraph(initialText: text);
|
||||
await editor.startTesting();
|
||||
expect(
|
||||
find.text(text, findRichText: true),
|
||||
findsOneWidget,
|
||||
);
|
||||
await editor.updateSelection(
|
||||
Selection(
|
||||
start: Position(path: [0], offset: 0),
|
||||
end: Position(path: [0], offset: 18),
|
||||
),
|
||||
);
|
||||
final copiedText =
|
||||
editor.editorState.getTextInSelection(editor.selection).join('/n');
|
||||
final position = tester.getCenter(find.text(text, findRichText: true));
|
||||
rightClickAt(position);
|
||||
await tester.pump();
|
||||
final cutButton = find.text('Cut');
|
||||
expect(cutButton, findsOneWidget);
|
||||
await tester.tap(cutButton);
|
||||
await tester.pumpAndSettle(const Duration(milliseconds: 500));
|
||||
expect(
|
||||
find.text('Welcome to AppFlowy', findRichText: true),
|
||||
findsNothing,
|
||||
);
|
||||
final clipBoardData = await AppFlowyClipboard.getData();
|
||||
expect(clipBoardData.text, copiedText);
|
||||
await editor.dispose();
|
||||
});
|
||||
|
||||
testWidgets('context menu copy and paste test', (tester) async {
|
||||
const text = 'Welcome to AppFlowy';
|
||||
final editor = tester.editor
|
||||
|
|
|
|||
Loading…
Reference in a new issue