Skip to content

Fix: Issue with single character formatting in the toggle style button . #2597

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
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

shivansh00011
Copy link

@shivansh00011 shivansh00011 commented Jun 16, 2025

Description

Fixed the issue with single character formatting in the toggle style button. Previously, when formatting a single character (e.g., making it bold), the toolbar state was incorrectly affected, causing subsequent text to be formatted by default. This was due to using the incorrect length property on TextSelection.

The fix replaces selection.length with selection.end - selection.start to properly check the selection length, ensuring that single character formatting doesn't affect the toolbar state while maintaining the correct behavior for multiple character selections.

Related Issues

Type of Change

  • Bug fix: Resolves an issue without altering current behavior.
  • Tests: New or modified tests

Changes Made

  • Modified toggle_style_button.dart to use correct TextSelection length calculation
  • Added test cases to verify single character formatting behavior
  • Added test utility class for testing

Testing

  • Added unit tests that verify:
    • Single character formatting works without affecting toolbar state
    • Multiple character formatting works correctly with toolbar state changes
  • All tests are passing

@shivansh00011 shivansh00011 changed the title Fixed the issue with single character formatting in the toggle style button by replacing selection.length with selection.end - selection.start to properly check the selection length. Fix: Issue with single character formatting in the toggle style button . Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

After formatText() modifies the style, the style is automatically turned on
1 participant