fix: bulleted list format error
This commit is contained in:
parent
6473be7c68
commit
8bc0b8be99
7 changed files with 78 additions and 21 deletions
|
|
@ -1,10 +1,6 @@
|
|||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:appflowy_editor/src/core/document/attributes.dart';
|
||||
import 'package:appflowy_editor/src/core/document/node.dart';
|
||||
import 'package:appflowy_editor/src/core/document/path.dart';
|
||||
import 'package:appflowy_editor/src/core/document/text_delta.dart';
|
||||
|
||||
/// [Operation] represents a change to a [Document].
|
||||
abstract class Operation {
|
||||
Operation(
|
||||
|
|
|
|||
|
|
@ -71,11 +71,11 @@ Future<bool> _formatSymbolToBulletedList(
|
|||
},
|
||||
);
|
||||
final transaction = editorState.transaction
|
||||
..deleteNode(node)
|
||||
..insertNode(
|
||||
node.path,
|
||||
bulletedListNode,
|
||||
)
|
||||
..deleteNode(node)
|
||||
..afterSelection = afterSelection;
|
||||
await editorState.apply(transaction);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import 'dart:async';
|
||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:appflowy_editor/src/editor/editor_component/service/renderer/block_component_service.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:appflowy_editor/src/history/undo_manager.dart';
|
||||
|
|
@ -160,6 +159,7 @@ class EditorState {
|
|||
final completer = Completer<void>();
|
||||
|
||||
for (final operation in transaction.operations) {
|
||||
Log.editor.debug('apply op: ${operation.toJson()}');
|
||||
_applyOperation(operation);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,18 +34,6 @@ ShortcutEventHandler tabHandler = (editorState, event) {
|
|||
end: selection.end.copyWith(path: path),
|
||||
);
|
||||
|
||||
// abc
|
||||
// efg
|
||||
|
||||
// abc
|
||||
// efg
|
||||
|
||||
// abc 0
|
||||
// 1
|
||||
|
||||
// abc 0 -> insert([0, 0], efg)
|
||||
// efg 0,0
|
||||
|
||||
final transaction = editorState.transaction
|
||||
..deleteNode(textNode)
|
||||
..insertNode(path, textNode)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,23 @@
|
|||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../util/document_util.dart';
|
||||
import '../../util/util.dart';
|
||||
|
||||
void main() async {
|
||||
group('bulleted_list_shortcut.dart', () {
|
||||
setUpAll(() {
|
||||
if (kDebugMode) {
|
||||
activateLog();
|
||||
}
|
||||
});
|
||||
|
||||
tearDownAll(() {
|
||||
if (kDebugMode) {
|
||||
deactivateLog();
|
||||
}
|
||||
});
|
||||
|
||||
group('formatAsteriskToBulletedList', () {
|
||||
// Before
|
||||
// *|Welcome to AppFlowy Editor 🔥!
|
||||
|
|
@ -58,6 +71,40 @@ void main() async {
|
|||
expect(result, false);
|
||||
expect(before.toJson(), after.toJson());
|
||||
});
|
||||
|
||||
// Before
|
||||
// Welcome to AppFlowy Editor 🔥!
|
||||
// *|Welcome to AppFlowy Editor 🔥!
|
||||
// After
|
||||
// Welcome to AppFlowy Editor 🔥!
|
||||
//[bulleted_list] Welcome to AppFlowy Editor 🔥!
|
||||
test('mock inputting a ` ` in the middle of the text', () async {
|
||||
const text = 'Welcome to AppFlowy Editor 🔥!';
|
||||
final document = Document.blank()
|
||||
.addParagraphs(
|
||||
1,
|
||||
builder: (index) => Delta()..insert(text),
|
||||
)
|
||||
.addParagraphs(
|
||||
1,
|
||||
builder: (index) => Delta()..insert('*$text'),
|
||||
);
|
||||
final editorState = EditorState(document: document);
|
||||
|
||||
// Welcome to AppFlowy Editor 🔥!
|
||||
// *|Welcome to AppFlowy Editor 🔥!
|
||||
final selection = Selection.collapsed(
|
||||
Position(path: [1], offset: 1),
|
||||
);
|
||||
editorState.selection = selection;
|
||||
final result = await formatAsteriskToBulletedList.execute(editorState);
|
||||
final after = editorState.getNodeAtPath([1])!;
|
||||
|
||||
// the second line will be formatted as the bulleted list style
|
||||
expect(result, true);
|
||||
expect(after.type, 'bulleted_list');
|
||||
expect(after.delta!.toPlainText(), text);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
|
|
@ -7,6 +8,18 @@ import '../../../util/util.dart';
|
|||
// single | means the cursor
|
||||
// double | means the selection
|
||||
void main() async {
|
||||
setUpAll(() {
|
||||
if (kDebugMode) {
|
||||
activateLog();
|
||||
}
|
||||
});
|
||||
|
||||
tearDownAll(() {
|
||||
if (kDebugMode) {
|
||||
deactivateLog();
|
||||
}
|
||||
});
|
||||
|
||||
group('backspace_command.dart', () {
|
||||
group('backspaceCommand - collapsed selection', () {
|
||||
const text = 'Welcome to AppFlowy Editor 🔥!';
|
||||
|
|
|
|||
|
|
@ -1,9 +1,22 @@
|
|||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../util/document_util.dart';
|
||||
import '../util/util.dart';
|
||||
|
||||
void main() async {
|
||||
setUpAll(() {
|
||||
if (kDebugMode) {
|
||||
activateLog();
|
||||
}
|
||||
});
|
||||
|
||||
tearDownAll(() {
|
||||
if (kDebugMode) {
|
||||
deactivateLog();
|
||||
}
|
||||
});
|
||||
|
||||
group('selection_transform.dart', () {
|
||||
group('deleteSelection', () {
|
||||
test('the selection is collapsed', () async {
|
||||
|
|
|
|||
Loading…
Reference in a new issue