danhper / atomic-chrome

Edit Chrome textareas in Atom
https://goo.gl/Et0hwg
MIT License
916 stars 30 forks source link

Cannot edit ACE Editor inputs #1

Closed dlitvakb closed 8 years ago

dlitvakb commented 8 years ago

Extension does not work for https://gist.github.com

danhper commented 8 years ago

Thanks for reporting, I am going to check it out!

jtokoph commented 8 years ago

Seems ok to piggy back on this issue to say that it doesn't work with CodeMirror either: https://codemirror.net/

danhper commented 8 years ago

Yep, it seems that the normal TextareaHandler cannot be used for codemirror and ace, so I am going to add special handlers for these. Thank you for the report.

dlitvakb commented 8 years ago

This is probably more accurate to be named "Cannot edit ACE Editor inputs"

oxguy3 commented 8 years ago

Very excited to hear this bug is working on -- replacing the awful editor on GitHub Gists is definitely my #[]()1 use case for this plugin.

danhper commented 8 years ago

I am working on this issue in the support-ace-editor branch, but I am not really sure why the first call to editor.getValue() returns some weird value. If anyone familiar with ace would like to give it a look, it would be very nice!

jtokoph commented 8 years ago

If i load up gist.github.com or ace.c9.io, I'm able to run this in the console and get the value on the first call:

ace.edit(document.activeElement.parentElement).getSession().getValue()

jtokoph commented 8 years ago

And for codemirror:

document.activeElement.parentElement.parentElement.CodeMirror.getValue()

The CodeMirror element we eventually follow the ancestry too has the class CodeMirror by default I think.

danhper commented 8 years ago

@jtokoph Thank you very much for your help.

Actually, it is a little more tricky than this here. In both cases, this requires to use JS variables from the page, but as Chrome plugins run in sandboxed environment, it is not possible to access them directly, so what would work in the console will not work in the plugin. I thought it could work by adding ace to the plugin, but it seems that ace keeps some state when initializing editors, so ace.edit creates a new editor instead of using the existing one.

I think the simplest way to do this is to inject a script in the main page and send the actual CodeMirror, or ace editor back to the plugin. I am going to see if this approach works.

If anyone has an alternative solution, I am of course opened.

danhper commented 8 years ago

I got a very basic prototype working in the support-ace-editor branch, so I think I should be able to get this working by the end of the week. The approach is to inject a script in the host page and add an extra layer of message passing to get the value from the host page to the content-script.

danhper commented 8 years ago

@dlitvakb @jtokoph Thanks for the feedback and the help. From 0.1.0, it should now work with ace and codemirror. I would love if you could give it a try and give some feedback if you have any.

jtokoph commented 8 years ago

Works like a charm for both! Thanks so much for the extension!

danhper commented 8 years ago

Great, glad you like it! :smile: