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

customLinkPrefixes isn't plumbed throughout library

Open mikecodega opened this issue 1 year ago • 3 comments

Is there an existing issue for this?

Flutter Quill version

9.3.1

Steps to reproduce

When customLinkPrefixes are set in QuillEditorConfigurations...

  • They aren't honored in the _LinkDialog from the toolbar.
    • this can be reproduced by (1) setting them in the config, (2) trying to use them in the dialog.
  • They aren't honored during insert by AutoFormatMultipleLinksRule
    • this can be reproduced by trying to insert text when using the rule.

Expected results

Expect that custom Link Prefixes are honored for the above fields.

I would be happy to help with writing a PR for the fix, but I think the library maintainers should suggest a path for the fix. The library mostly uses Regex to detect links, but the customLinkPrefixes is just a list of strings of the prefixes. Additionally, some parts of the library that interact with links aren't configured via the QuillEditorConfigurations. I'm not experienced with the library's architecture enough to make them without input.

Actual results

Custom Link Prefixes are ignored for the above fields.

Code sample

n/a this can be validated using the repo's provided examples, with this one config added.

Screenshots or Video

No response

Logs

No response

mikecodega avatar Mar 18 '24 03:03 mikecodega

Does this isse still persists? I will close it. Please, reopen if it does.

CatHood0 avatar Sep 21 '24 03:09 CatHood0

@mikecodega Can you confirm if this still an issue?

EchoEllet avatar Sep 21 '24 13:09 EchoEllet

Hey, this issue doesn't seem to be resolved. What changes were made?

It looks like it's still not possible to use the built-in link insertion modal from the toolbar to insert a link with a custom prefix.

For example, I tried "scheme://" as a prefix, and then adding a link such as "scheme://XXXX", and the only thing it'd accept is "http://XXXX" or "https://XXXX"

mikecodega avatar Sep 27 '24 22:09 mikecodega

I can confirm that customLinkPrefixes is not honored, it's not passed at all in the actual link detection rule.

I think the fix might not be too heavy, we should pass this parameter to AutoFormatMultipleLinksRule and generate more link patterns for link detection, because currently quill editor enforces only one pattern:

static const _oneLineLinkPattern =
      r'^https?:\/\/[\w\-]+(\.[\w\-]+)*(:\d+)?([\/\?#].*)?$';
  static const _detectLinkPattern =
      r'https?:\/\/[\w\-]+(\.[\w\-]+)*(:\d+)?([\/\?#][^\s]*)?';

Something like this might work (it's only pseudo-code though):

customLinkPrefixes.forEach((customPrefix) {
  final pattern = '^${customPrefix}?:\/\/[\w\-]+(\.[\w\-]+)*(:\d+)?([\/\?#].*)?$';

  // Check if the custom pattern matches 
  if(matches)
     // proceed with match on next steps
  else
     // continue in for loop
});

orevial avatar Oct 25 '24 10:10 orevial

It would really be great if someone could fix this. Even simple email links like "mailto:[email protected]" are not accepted in the input dialog after adding customLinkPrefixes: const ['mailto:', 'tel:'] in the "QuillEditorConfigurations"

LP0815 avatar Mar 27 '25 08:03 LP0815

I'll check it out after merge some of the open PRs that i have. Thanks for the code example.

CatHood0 avatar Mar 27 '25 08:03 CatHood0

@CatHood0

I will take over, I noticed you've been trying to do too much recently. Related #1164

EchoEllet avatar Mar 27 '25 10:03 EchoEllet

I will take over, I noticed you've been trying to do too much recently.

Thank you so much 🙇🏻‍♂️!

CatHood0 avatar Mar 27 '25 10:03 CatHood0

For example, I tried "scheme://" as a prefix, and then adding a link such as "scheme://XXXX", and the only thing it'd accept is "http://XXXX" or "https://XXXX"

Yes, it isn't clear; see the related lines.

I have fixed it in my local branch.

EchoEllet avatar Mar 27 '25 10:03 EchoEllet