quill icon indicating copy to clipboard operation
quill copied to clipboard

quill.clipboard.addMatcher does not detect pasted URLs

Open compmaster opened this issue 1 year ago • 1 comments

Steps for Reproduction

  1. Visit https://stackblitz.com/edit/stackblitz-starters-zqlwfk?file=src%2FLinkPreview.ts
  2. Copy link from browser's address bar
  3. Paste the link into Quill editor

Expected behavior:

Should show alert "it works"

Actual behavior:

Nothing happens (however, when you cut the link from editor and paste it back, then it works)

Platforms:

OS: Windows 7, Windows 10, Ubuntu 22.04 Browsers: Chrome, Firefox, Opera, Vivaldi

Version:

Quill 2.0.2

compmaster avatar Sep 09 '24 08:09 compmaster

When you copy URL from browser's address bar, it's recognized as text and clipboard matchers are not executed.

onCapturePaste(e: ClipboardEvent) {
  /* ... */
  const html = e.clipboardData?.getData('text/html');  // undefined
  let text = e.clipboardData?.getData('text/plain');   // URL as string
  /* ... */
  this.onPaste(range, { html, text });
}
convert(
  { html, text }: { html?: string; text?: string },
  formats: Record<string, unknown> = {},
) {
  if (formats[CodeBlock.blotName]) {     // formats is empty
    return new Delta().insert(text || '', {
      [CodeBlock.blotName]: formats[CodeBlock.blotName],
    });
  }
  if (!html) {
    return new Delta().insert(text || '', formats);   // it's executed - insert text and finish
  }
  const delta = this.convertHTML(html);   // it's not executed (this method calls clipboard matchers)
  /* ... */
  return delta;
}

So is this a feature request to add clipboard matchers for plain text?

compmaster avatar Sep 23 '24 09:09 compmaster