Skip to content

Commit 8afa48c

Browse files
committed
fix: # doesn't work #937
1 parent 0f33496 commit 8afa48c

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/heading_text.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class HeadingTextNodeWidget extends StatefulWidget {
3838
}
3939

4040
// customize
41-
4241
class _HeadingTextNodeWidgetState extends State<HeadingTextNodeWidget>
4342
with Selectable, DefaultSelectable {
4443
@override

frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/rich_text_style.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ Map<String, double> headingToFontSize = {
7979

8080
extension NodeAttributesExtensions on Attributes {
8181
String? get heading {
82-
if (containsKey(StyleKey.heading) && this[StyleKey.heading] is String) {
82+
if (containsKey(StyleKey.subtype) &&
83+
containsKey(StyleKey.heading) &&
84+
this[StyleKey.subtype] == StyleKey.heading &&
85+
this[StyleKey.heading] is String) {
8386
return this[StyleKey.heading];
8487
}
8588
return null;

frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/backspace_handler.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart';
12
import 'package:flutter/material.dart';
23
import 'package:flutter/services.dart';
34

@@ -29,7 +30,8 @@ KeyEventResult _handleBackspace(EditorState editorState, RawKeyEvent event) {
2930
if (textNode.subtype != null) {
3031
transactionBuilder
3132
..updateNode(textNode, {
32-
'subtype': null,
33+
StyleKey.subtype: null,
34+
textNode.subtype!: null,
3335
})
3436
..afterSelection = Selection.collapsed(
3537
Position(

frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/backspace_handler_test.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,38 @@ void main() async {
234234
(tester) async {
235235
await _deleteLastImage(tester, false);
236236
});
237+
238+
testWidgets('Removes the style of heading text and revert', (tester) async {
239+
const text = 'Welcome to Appflowy 😁';
240+
final editor = tester.editor..insertTextNode(text);
241+
await editor.startTesting();
242+
243+
await editor.updateSelection(
244+
Selection.single(path: [0], startOffset: 0),
245+
);
246+
247+
final textNode = editor.nodeAtPath([0]) as TextNode;
248+
249+
await editor.insertText(textNode, '#', 0);
250+
await editor.pressLogicKey(LogicalKeyboardKey.space);
251+
expect(
252+
(editor.nodeAtPath([0]) as TextNode).attributes.heading,
253+
StyleKey.h1,
254+
);
255+
256+
await editor.pressLogicKey(LogicalKeyboardKey.backspace);
257+
expect(
258+
textNode.attributes.heading,
259+
null,
260+
);
261+
262+
await editor.insertText(textNode, '#', 0);
263+
await editor.pressLogicKey(LogicalKeyboardKey.space);
264+
expect(
265+
(editor.nodeAtPath([0]) as TextNode).attributes.heading,
266+
StyleKey.h1,
267+
);
268+
});
237269
}
238270

239271
Future<void> _deleteFirstImage(WidgetTester tester, bool isBackward) async {

0 commit comments

Comments
 (0)