chore: integrate delete line command into cut command (#907)
This commit is contained in:
parent
54edcadbb2
commit
c5de9ed84d
2 changed files with 84 additions and 125 deletions
|
|
@ -1,19 +1,46 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../../infra/testable_editor.dart';
|
||||
import '../../../util/util.dart';
|
||||
|
||||
void main() async {
|
||||
setUpAll(() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
});
|
||||
group('cut_command_test.dart', () {
|
||||
const text = 'Welcome to AppFlowy Editor 🔥!';
|
||||
|
||||
testWidgets('update selection and execute cut command', (tester) async {
|
||||
await _testCutHandle(tester, Document.fromJson(paragraphdata));
|
||||
});
|
||||
|
||||
test('cut current line if the selection is collapsed', () async {
|
||||
final document = Document.blank().addParagraphs(
|
||||
2,
|
||||
builder: (index) => Delta()..insert('${index + 1}. $text'),
|
||||
);
|
||||
final editorState = EditorState(document: document);
|
||||
|
||||
final selection = Selection.collapsed(
|
||||
Position(path: [0], offset: text.length),
|
||||
);
|
||||
editorState.selection = selection;
|
||||
|
||||
final result = cutCommand.execute(editorState);
|
||||
expect(result, KeyEventResult.handled);
|
||||
|
||||
// check the clipboard
|
||||
final lastText = AppFlowyClipboard.lastText!;
|
||||
expect(lastText, '1. $text');
|
||||
|
||||
final after = editorState.getNodeAtPath([0])!;
|
||||
expect(after.delta!.toPlainText(), '2. $text');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../../util/util.dart';
|
||||
|
||||
void main() async {
|
||||
group('deleteLineCommand', () {
|
||||
group('delete current line if the selection is collapsed', () {
|
||||
const text = 'Welcome to AppFlowy Editor 🔥!';
|
||||
|
||||
test('delete in collapsed selection when the index > 0', () async {
|
||||
final document = Document.blank().addParagraphs(
|
||||
2,
|
||||
builder: (index) => Delta()..insert('${index + 1}. $text'),
|
||||
);
|
||||
final editorState = EditorState(document: document);
|
||||
|
||||
final selection = Selection.collapsed(
|
||||
Position(path: [0], offset: text.length),
|
||||
);
|
||||
editorState.selection = selection;
|
||||
|
||||
final result = deleteLineCommand.execute(editorState);
|
||||
expect(result, KeyEventResult.handled);
|
||||
|
||||
final after = editorState.getNodeAtPath([0])!;
|
||||
expect(after.delta!.toPlainText(), '2. $text');
|
||||
});
|
||||
|
||||
test('do nothing if the selection is not collapsed', () async {
|
||||
final document = Document.blank().addParagraphs(
|
||||
2,
|
||||
builder: (index) => Delta()..insert('${index + 1}. $text'),
|
||||
);
|
||||
final editorState = EditorState(document: document);
|
||||
|
||||
final selection = Selection(
|
||||
start: Position(path: [0], offset: 0),
|
||||
end: Position(path: [0], offset: text.length),
|
||||
);
|
||||
editorState.selection = selection;
|
||||
|
||||
final result = deleteLineCommand.execute(editorState);
|
||||
expect(result, KeyEventResult.ignored);
|
||||
|
||||
expect(
|
||||
editorState.getNodeAtPath([0])!.delta!.toPlainText(),
|
||||
'1. $text',
|
||||
);
|
||||
expect(
|
||||
editorState.getNodeAtPath([1])!.delta!.toPlainText(),
|
||||
'2. $text',
|
||||
);
|
||||
expect(editorState.selection, selection);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue