fix: Cannot type on empty document in latest changes
This commit is contained in:
parent
5fc5419d4e
commit
9199d0e94d
3 changed files with 19 additions and 7 deletions
|
|
@ -99,7 +99,9 @@ class _HomePageState extends State<HomePage> {
|
|||
}),
|
||||
_buildListTile(context, 'With Empty Document', () {
|
||||
final jsonString = Future<String>.value(
|
||||
jsonEncode(EditorState.empty().document.toJson()).toString(),
|
||||
jsonEncode(
|
||||
EditorState.blank(withInitialText: true).document.toJson(),
|
||||
).toString(),
|
||||
);
|
||||
_loadEditor(context, jsonString);
|
||||
}),
|
||||
|
|
@ -108,7 +110,9 @@ class _HomePageState extends State<HomePage> {
|
|||
_buildSeparator(context, 'Text Robot'),
|
||||
_buildListTile(context, 'Type Text Automatically', () async {
|
||||
final jsonString = Future<String>.value(
|
||||
jsonEncode(EditorState.empty().document.toJson()).toString(),
|
||||
jsonEncode(
|
||||
EditorState.blank(withInitialText: true).document.toJson(),
|
||||
).toString(),
|
||||
);
|
||||
await _loadEditor(context, jsonString);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
import 'dart:collection';
|
||||
|
||||
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';
|
||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
|
||||
/// [Document] represents a AppFlowy Editor document structure.
|
||||
///
|
||||
|
|
@ -24,6 +21,7 @@ class Document {
|
|||
}
|
||||
|
||||
/// Creates a empty document with a single text node.
|
||||
@Deprecated('use Document.blank() instead')
|
||||
factory Document.empty() {
|
||||
final root = Node(
|
||||
type: 'document',
|
||||
|
|
@ -34,9 +32,10 @@ class Document {
|
|||
);
|
||||
}
|
||||
|
||||
factory Document.blank() {
|
||||
factory Document.blank({bool withInitialText = false}) {
|
||||
final root = Node(
|
||||
type: 'document',
|
||||
children: withInitialText ? [paragraphNode()] : [],
|
||||
);
|
||||
return Document(
|
||||
root: root,
|
||||
|
|
|
|||
|
|
@ -58,11 +58,20 @@ class EditorState {
|
|||
undoManager.state = this;
|
||||
}
|
||||
|
||||
@Deprecated('use EditorState.blank() instead')
|
||||
EditorState.empty()
|
||||
: this(
|
||||
document: Document.blank(),
|
||||
);
|
||||
|
||||
EditorState.blank({
|
||||
bool withInitialText = true,
|
||||
}) : this(
|
||||
document: Document.blank(
|
||||
withInitialText: withInitialText,
|
||||
),
|
||||
);
|
||||
|
||||
final Document document;
|
||||
|
||||
/// Whether the editor is editable.
|
||||
|
|
|
|||
Loading…
Reference in a new issue