quill icon indicating copy to clipboard operation
quill copied to clipboard

Clipboard Documentation/Examples

Open fernandogmar opened this issue 10 years ago • 22 comments

Hi guys,

Thank you for this nice editor ;)

I am using quilljs 1.0.0 beta, from what I read the behaviour on paste can be customized thanks to Clipboard.

But I haven't found documentation/examples about that. Could you point me to some of these?

I was happy with quilljs behaviour before, if I am not wrong it allowed to paste only those tags available on the specified formats. It would be nice to reproduce this behaviour with quilljs 1.0.0 again, or at least to copy only the text without format as ctrl + shift + v can do.

Anyone can give me a clue if this can be done and how?

Thanks a lot in advance!

Keep pushing forward! :D

fernandogmar avatar Jul 20 '16 15:07 fernandogmar

Not sure if this was missed this or if something was unclear there but details on the Clipboard and customizing it can be found on its own documentation. Quill 0.20 allows a whitelist of formats which is still available in 1.0 in its configuration options. If you want to completely remove pasted formatting then it might be best to remove the Clipboard matchers that add formatting.

jhchen avatar Jul 20 '16 21:07 jhchen

Thanks @jhchen

I read it that before, but I couldn't guess how to do what I needed with that description. I miss more real examples there. So I thought maybe there was something else. Notice that even I don't know how to do what you suggested "to remove the Clipboard matchers" with that documentation.

Anyway I was playing with the playground on the page, pasting content works I would expect there. So I have spent the full morning trying to guess what was the problem and it seems it was related with having custom.snow.css included... Finally what I did was to upgrade it to the last version beta.9... and redo some work based on this version.

Thanks again!

fernandogmar avatar Jul 21 '16 10:07 fernandogmar

Thanks for the feedback. I'll work on making the docs more clear.

jhchen avatar Jul 21 '16 21:07 jhchen

@jhchen it would really help to do this. I've spent an hour trying to either override or disable the built in clipboard without any luck. It's extremely frustrating.

adamkdean avatar May 25 '17 10:05 adamkdean

What specific pages of documentation have you looked at and what have tried?

jhchen avatar May 25 '17 16:05 jhchen

I too like @adamkdean have trouble understanding how the addMatcher( ) should work... I have been studying the examples here https://quilljs.com/docs/modules/clipboard/ and have been trying to reproduce them but they do not work. Or maybe I might be doing something wrong because I have noticed that when I am pasting simple text or something with a < b > tag (as in the examples) the addMatcher( ) callback function is never called!

Also it would be nice if there was some documentation that lets you know what String formats the addMatcher accepts as its first parameter, for e.g. "B" is for < b > but I have no idea what works for < a >, is it "A" or "a" or none of these? It would be nice if there was a list somewhere listing all the possible options that Quill.js recognizes...

nitaskenderi avatar Jul 06 '17 14:07 nitaskenderi

@nitaskenderi As it states in the addMatcher docs it takes a CSS selector. Both "A" and "a" are valid CSS selectors. CSS selectors are too complex to enumerate the possibilities but it's also a common enough technology that I do not see it as Quill's role to explain.

jhchen avatar Jul 06 '17 18:07 jhchen

Yes that is how I understood it.. Well then I must be having some trouble using the actual function. Here is how I have been trying to use it:

messageBox = new Quill('#' + containerId, {
            placeholder: 'Write a message...',
            modules: {
                "toolbar": false,
                keyboard: {
                    bindings:
                    { enter: {
                            key: 13,
                            handler: handleEnter
                        }
                    }
                }
            }
        });

messageBox.clipboard.addMatcher('B', function(node, delta) {
  //debugger;
  return delta.compose(new Delta().retain(delta.length(), { bold: true }));
});

messageBox.clipboard.addMatcher('a', function(node, delta) {
  //debugger;
  return delta.compose(new Delta().retain(delta.length(), { color: "red"}));
});

So I basically just used the example given in the documentation and then tried to add my own version, but when I paste in html with a < b > tag or a link, it never enters the addMatcher( ) callback function... How do I fix this? I really need to set my own rules for when pasting HTML into the editor because I will only accept two or three HTML elements, everything else has to be pasted as plain text.

nitaskenderi avatar Jul 07 '17 07:07 nitaskenderi

Create a minimal complete verifiable example and in another Issue with all fields filled out and someone might be able to help you out. The exercise of making one often reveals the error.

jhchen avatar Jul 07 '17 07:07 jhchen

Okay, will do. Thank you!

nitaskenderi avatar Jul 07 '17 08:07 nitaskenderi

@jhchen Is it possible to remove one of the default matches? I'm running into a lot of issues with matchSpacing as it adds in extra newlines that screw up email formatting.

Looking through the code it seems like I can only add more, but not specify a set of new matches. I could try to add a matcher with opposite logic that undoes the default one, but doesn't seem like the best solution. It would be hard to know which newlines were automatically added by the matcher and which were intended by the user.

justinpincar avatar Jul 13 '17 17:07 justinpincar

@justinpincar Others have been asking for this as well but Semantic Versioning would dictate that Quill go to 2.0 if it were removed. I could add a config option that would skip this matcher (of course the default of that would have to be false). Would that work?

jhchen avatar Jul 13 '17 18:07 jhchen

That would be perfect! Or possibly another config directive along the lines of replaceMatchers that sets new ones instead of appending like the current matchers one does.

Really appreciate the prompt and helpful response! <3

justinpincar avatar Jul 13 '17 18:07 justinpincar

You can now use a new config in 1.3.0 matchVisual to disable Quill's visual paste matching.

jhchen avatar Jul 17 '17 06:07 jhchen

Using matchVisual seems to be working great, thank you!

Since I'm using this for composing emails which have no style sheets, I also needed to remove the .ql-editor * { margin: 0; padding: 0;} from quill.snow.scss, otherwise the editor would be really cramped and not match the output.

justinpincar avatar Jul 17 '17 16:07 justinpincar

I can't find matchVisual property in the documentation that you linked. Is there any up to date solution for this problem?

chillyistkult avatar Dec 05 '18 16:12 chillyistkult

@chillyistkult For some reason, they have removed it from the documentation but the option is still available, you can find the documentation that does include it using WayBackMachine website, link as follows:

https://web.archive.org/web/20170807100811/http://quilljs.com:80/docs/modules/clipboard/

trfletch avatar Feb 03 '19 16:02 trfletch

This not in the docs 😱

franciscolourenco avatar Apr 25 '19 16:04 franciscolourenco

Is the default behaviour changed in 2.0?

franciscolourenco avatar Apr 25 '19 16:04 franciscolourenco

@franciscolourenco No as per my comment above it is not in the docs (although I have provided a link to the archived docs) but it still works in version 1.3.6 which is the version I am using. Sorry, I do not know if it has changed in 2.0 as I am not using that version yet.

trfletch avatar Apr 25 '19 18:04 trfletch