Skip to content

ignoreFocusOnTextChange causes text selection issues; cursor does not move #2547

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

Open
1 task done
md-rifatkhan opened this issue Apr 23, 2025 · 2 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@md-rifatkhan
Copy link
Contributor

Have you checked for an existing issue?

Flutter Quill Version

11.2.0

Steps to Reproduce

After press, Try selecting text multiple times or move the cursor.

QuillToolbarToggleStyleButton(
                options: QuillToolbarToggleStyleButtonOptions(
                  afterButtonPressed: () async {
                    quillController.ignoreFocusOnTextChange = true;
                  },
                ),
                controller: quillController,
                attribute: Attribute.bold,
              ),

Expected results

Cursor should behave normally after toggling toolbar actions
Text should be selectable and cursor should be moveable

Actual results

After pressing a toolbar button (like Bold), cursor stops responding
Unable to select text or move the cursor properly,

if we press backbutton, then text selection appear,

Additional Context

@md-rifatkhan md-rifatkhan added the bug Something isn't working label Apr 23, 2025
@md-rifatkhan
Copy link
Contributor Author

md-rifatkhan commented Apr 23, 2025

First button is normal bold, second custom button is bold with quillController.ignoreFocusOnTextChange = true;
Sorry for no tapping effect,

@shafisma
Copy link

shafisma commented May 1, 2025

Proposed Workaround

The root issue here is that setting

quillController.ignoreFocusOnTextChange = true

prevents the editor from updating its cursor/focus when the document changes. You can work around it by briefly resetting that flag around your format call, then re-focusing the editor:

QuillToolbarToggleStyleButton(
  options: QuillToolbarToggleStyleButtonOptions(
    afterButtonPressed: () async {
      // 1. Temporarily re-enable focus updates
      quillController.ignoreFocusOnTextChange = false;

      // 2. Apply the style toggle (e.g. Bold/Unbold)
      quillController.formatSelection(Attribute.bold);

      // 3. Re-focus the editor so the cursor moves correctly
      quillFocusNode.requestFocus();

      // 4. (Optional) Re-disable focus updates after the frame
      WidgetsBinding.instance.addPostFrameCallback((_) {
        quillController.ignoreFocusOnTextChange = true;
      });
    },
  ),
  controller: quillController,
  attribute: Attribute.bold,
),

Why this helps:

  • Step 1 lets the controller handle the text change and move the cursor as usual.
  • Step 3 ensures the editor regains focus immediately.
  • Step 4 restores ignoreFocusOnTextChange (if you still need it to suppress unwanted scroll jumps on subsequent edits).

If you’d rather avoid the post-frame callback, you can also re-enable the ignore flag with a short Future.delayed(Duration.zero, () { ... }); instead of addPostFrameCallback. Let me know if this solves the issue or if you need a more integrated fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants