Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] changing heading from one level to another from toolbar #2171

Closed
zoli opened this issue Apr 3, 2023 · 1 comment · Fixed by AppFlowy-IO/appflowy-editor#96
Closed
Assignees
Labels
bug Something isn't working editor features related to the rich-text editor
Milestone

Comments

@zoli
Copy link
Contributor

zoli commented Apr 3, 2023

Bug Description

If we have a text with h2 heading, Changing it to h1 from toolbar will just reset it to plain text. The subtype attribute becomes null but the heading will be h1 which causes the "H1" highlighted in toolbar but Appflowy editor it renders it as plain text.

The problem is rooted in this part of code which is intended for toggling attribute so if we try to format a quote subtype text again to quote subtype it just removes the quote (toggles it).

How to Reproduce

From toolbar change plain text to "H2" heading then try to change it to "H1".

Expected Behavior

To change from "H2" heading to "H1".

Operating System

Arch Linux

AppFlowy Version(s)

0.1.2

Screenshots

No response

Additional Context

This test case does not pass. If I'm right it should get added to "format_rich_text_style_test.dart" file

testWidgets('formatHeading from h2 to h1', (tester) async {
      const text = 'Welcome to Appflowy 😁';
      final editor = tester.editor
        ..insertTextNode(text, attributes: {
          BuiltInAttributeKey.subtype: BuiltInAttributeKey.heading,
          BuiltInAttributeKey.heading: BuiltInAttributeKey.h2,
        });
      await editor.startTesting();
      await editor.updateSelection(
        Selection.single(path: [0], startOffset: 0, endOffset: text.length),
      );

      // format the text to Quote
      formatHeading(editor.editorState, BuiltInAttributeKey.h1);
      await tester.pumpAndSettle(const Duration(milliseconds: 100));
      expect(find.byType(HeadingTextNodeWidget), findsOneWidget);

      final tn = editor.nodeAtPath([0])!;
      expect(tn.attributes.containsKey(BuiltInAttributeKey.subtype), true);
      expect(tn.attributes[BuiltInAttributeKey.subtype],
          BuiltInAttributeKey.heading);
      expect(tn.attributes.containsKey(BuiltInAttributeKey.heading), true);
      expect(
          tn.attributes[BuiltInAttributeKey.heading], BuiltInAttributeKey.h1);
    });

I'm not sure about all the cases but maybe an applicable solution would be that on removing subtype we should check if all other keys are unchanged or not.

@annieappflowy annieappflowy added bug Something isn't working editor features related to the rich-text editor labels Apr 6, 2023
@annieappflowy
Copy link
Collaborator

Thanks for reporting!
I'm able to reproduce it on MacOS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working editor features related to the rich-text editor
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants