chore: update editor version to 1.2.3 (#3153)

This commit is contained in:
Lucas.Xu
2023-08-10 17:35:27 +07:00
committed by GitHub
parent 0c9935ccf2
commit c9ee82ec75
13 changed files with 70 additions and 13 deletions

View File

@ -0,0 +1,47 @@
import 'dart:io';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import '../util/util.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('copy and paste in document', () {
testWidgets('paste multiple lines at the first line', (tester) async {
await tester.initializeAppFlowy();
await tester.tapGoButton();
// create a new document
await tester.createNewPageWithName();
// mock the clipboard
const lines = 3;
AppFlowyClipboard.mockSetData(
AppFlowyClipboardData(
text: List.generate(lines, (index) => 'line $index').join('\n'),
),
);
// paste the text
await tester.simulateKeyEvent(
LogicalKeyboardKey.keyV,
isControlPressed: Platform.isLinux || Platform.isWindows,
isMetaPressed: Platform.isMacOS,
);
await tester.pumpAndSettle();
final editorState = tester.editor.getCurrentEditorState();
expect(editorState.document.root.children.length, 4);
for (var i = 0; i < lines; i++) {
expect(
editorState.getNodeAtPath([i])!.delta!.toPlainText(),
'line $i',
);
}
});
});
}

View File

@ -10,6 +10,7 @@ import 'document_with_inline_page_test.dart' as document_with_inline_page_test;
import 'document_with_toggle_list_test.dart' as document_with_toggle_list_test; import 'document_with_toggle_list_test.dart' as document_with_toggle_list_test;
import 'edit_document_test.dart' as document_edit_test; import 'edit_document_test.dart' as document_edit_test;
import 'document_with_outline_block_test.dart' as document_with_outline_block; import 'document_with_outline_block_test.dart' as document_with_outline_block;
import 'document_copy_and_paste_test.dart' as document_copy_and_paste_test;
void startTesting() { void startTesting() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); IntegrationTestWidgetsFlutterBinding.ensureInitialized();
@ -23,4 +24,5 @@ void startTesting() {
document_with_cover_image_test.main(); document_with_cover_image_test.main();
document_with_outline_block.main(); document_with_outline_block.main();
document_with_toggle_list_test.main(); document_with_toggle_list_test.main();
document_copy_and_paste_test.main();
} }

View File

