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

want onPaste handler #31

Open
ttlg opened this issue Sep 5, 2018 · 3 comments
Open

want onPaste handler #31

ttlg opened this issue Sep 5, 2018 · 3 comments

Comments

@ttlg
Copy link

ttlg commented Sep 5, 2018

It would be useful to add onPaste interface on the editable text. It makes URL pasting experience great.

@pulyaevskiy
Copy link
Contributor

Not sure if I understand this correctly. What exact behavior are you expecting?

I assume it's when you paste a URL it is formatted as link right away? As opposed to how it works currently when you still need to add a space to trigger auto format.

@ttlg
Copy link
Author

ttlg commented Sep 6, 2018

Thank you for your reply.
I want paste event handler so that we can add any functions (like displaying modal window for asking if user want formatted link or not) before pasting.

@ChickenTarm
Copy link

ChickenTarm commented Jun 9, 2020

I might be useful for an OnPasteHandler, but my work around was to add an insert rule into notus that checks if the insert is a valid URL if it is then it will insert the text along with the link
Calling it an onPasteHandler is probably wrong since it works even for just typing in a valid URL.

`

class CheckLinkOnPasteRule extends InsertRule {
    const CheckLinkOnPasteRule();

@override
Delta apply(Delta document, int index, String text) {
    try { 
        // need this try since the parsing will throw an error after empty :
        if (!Uri.parse(text.trim()).isAbsolute) {
             // Only interested in text containing a url
            return null;
        }
    } on Exception catch (_) {
        return null;
    }

    final iter = DeltaIterator(document);
    iter.skip(index);

    final result = Delta()..retain(index);

    result.insert(text, {'a': text.trim()});

    return result;
  }
}

`

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

No branches or pull requests

3 participants