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

Flutter Quill Editor Custom Embed: Select Custom Dropdown on Backspace Key #2308

Open
1 task done
kaushikcrypticalinfo opened this issue Oct 2, 2024 · 0 comments
Open
1 task done
Labels
question Further information is requested

Comments

@kaushikcrypticalinfo
Copy link

Is there an existing issue for this?

The question

Flutter Quill Editor Custom Embed: Select Dropdown on Backspace Key

Description

I am working on a Flutter project where I use the Quill editor and have created a custom embedded dropdown using the DropdownEmbed class. My goal is to detect when the cursor reaches this embedded dropdown and handle the backspace key in such a way that instead of deleting the dropdown immediately, it gets selected or highlighted first.

Expected Behavior

  • When the user presses the backspace key and the cursor reaches the position of the embedded dropdown, the dropdown should be selected or highlighted, giving the user a visual cue before it is deleted.

Actual Behavior

  • Currently, when the backspace key is pressed and the cursor reaches the embedded dropdown, the dropdown is deleted immediately without selection or highlight.

Code Example

Here is my DropdownEmbed class used for embedding a dropdown within the Quill editor:

const String dropDownType = 'dropdown';

class DropdownEmbed extends Embeddable {
  final DropDownTitleItem title;
  final String options;

  DropdownEmbed({
    required this.title,
    required this.options,
  }) : super(
          dropDownType,
          jsonEncode(
            {
              'title': title.toJson(),
              'options': options,
            },
          ),
        );

  @override
  Map<String, dynamic> toJson() {
    return {
      dropDownType: {
        'title': title.toJson(),
        'options': options,
      },
    };
  }

  static DropdownEmbed fromJson(Map<String, dynamic> json) {
    final data = Map<String, dynamic>.from(json);
    return DropdownEmbed(
      title: DropDownTitleItem.fromJson(data['title']),
      options: data['options'],
    );
  }
}

class DropdownBlockEmbed extends CustomBlockEmbed {
  DropdownBlockEmbed(DropdownEmbed embed) : super(dropDownType, embed.data);

  static DropdownBlockEmbed fromEmbed(DropdownEmbed embed) {
    return DropdownBlockEmbed(embed);
  }

  static DropdownEmbed fromCustomBlockEmbed(CustomBlockEmbed blockEmbed) {
    final data = blockEmbed.data as Map<String, dynamic>;
    return DropdownEmbed.fromJson(data);
  }
}

Code Example

Here is my Quill Editor Code

QuillEditor(
  scrollController: scrollController,
  focusNode: focusNode,
  controller: controller,
  configurations: configurations.copyWith(
    customStyles: DefaultStyles(
      h1: DefaultTextBlockStyle(
        defaultTextStyle.style.copyWith(
          fontSize: 32,
          height: 1.15,
          fontWeight: FontWeight.w300,
        ),
        HorizontalSpacing.zero,
        const VerticalSpacing(16, 0),
        VerticalSpacing.zero,
        null,
      ),
    ),
    placeholder: 'Start writing your notes...',
    padding: const EdgeInsets.all(16),
    embedBuilders: [
      DropdownEmbedBuilder(),
      // Other embed builders
    ],
  ),
)

Question

  • How can I modify the behavior so that when the backspace key is pressed, and the cursor reaches the embedded dropdown, the dropdown gets selected or highlighted instead of being immediately deleted?
@kaushikcrypticalinfo kaushikcrypticalinfo added the question Further information is requested label Oct 2, 2024
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

1 participant