@ -94,6 +94,13 @@ const expectedMarkdown = r'''
1. Keyboard shortcuts [guide](https://appflowy.gitbook.io/docs/essential-documentation/shortcuts) 1. Keyboard shortcuts [guide](https://appflowy.gitbook.io/docs/essential-documentation/shortcuts)
1. Markdown [reference](https://appflowy.gitbook.io/docs/essential-documentation/markdown) 1. Markdown [reference](https://appflowy.gitbook.io/docs/essential-documentation/markdown)
1. Type `/code` to insert a code block 1. Type `/code` to insert a code block
```rust
// This is the main function.
fn main() {
// Print text to the console.
println!("Hello World!");
}
```
## Have a question❓ ## Have a question❓
> Click `?` at the bottom right for help and support. > Click `?` at the bottom right for help and support.

View File

@ -87,7 +87,7 @@ class EditorOperations {
Future<void> switchSolidColorBackground() async { Future<void> switchSolidColorBackground() async {
final findPurpleButton = find.byWidgetPredicate( final findPurpleButton = find.byWidgetPredicate(
(widget) => widget is ColorItem && widget.option.colorHex == "ffe8e0ff", (widget) => widget is ColorItem && widget.option.name == 'Purple',
); );
await tester.tapButton(findPurpleButton); await tester.tapButton(findPurpleButton);
} }

View File

@ -1,5 +1,6 @@
import 'package:appflowy/plugins/document/application/document_data_pb_extension.dart'; import 'package:appflowy/plugins/document/application/document_data_pb_extension.dart';
import 'package:appflowy/plugins/document/application/doc_service.dart'; import 'package:appflowy/plugins/document/application/doc_service.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-document2/protobuf.dart'; import 'package:appflowy_backend/protobuf/flowy-document2/protobuf.dart';
import 'package:appflowy_editor/appflowy_editor.dart' import 'package:appflowy_editor/appflowy_editor.dart'
show show
@ -31,13 +32,13 @@ class TransactionAdapter {
final String documentId; final String documentId;
Future<void> apply(Transaction transaction, EditorState editorState) async { Future<void> apply(Transaction transaction, EditorState editorState) async {
// Log.debug('transaction => ${transaction.toJson()}'); Log.debug('transaction => ${transaction.toJson()}');
final actions = transaction.operations final actions = transaction.operations
.map((op) => op.toBlockAction(editorState)) .map((op) => op.toBlockAction(editorState))
.whereNotNull() .whereNotNull()
.expand((element) => element) .expand((element) => element)
.toList(growable: false); // avoid lazy evaluation .toList(growable: false); // avoid lazy evaluation
// Log.debug('actions => $actions'); Log.debug('actions => $actions');
await documentService.applyAction( await documentService.applyAction(
documentId: documentId, documentId: documentId,
actions: actions, actions: actions,
@ -72,7 +73,7 @@ extension on InsertOperation {
editorState.getNodeAtPath(path.previous)?.id ?? editorState.getNodeAtPath(path.previous)?.id ??
''; '';
assert(parentId.isNotEmpty); assert(parentId.isNotEmpty);
if (path.equals(path.previous)) { if (path.equals(path.previous) && !path.equals([0])) {
prevId = ''; prevId = '';
} else { } else {
assert(prevId.isNotEmpty && prevId != node.id); assert(prevId.isNotEmpty && prevId != node.id);

View File

@ -48,7 +48,7 @@ SelectionMenuItem calloutItem = SelectionMenuItem.node(
name: 'Callout', name: 'Callout',
iconData: Icons.note, iconData: Icons.note,
keywords: ['callout'], keywords: ['callout'],
nodeBuilder: (editorState) => calloutNode(), nodeBuilder: (editorState, _) => calloutNode(),
replace: (_, node) => node.delta?.isEmpty ?? false, replace: (_, node) => node.delta?.isEmpty ?? false,
updateSelection: (_, path, __, ___) { updateSelection: (_, path, __, ___) {
return Selection.single(path: path, startOffset: 0); return Selection.single(path: path, startOffset: 0);

View File

@ -43,7 +43,7 @@ SelectionMenuItem codeBlockItem = SelectionMenuItem.node(
name: 'Code Block', name: 'Code Block',
iconData: Icons.abc, iconData: Icons.abc,
keywords: ['code', 'codeblock'], keywords: ['code', 'codeblock'],
nodeBuilder: (editorState) => codeBlockNode(), nodeBuilder: (editorState, _) => codeBlockNode(),
replace: (_, node) => node.delta?.isEmpty ?? false, replace: (_, node) => node.delta?.isEmpty ?? false,
); );

View File

@ -37,7 +37,7 @@ SelectionMenuItem mathEquationItem = SelectionMenuItem.node(
name: 'MathEquation', name: 'MathEquation',
iconData: Icons.text_fields_rounded, iconData: Icons.text_fields_rounded,
keywords: ['tex, latex, katex', 'math equation', 'formula'], keywords: ['tex, latex, katex', 'math equation', 'formula'],
nodeBuilder: (editorState) => mathEquationNode(), nodeBuilder: (editorState, _) => mathEquationNode(),
replace: (_, node) => node.delta?.isEmpty ?? false, replace: (_, node) => node.delta?.isEmpty ?? false,
updateSelection: (editorState, path, __, ___) { updateSelection: (editorState, path, __, ___) {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) { WidgetsBinding.instance.addPostFrameCallback((timeStamp) {

View File

@ -45,7 +45,7 @@ SelectionMenuItem autoGeneratorMenuItem = SelectionMenuItem.node(
name: LocaleKeys.document_plugins_autoGeneratorMenuItemName.tr(), name: LocaleKeys.document_plugins_autoGeneratorMenuItemName.tr(),
iconData: Icons.generating_tokens, iconData: Icons.generating_tokens,
keywords: ['ai', 'openai' 'writer', 'autogenerator'], keywords: ['ai', 'openai' 'writer', 'autogenerator'],
nodeBuilder: (editorState) { nodeBuilder: (editorState, _) {
final node = autoCompletionNode(start: editorState.selection!); final node = autoCompletionNode(start: editorState.selection!);
return node; return node;
}, },

View File

@ -19,7 +19,7 @@ SelectionMenuItem outlineItem = SelectionMenuItem.node(
name: LocaleKeys.document_selectionMenu_outline.tr(), name: LocaleKeys.document_selectionMenu_outline.tr(),
iconData: Icons.list_alt, iconData: Icons.list_alt,
keywords: ['outline', 'table of contents'], keywords: ['outline', 'table of contents'],
nodeBuilder: (editorState) => outlineBlockNode(), nodeBuilder: (editorState, _) => outlineBlockNode(),
replace: (_, node) => node.delta?.isEmpty ?? false, replace: (_, node) => node.delta?.isEmpty ?? false,
); );

View File

@ -49,7 +49,7 @@ SelectionMenuItem toggleListBlockItem = SelectionMenuItem.node(
name: LocaleKeys.document_plugins_toggleList.tr(), name: LocaleKeys.document_plugins_toggleList.tr(),
iconData: Icons.arrow_right, iconData: Icons.arrow_right,
keywords: ['collapsed list', 'toggle list', 'list'], keywords: ['collapsed list', 'toggle list', 'list'],
nodeBuilder: (editorState) => toggleListBlockNode(), nodeBuilder: (editorState, _) => toggleListBlockNode(),
replace: (_, node) => node.delta?.isEmpty ?? false, replace: (_, node) => node.delta?.isEmpty ?? false,
); );

View File

@ -53,10 +53,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: appflowy_editor name: appflowy_editor
sha256: b30f645eac57639ff003e6920d04432b9c80a4e2f6e177326e81c221608d7044 sha256: "6886c32ab8c3f5385ec9eb333f3fca596fe5f5ee94da84484c7f56a322a026e7"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.2.1" version: "1.2.3"
appflowy_popover: appflowy_popover:
dependency: "direct main" dependency: "direct main"
description: description:

View File

@ -42,7 +42,7 @@ dependencies:
git: git:
url: https://github.com/AppFlowy-IO/appflowy-board.git url: https://github.com/AppFlowy-IO/appflowy-board.git
ref: a183c57 ref: a183c57
appflowy_editor: ^1.2.1 appflowy_editor: 1.2.3
appflowy_popover: appflowy_popover:
path: packages/appflowy_popover path: packages/appflowy_popover