fix: pressing enter key in the edge of node doesn't work good.

This commit is contained in:
Lucas.Xu 2022-08-02 17:16:02 +08:00
parent 5fdcdbd357
commit a1be60721e
6 changed files with 26 additions and 18 deletions

View File

@ -116,13 +116,16 @@ class _MyHomePageState extends State<MyHomePage> {
_editorState = EditorState(
document: document,
);
return FlowyEditor(
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.
// {

View File

@ -74,7 +74,7 @@ class _FlowyRichTextState extends State<FlowyRichText> 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,

View File

@ -51,6 +51,7 @@ class StyleKey {
static List<String> globalStyleKeys = [
StyleKey.heading,
StyleKey.checkbox,
StyleKey.bulletedList,
StyleKey.numberList,
StyleKey.quote,

View File

@ -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: {},
),
)

View File

@ -233,6 +233,9 @@ class _FlowySelectionState extends State<FlowySelection>
@override
void dispose() {
clearSelection();
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@ -455,7 +458,7 @@ class _FlowySelectionState extends State<FlowySelection>
..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<FlowySelection>
if (topmostRect != null && layerLink != null) {
editorState.service.toolbarService
.showInOffset(topmostRect.topLeft, layerLink);
?.showInOffset(topmostRect.topLeft, layerLink);
}
}

View File

@ -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);
ToolbarService? get toolbarService {
if (toolbarServiceKey.currentState != null &&
toolbarServiceKey.currentState is ToolbarService) {
return toolbarServiceKey.currentState! as ToolbarService;
}
return null;
}
}