calling getHtmlFromSelection

27 views
Skip to first unread message

Mika Genic

unread,
Dec 23, 2015, 9:56:35 PM12/23/15
to Firepad
I am working towards a PR for rich text copy/cut/paste and need some help with this last hurdle

I am having problems invoking getHtmlFromSelection (and insertHtmlAtCursor) from within a RichTextCodeMirror event handler 

In:
   function RichTextCodeMirror(codeMirror, entityManager, options) {

I tried:
    codeMirror.getWrapperElement().addEventListener('copy', function(e) { 
       var html1=getHtmlFromSelection();
       var html2=self.getHtmlFromSelection();
       var html3=firepad.getHtmlFromSelection();
     });

However all these calls to getHtmlFromSelection return 'is not a function'

What's the proper way to do this ?

Michael Lehenbauer

unread,
Jan 2, 2016, 7:58:45 PM1/2/16
to Mika Genic, Firepad
Hrm.  It seems like the last one should work:

       var html3=firepad.getHtmlFromSelection();


Assuming "firepad" is a valid firepad reference.

--
You received this message because you are subscribed to the Google Groups "Firepad" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firepad-io+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firepad-io/1e821882-e60e-49d0-8251-11df17553d55%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mika Genic

unread,
Jan 3, 2016, 9:01:20 PM1/3/16
to Firepad, mika...@gmail.com
No it does not :(

In:

function RichTextCodeMirror(codeMirror, entityManager, options) {

I added:

this.codeMirror.getWrapperElement().addEventListener('copy', function(e) { 
      firepad.getHtmlFromSelection();
});

If I set a breakpoint before the getHtmlFromSelection I can see that firepad is defined but does not have the getHtmlFromSelection()

Is this function private in some way ?

Would really appreciate some help here thx!


  

Michael Lehenbauer

unread,
Jan 4, 2016, 10:04:10 AM1/4/16
to Mika Genic, Firepad
Yeah, that's the internal firepad namespace (that is used to hang all of the internal classes off of).  You're looking for an instance of the Firepad class...

You're probably going to need to move your code from rich-text-codemirror.js into firepad.js (in which case you'll be working in the Firepad class which has the getHtmlFromSelection() method so you can just do this.getHtmlFromSelection(...)).

Good luck,
-Michael


--
You received this message because you are subscribed to the Google Groups "Firepad" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firepad-io+...@googlegroups.com.

Clement Wehrung

unread,
Jan 4, 2016, 10:26:38 AM1/4/16
to Michael Lehenbauer, Mika Genic, Firepad
FYI, it may be harder than it seems to come up with a full solution for copy-paste as entities support creates more complex cases: for instance, when a user pastes an image, you probably need to first upload the image to some server, etc. Hence, if copy-paste becomes officially supported in Firepad, it should be possible to opt out in some cases. 

Message has been deleted

Mika Genic

unread,
Jan 4, 2016, 3:45:26 PM1/4/16
to Firepad, mic...@firebase.com, mika...@gmail.com
Thank you Michael and cwehrung 

Please see my solution (as kofifus) in the end of https://github.com/firebase/firepad/issues/35 - this is the code I am thinking of integrating into FP itself

Michael - can you recommend a place (ie a function) in firepad.js which will be a good point put in the three handles:

    codeMirror.getWrapperElement().addEventListener('copy', function(e) { ...
    codeMirror.getWrapperElement().addEventListener('cut', function(e) { ...
    codeMirror.on('paste', ...

so that they will have access to firepad internal functions ?

cwehrung - you are right imges are a special case and harder to copy/cut/paste. I guess for that functionality they will have to be encoded into json somehow. Have a look at my code, perhaps you can help solve this ? 

Thx!

Michael Lehenbauer

unread,
Jan 4, 2016, 4:21:53 PM1/4/16
to Mika Genic, Firepad
That code actually doesn't require any firepad internal functions.  It was written to be executed outside Firepad, I think.  But you should be able to put it in the Firepad constructor in firepad.js (changing codemirror to this.codeMirror_, firepad to this, etc.).

I'd perhaps put it inside the "if (this.getOption('richTextShortcuts', false))" block since it only applies to rich-text editing.

-Michael
Reply all
Reply to author
Forward
0 new messages