From 0650c40d9d86c288534b88ce0c8fc318ec66dc52 Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Tue, 9 Aug 2022 19:11:17 +0800 Subject: [PATCH] fix: checkbox error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pressing Enter after a checked-off item, the new checkbox is also checked off. it should be unchecked when it’s newly created. --- .../enter_without_shift_in_text_node_handler.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart b/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart index 3dd0eef2df..51e593a20b 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart +++ b/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart @@ -100,6 +100,13 @@ FlowyKeyEventHandler enterWithoutShiftInTextNodesHandler = final needCopyAttributes = StyleKey.globalStyleKeys .where((key) => key != StyleKey.heading) .contains(textNode.subtype); + Attributes attributes = {}; + if (needCopyAttributes) { + attributes = Attributes.from(textNode.attributes); + if (attributes.check) { + attributes[StyleKey.checkbox] = false; + } + } final afterSelection = Selection.collapsed( Position(path: textNode.path.next, offset: 0), ); @@ -107,8 +114,7 @@ FlowyKeyEventHandler enterWithoutShiftInTextNodesHandler = ..insertNode( textNode.path.next, textNode.copyWith( - attributes: - needCopyAttributes ? Attributes.from(textNode.attributes) : {}, + attributes: attributes, delta: textNode.delta.slice(selection.end.offset), ), )