-
Notifications
You must be signed in to change notification settings - Fork 882
Copy/Paste should preserve styling #35
Comments
The easiest way of doing this seems to me to play with event.clipboardData.getData('text/firepad') and setData('text/firepad') (or using directly the mime/type 'text/html' which is slightly more risky as Chrome will provide rich html content for data pasted from others apps). Then, using HTML as a bridge for import/export (as we currently do), would require for these operations to have getHtmlFromSelection (or getHtmlFromRange ?) and insertHtmlAtIndex/Cursor. How does that seem to you? |
That sounds great, but I don't think clipboardData is widely supported (it might be IE-only?). In general, I believe browsers make it difficult to access the clipboard directly, due to security concerns. So making copy/paste work well will likely require some browser hackery. The typical approach (I think) is to detect a ctrl-C operation and move the focus / selection to some place that has the content that you want to end up in the clipboard. Similarly for ctrl-V, you paste to some alternate location and then process the pasted content and insert where you want it. This hackery is why I haven't felt like tackling this. :-) |
I did think the same. But the fact is that window.clipboardData is supported by IE, and at least Chrome+Safari support event.clipboardData getData and setData (I've tested this). So it made me change a bit my mind ;-)
Do you have any suggestion for a getHtmlFromSelection? |
Perhaps this will help (add it in firepad.js somewhere): Firepad.prototype.getOperationForSpan = function(start, end) { You can use that to create a TextOperation representing the span, and then If you can get something working, I'd be thrilled with a pull request. :-) On Thu, Nov 14, 2013 at 11:50 AM, Clément Wehrung
|
I'm very curious if anyone has worked on this... Google Docs handles it so well, I think now the user expectation is that this work. We're using firepad inside an app, and so are very interested. |
I think @iclems made progress on this at one point. Hopefully he'll chime in. :-) |
Thanks Michael. On Wed, Oct 8, 2014 at 6:24 PM, Michael Lehenbauer <[email protected]
Brian Burt Leader in Social Conferencing We are the leading technology for hosting real conversations at large |
You’ll find here a quick example of how to do it: https://gist.github.com/iclems/31b44bb7aba9bf7713a8 Note that if you use entities, you probably need some additional processing, etc. Clément On Fri, Oct 10, 2014 at 12:38 AM, brianburt [email protected]
|
Thanks -- I just looked at that Gist and couldn't quite figure how to integrate it. I was able to update it with correct references to my firepad and codeMirror instances, but choked on the "LineSentinelCharacter+EntitySentinelCharacter" variables. Any suggestions? Thanks -- this would be a really awesome feature to have |
@nickgrossman (and/or @brianburt), I'd be happy to try to help with this (and eventually submit a pull request), since I'd like the same feature in Firepad. But |
The gist does work fine. Though, you can actually improve it by setting a private mime type for Firepad to distinguish copy/paste within a firepad or from outside. When a paste comes from outside, you may need to perform additional cleanup before trying to insert the pasted HTML or text. Also, some entities may require to be able to perform some specific tasks when being inserted through a paste. Think of a paste of rich text which includes images: in this scenario, the clipboard should contain an HTML version of the rich text (at least on Mac), though you'll probably need to upload the base64 or image URL to your server to store it, and get a token to store in Firepad, etc. Hence, it would take some work to figure a really generic implementation of copy/paste for rich text that would work in every case and have full support for entities. |
@iclems, thanks for this additional info. It sounds much easier to just preserve basic styling, and that is what's high-priority for my use case, so I'm planning to try to get that to work (and fix #199), and after that we'll see (maybe splitting off a separate issue for going farther will make sense). One question about your gist: does the ios case (shown below) work correctly, or does it always copy the entire input element? (I am not familiar with web programming, so I am just guessing the details of the DOM interface used below when assigning to node.selectionEnd, etc.)
|
…the August posted work on github to use a rtf cut and paste that actually maintains formatting. here is the link on git hub to the working code that is currently being imported for a pull, hopefully.... source: with other good links FirebaseExtended/firepad#35 specific link (last year) https://gist.github.com/iclems/31b44bb7aba9bf7713a8 recent comments: FirebaseExtended/firepad#199 I am going to do my best to impliment a direct feed of text to our word array creator, and keep formatting... huge plus
Hi, iclems gist above does not work anymore for several reasons
The code below shows a solution to these problems:
See code example in rich text can be copied/cut/pasted inside FP and from/to a richpad document (ie gmail msg) consider adding lineWiseCopyCut:false to CM options to prevent cut without selection This was tested in IE9-11, FF and Chrome Note that for some reason this does not work when chrome developer tools is opened. I am working towards a PR for this. Any feedback appreciated Code:
|
@kofifus and Firepad team. I've implemented this and while it works, the editor freezes on insert of more than a couple lines. After doing some digging in the Chrome Profiler it seems that its the internals of Firepad causing the extreme slowness. Here is a screenshot of my profiler: Happy to send you guys my CPU profile from Chrome. Is this a known issue or am I doing something wrong here? |
Hrm. I don't see anything obvious from that screenshot. Looks like the bulk of the expanded time actually ends up in markText(), which is a CodeMirror API... but maybe firepad is doing something inefficient in how it's using the API. I'm not sure when I'll have time to dig into this, but any chance you could provide a pull request or jsfiddle or something that has your changes so I can debug / profile myself? That'd probably be most useful. |
Hi Daniel, Thank you for the feedback !
I will investigate further |
@mikelehen will try to get any changes i've made on Firepad internal into a pull request or something similar. Edit: The slow initial load is based on how much of the actual document your rendering in CodeMirror. Basically, don't use My original issue with copy paste (which uses |
@kofifus realized I never answered your questions:
My next place to look will be in the places where Firepad subscribes to CodeMirror events. In my fork of Firepad i've added Also interested in seeing if its possible to batch |
I opened #229 |
You can use cm.operation around markText. I've done it in a different use
|
Hrm. Definitely interesting that the setHtml is taking longer than initial load. That probably suggests there's some improvement that could be made like wrapping it in a CodeMirror operation as Beni suggested. |
@mikelehen ill probably have some time today or tomorrow to test this theory out. Will report back and see if theres any substantial gain from doing this. |
@mikelehen, @kofifus reporting back. Wrapping Update: finally got my browser not to crash. Here are the numbers:
So, yeah. Much better wrapped in an operation. |
Awesome, thanks for reporting back! Would love to see that PR if/when you On Tue, Feb 9, 2016 at 10:06 AM, Daniel Schwartz [email protected]
|
great daniel ! can you post an updated version of the fiddle from my solution above ? (http://jsfiddle.net/radcct7e/) |
Updated: http://jsfiddle.net/radcct7e/3/ |
daniel, speed issue is now "solved" with d0459a8 updated firepad.js with this fix is in https://github.com/firebase/firepad/blob/master/examples/firepad.js |
Awesome! Super fast turn around on both the PR and acceptance. Thanks! Daniel Schwartz On Thu, Feb 11, 2016 at 8:42 PM Kofifus <
daniel, speed issue is now solved with — Reply to this email directly or |
Hi All-- This is exciting! (for some reason the other notifications on this thread I will take a look at this. Thanks everyone for the effort! Best, On Monday, February 15, 2016, Kofifus [email protected] wrote:
http://nickgrossman.is | @nickgrossman http://twitter.com/nickgrossman |
Hello everyone! |
Hey domalak, daniel's fiddle is based on mine above which has been improved a lot and submitted as a PR - pls see #237 |
oh thanks a lot @kofifus |
Are we going to mark this issue as closed? |
Probably not until #237 is merged and I'm swamped at the moment. Sorry! |
clipboard manipulation in browsers is difficult and not well documented/supported (for example as far as I could tell not feasible in IE), any help with testing will be greatly appreciated. The PR was only tested in Chrome and FF but there may be issues with safari/phones/tablets or with some formatting combinations. |
CodeMirror 5.12 now supports copy & cut events which makes the firepad code simpler. I have updated the #237 accordingly and also enhanced some styles support. New plnkr in http://plnkr.co/edit/fMroiV79FvkCJF590dpj Obviously you need CodeMirror 5.12 .. Hope this helps |
When can we see this in main repo? |
Sorry, I'm not sure. I'm a little nervous about the change and haven't had time to do a detailed review / testing. If people can use #237 for now and chime in to let me know how it's working and whether they've hit any issues, that would help some. :-) |
yeah #237 is definitely a complicated PR .. I would really appreciate more people testing ... it seems to work great on chrome/firefox/safari desktops, didn't really test much on mobiles ... I tried to make it so it reverts to default behavior in places where the clipboard api is not supported |
I'm going to use #237 in my test environment; will update here if come across any issue |
There are three discussions here:
The text was updated successfully, but these errors were encountered: