diff --git a/frontend/app_flowy/packages/flowy_editor/example/lib/main.dart b/frontend/app_flowy/packages/flowy_editor/example/lib/main.dart index 158e33bbb1..1a68f38ead 100644 --- a/frontend/app_flowy/packages/flowy_editor/example/lib/main.dart +++ b/frontend/app_flowy/packages/flowy_editor/example/lib/main.dart @@ -116,13 +116,16 @@ class _MyHomePageState extends State { _editorState = EditorState( document: document, ); - return FlowyEditor( - key: editorKey, - editorState: _editorState, - keyEventHandlers: const [], - customBuilders: { - 'image': ImageNodeBuilder(), - }, + return Container( + padding: const EdgeInsets.only(left: 20, right: 20), + child: FlowyEditor( + key: editorKey, + editorState: _editorState, + keyEventHandlers: const [], + customBuilders: { + 'image': ImageNodeBuilder(), + }, + ), // shortcuts: [ // // TODO: this won't work, just a example for now. // { diff --git a/frontend/app_flowy/packages/flowy_editor/lib/render/rich_text/flowy_rich_text.dart b/frontend/app_flowy/packages/flowy_editor/lib/render/rich_text/flowy_rich_text.dart index 70834184cc..f302fcaba8 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/render/rich_text/flowy_rich_text.dart +++ b/frontend/app_flowy/packages/flowy_editor/lib/render/rich_text/flowy_rich_text.dart @@ -74,7 +74,7 @@ class _FlowyRichTextState extends State with Selectable { _renderParagraph.getOffsetForCaret(textPosition, Rect.zero); final cursorHeight = widget.cursorHeight ?? _renderParagraph.getFullHeightForCaret(textPosition) ?? - 5.0; // default height + 18.0; // default height return Rect.fromLTWH( cursorOffset.dx - (widget.cursorWidth / 2), cursorOffset.dy, diff --git a/frontend/app_flowy/packages/flowy_editor/lib/render/rich_text/rich_text_style.dart b/frontend/app_flowy/packages/flowy_editor/lib/render/rich_text/rich_text_style.dart index 19aa109faf..cc4f6038ac 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/render/rich_text/rich_text_style.dart +++ b/frontend/app_flowy/packages/flowy_editor/lib/render/rich_text/rich_text_style.dart @@ -51,6 +51,7 @@ class StyleKey { static List globalStyleKeys = [ StyleKey.heading, + StyleKey.checkbox, StyleKey.bulletedList, StyleKey.numberList, StyleKey.quote, diff --git a/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/enter_in_edge_of_text_node_handler.dart b/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/enter_in_edge_of_text_node_handler.dart index 525afd9021..5b49907138 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/enter_in_edge_of_text_node_handler.dart +++ b/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/enter_in_edge_of_text_node_handler.dart @@ -37,9 +37,8 @@ FlowyKeyEventHandler enterInEdgeOfTextNodeHandler = (editorState, event) { textNode.path.next, textNode.copyWith( children: LinkedList(), - delta: Delta([TextInsert(' ')]), - attributes: - needCopyAttributes ? {StyleKey.subtype: textNode.subtype} : {}, + delta: Delta([TextInsert('')]), + attributes: needCopyAttributes ? textNode.attributes : {}, ), ) ..afterSelection = Selection.collapsed( @@ -56,7 +55,7 @@ FlowyKeyEventHandler enterInEdgeOfTextNodeHandler = (editorState, event) { textNode.path, textNode.copyWith( children: LinkedList(), - delta: Delta([TextInsert(' ')]), + delta: Delta([TextInsert('')]), attributes: {}, ), ) diff --git a/frontend/app_flowy/packages/flowy_editor/lib/service/selection_service.dart b/frontend/app_flowy/packages/flowy_editor/lib/service/selection_service.dart index 0695dd5e90..59632773e5 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/service/selection_service.dart +++ b/frontend/app_flowy/packages/flowy_editor/lib/service/selection_service.dart @@ -233,6 +233,9 @@ class _FlowySelectionState extends State @override void dispose() { + clearSelection(); + WidgetsBinding.instance.removeObserver(this); + super.dispose(); } @@ -455,7 +458,7 @@ class _FlowySelectionState extends State ..forEach((overlay) => overlay.remove()) ..clear(); // clear toolbar - editorState.service.toolbarService.hide(); + editorState.service.toolbarService?.hide(); } void _updateSelection(Selection selection) { @@ -526,7 +529,7 @@ class _FlowySelectionState extends State if (topmostRect != null && layerLink != null) { editorState.service.toolbarService - .showInOffset(topmostRect.topLeft, layerLink); + ?.showInOffset(topmostRect.topLeft, layerLink); } } diff --git a/frontend/app_flowy/packages/flowy_editor/lib/service/service.dart b/frontend/app_flowy/packages/flowy_editor/lib/service/service.dart index 829ad2bde1..937a16044a 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/service/service.dart +++ b/frontend/app_flowy/packages/flowy_editor/lib/service/service.dart @@ -23,9 +23,11 @@ class FlowyService { // toolbar service final toolbarServiceKey = GlobalKey(debugLabel: 'flowy_toolbar_service'); - ToolbarService get toolbarService { - assert(toolbarServiceKey.currentState != null && - toolbarServiceKey.currentState is ToolbarService); - return toolbarServiceKey.currentState! as ToolbarService; + ToolbarService? get toolbarService { + if (toolbarServiceKey.currentState != null && + toolbarServiceKey.currentState is ToolbarService) { + return toolbarServiceKey.currentState! as ToolbarService; + } + return null; } }