Topic on Extension talk:CodeMirror

Seudo (talkcontribs)

Hello,

Apparently, CodeMirror creates another textarea which ID is not "w p Textbox1" (I add spaces because a stupid spam filter rejects my message otherwise). Therefore any customization of gadget that is based on that ID will not work with CodeMirror. Am I correct?

It took me quite a while to understand that a few days ago when the user interface was suddenly broken because of the activation of CodeMirror (I guess I accidentally clicked on a small pencil in the toolbar and thus activated this extension, which I knew nothing about).

Of course I deactivated CodeMirror as soon as I understood what was happening, but code hightlighting might be useful, so is there any way to maintain Javascript customizations in the editing field? When I read the source code, I cannot see any ID in the various DIVs used by CodeMirror. Thanks.

NKohli (WMF) (talkcontribs)

You're quite right. I don't see any IDs either. Will class="CodeMirror" work for your use case? Although CodeMirror chunks out the text into a lot of divs and spans so performing any sort of operations on the text would be very challenging.

Seudo (talkcontribs)

Thanks. So I'll keep CodeMirror deactivated for now and hope the good old textarea will not disappear...

TheDJ (talkcontribs)

I'm not sure what kind of customizations you are doing, but if you are changing the value of the textarea, it sounds like you should be using the jquery.textSelection module.

Seudo (talkcontribs)

For example I replace $oe with œ (and use other replacements to insert characters that are not easy to find in the keyboard, which is useful when editing old French texts in Wikisource). I don't think the textSelection module would be useful since I want the replacement to occur immediately (in the onkeyup event).

When I see the documentation of this module, I guess jquery.textSelection is one of the many modules that won't work in combination with CodeMirror, since it works with textareas.

Jack who built the house (talkcontribs)

Seudo, you should work with $('#wpTextbox1'), just use .textSelection() method for it. As I understand, CodeMirror emulates #wpTextbox1, and changes made to it are automatically transmitted to CodeMirror.

See what we did in ruwiki. At the bottom, you can find a code for the new wikitext editor also.

.val() for $('#wpTextbox1') works too. The only thing which we in ruwiki need that doesn't work is focus/blur jQuery events. I've created phab:T197632 for that.

Seudo (talkcontribs)

You're right, I tried using the textSelection API and now my customizations work even when activating CodeMirror. Thanks !

Seudo (talkcontribs)

At least I thought it worked. In some parts of Wikisource, $('#wpTextbox1').val() and $('#wpTextbox1').textSelection('getContents') do not return the same thing because some hidden text is added in the place where textSelection stores its value...

But this is not a CodeMirror problem and it's probably Wikisource-specific, so I'll try somewhere else. Thanks for the help!

Reply to "wpTextbox1"