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

Question: Markdown Formatting Not Applied on First Use in FleatherField #429

Open
gitStanda opened this issue Sep 17, 2024 · 5 comments
Open
Labels
question Further information is requested

Comments

@gitStanda
Copy link

gitStanda commented Sep 17, 2024

I need to have 2 different FleatherFields & I don't want to have 2 toolbars shown at the same time - so depending on the focused field, I show toolbar with selected field's controller.

However, I’m experiencing an issue with both FleatherFields where formatting options (e.g., bold, italics, etc.) are not applied correctly when selected before typing. You can see the issue on the attached video.

Zaznam.obrazovky.2024-09-17.153340.mp4

It seems like the formatting doesn’t persist until the user types at least one character first. This issue occurs only before any text is entered—after that, the controller behaves normally.

Steps to Reproduce:

  1. Tap into a FleatherField.
  2. Without typing anything, select bold, italics or any other option from the toolbar.
  3. Start typing text.
  4. Notice that the formatting options are unchecked, and the text is not formatted as expected.

Expected Behavior: The selected formatting (bold, italics, ...) should be applied correctly from the first character typed after being selected in the toolbar.

My code:

  • I tried to extract only the most relevant code.
class _ManualFlashcardScreenState extends ConsumerState<ManualFlashcardScreen> {
  late final FleatherController _frontSideController;
  late final FleatherController _backSideController;
  final FocusNode _frontFocusNode = FocusNode();
  final FocusNode _backFocusNode = FocusNode();
  FleatherController? _activeController;

  @override
  void initState() {
    super.initState();
    _frontSideController = FleatherController(
      document: widget.flashcard != null
          ? ParchmentDocument.fromDelta(widget.flashcard!.frontSide.toDelta())
          : ParchmentDocument(),
    );
    _backSideController = FleatherController(
      document: widget.flashcard != null
          ? ParchmentDocument.fromDelta(widget.flashcard!.backSide.toDelta())
          : ParchmentDocument(),
    );

    _frontFocusNode.addListener(_updateActiveController);
    _backFocusNode.addListener(_updateActiveController);

    if (widget.flashcard == null) _frontFocusNode.requestFocus(); // creating flashcard, not editing
  }

  void _updateActiveController() {
    setState(() {
      if (_frontFocusNode.hasFocus) {
        _activeController = _frontSideController;
      } else if (_backFocusNode.hasFocus) {
        _activeController = _backSideController;
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          FleatherField(
            controller: _frontSideController,
            focusNode: _frontFocusNode,
            enableSuggestions: false,
          ),
          FleatherField(
            controller: _backSideController,
            focusNode: _backFocusNode,
            enableSuggestions: false,
          ),
          if (_activeController != null)
            FleatherToolbar.basic(controller: _activeController!),
        ],
      ),
    );
  }
}

Question

Is this behavior expected with FleatherField, or is there something wrong in my code that might be causing it? Any advice on how to resolve this would be appreciated!

@amantoux amantoux added the question Further information is requested label Sep 21, 2024
@gitStanda
Copy link
Author

Might be a bug as well, not sure to be honest

@amantoux
Copy link
Member

Might be a bug as well, not sure to be honest

Sure, we'll take a look

@gitStanda
Copy link
Author

Might be a bug as well, not sure to be honest

Sure, we'll take a look

Thanks a lot!

@gitStanda
Copy link
Author

BTW just tested this out on iOS simulator and it works. So maybe the issue is just on Android or the Emulator itself?

@no-chili
Copy link

BTW just tested this out on iOS simulator and it works. So maybe the issue is just on Android or the Emulator itself?顺便说一句,刚刚在 iOS 模拟器上对此进行了测试,它有效。那么,也许问题仅在于 Android 或 Emulator 本身上?

Encountering the same situation, it is necessary to input once in advance on Android to enable the style, while iOS does not require this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants