suyati / line-control

A Light Weight HTML5 Text Editor designed as a JQuery Plugin
Other
124 stars 90 forks source link

Where in editor.js can I intercept user pasted text? #39

Open guidocs opened 9 years ago

guidocs commented 9 years ago

I would like to be able to examine text inserted by a user using the CTRL/V key combination. I have not been able to place a breakpoint in editor.js to at least determine where such code can be inserted.

I am particularly interested in being able to eliminate MS Word text formatting, etc., or if not give an alert message to the user.

Any help would be GREATLY APPRECIATED. THANKS.

xOneca commented 9 years ago

Well, copy/paste is not implemented by line-control itself, but by the browser. When you press Ctrl+V, it is the browser who pastes clipboard content. So there's no place in line-control code where you can put a breakpoint which will intercept that.

You can try with keydown/keypress events and wait for Ctrl+V. Or maybe paste event, but don't know about compatibility or if it will be useful at all.

xOneca commented 9 years ago

Note: Listening for Ctrl+V will miss pasted content inserted by other means, such as using the option Paste from the context menu.