fix: # doesn't work #937

This commit is contained in:
Lucas.Xu 2022-08-30 17:22:33 +08:00
parent 0f334962ce
commit 8afa48ca16
4 changed files with 39 additions and 3 deletions

View File

@ -38,7 +38,6 @@ class HeadingTextNodeWidget extends StatefulWidget {
} }
// customize // customize
class _HeadingTextNodeWidgetState extends State<HeadingTextNodeWidget> class _HeadingTextNodeWidgetState extends State<HeadingTextNodeWidget>
with Selectable, DefaultSelectable { with Selectable, DefaultSelectable {
@override @override

View File

@ -79,7 +79,10 @@ Map<String, double> headingToFontSize = {
extension NodeAttributesExtensions on Attributes { extension NodeAttributesExtensions on Attributes {
String? get heading { String? get heading {
if (containsKey(StyleKey.heading) && this[StyleKey.heading] is String) { if (containsKey(StyleKey.subtype) &&
containsKey(StyleKey.heading) &&
this[StyleKey.subtype] == StyleKey.heading &&
this[StyleKey.heading] is String) {
return this[StyleKey.heading]; return this[StyleKey.heading];
} }
return null; return null;

View File

@ -1,3 +1,4 @@
import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
@ -29,7 +30,8 @@ KeyEventResult _handleBackspace(EditorState editorState, RawKeyEvent event) {
if (textNode.subtype != null) { if (textNode.subtype != null) {
transactionBuilder transactionBuilder
..updateNode(textNode, { ..updateNode(textNode, {
'subtype': null, StyleKey.subtype: null,
textNode.subtype!: null,
}) })
..afterSelection = Selection.collapsed( ..afterSelection = Selection.collapsed(
Position( Position(

View File

@ -234,6 +234,38 @@ void main() async {
(tester) async { (tester) async {
await _deleteLastImage(tester, false); await _deleteLastImage(tester, false);
}); });
testWidgets('Removes the style of heading text and revert', (tester) async {
const text = 'Welcome to Appflowy 😁';
final editor = tester.editor..insertTextNode(text);
await editor.startTesting();
await editor.updateSelection(
Selection.single(path: [0], startOffset: 0),
);
final textNode = editor.nodeAtPath([0]) as TextNode;
await editor.insertText(textNode, '#', 0);
await editor.pressLogicKey(LogicalKeyboardKey.space);
expect(
(editor.nodeAtPath([0]) as TextNode).attributes.heading,
StyleKey.h1,
);
await editor.pressLogicKey(LogicalKeyboardKey.backspace);
expect(
textNode.attributes.heading,
null,
);
await editor.insertText(textNode, '#', 0);
await editor.pressLogicKey(LogicalKeyboardKey.space);
expect(
(editor.nodeAtPath([0]) as TextNode).attributes.heading,
StyleKey.h1,
);
});
} }
Future<void> _deleteFirstImage(WidgetTester tester, bool isBackward) async { Future<void> _deleteFirstImage(WidgetTester tester, bool isBackward) async {