flutter-quill icon indicating copy to clipboard operation
flutter-quill copied to clipboard

[Mobile] or [Desktop] Entering text in the amid link

Open Alspb opened this issue 1 year ago • 3 comments

It's currently possible to enter text amid link. For example, if there's a link "quill" to https://github.com/singerdmx/flutter-quill, then one can move the cursor after "qu", type something (e.g., "test"), and the link will be split to two identical links: "qu" and "ill" with the text "test" between them.

This behavior is not in line with other formatting options. For example, if "quill" word above were bold (not link), the whole "qutestill" word would also be bold.

Alspb avatar Jul 02 '23 10:07 Alspb

Hi, is this still an issue?

EchoEllet avatar Nov 09 '23 16:11 EchoEllet

Hi, That's a bit counterintuitive but obviously not a highest priority issue.

Alspb avatar Nov 22 '23 00:11 Alspb

class EditLinkRule extends InsertRule {
  const EditLinkRule();

  @override
  Delta? applyRule(
    Delta document,
    int index, {
    int? len,
    Object? data,
    Attribute<dynamic>? attribute,
  }) {
    final delta = Delta();
    final itr = DeltaIterator(document);
    final before = itr.skip(index), after = itr.next();
    if (before == null) return null;

    if (before.hasAttribute(Attribute.link.key) &&
        after.hasAttribute(Attribute.link.key)) {
      delta
        ..retain(index + (len ?? 0))
        ..insert(data, before.attributes);
      return delta;
    }
    return null;
  }
}

and then

    document.setCustomRules([
      const EditLinkRule(),
    ]);

shorben07 avatar Apr 23 '24 07:04 shorben07