How to send code fragment back to main editor?

I clicked inside a JavaScript fragment inside my main XML document, clicked the Lightbulb, and chose "Edit JavaScript Fragment" which openned it in a separate window. Made a couple changes; now how do I sent it back to the main editor once I'm done editing the fragment? My main window is never getting updated.

Would really like to use this feature, as it fixes up the > XML entities so it's not such a pain to write embedded JS!

8 comments
Comment actions Permalink

Hi mark,

Could you please provide an example of such file. As far as I'm aware it should send new fragment back as you edit it -- at least it works like that when I'm editing SQL block inside PHP.

0
Comment actions Permalink

Okay... I managed to narrow it down. It seems to happen when there is an XML entity in the JavaScript. In the file I've attached, click inside the "onchange" attribute and inject JavaScript, then try editing it. Happens in PS-110.518.



Attachment(s):
test.xml
0
Comment actions Permalink

Okay... I managed to narrow it down. It seems to happen when there is an XML entity in the JavaScript. Example:

<form>
    <input onchange="myFunction('aaaa&amp;amp;bbb');" />
</form>



Click inside the "onchange" attribute, then inject JavaScript and then try editing the fragment.


As an aside, is there a quicker way to access this "edit fragment" feature, perhaps a hotkey?

Edit: Your forums converted my ampersand entity into the ampersand character, despite it being in a code block! Double encoding it this time...

Edit2: Here's the stack trace ;)

Range: (1,28) in text: '"myFunction('aaaa&amp;bbb');"': String index out of range: -11

java.lang.StringIndexOutOfBoundsException: String index out of range: -11
     at java.lang.String.substring(String.java:1937)
     at com.intellij.psi.impl.source.resolve.reference.impl.manipulators.XmlAttributeValueManipulator.handleContentChange(XmlAttributeValueManipulator.java:56)
     at com.intellij.psi.impl.source.resolve.reference.impl.manipulators.XmlAttributeValueManipulator.handleContentChange(XmlAttributeValueManipulator.java:40)
     at org.intellij.plugins.intelliLang.inject.quickedit.QuickEditAction$MyHandler.commitToOriginalInner(QuickEditAction.java:375)
     at org.intellij.plugins.intelliLang.inject.quickedit.QuickEditAction$MyHandler.access$900(QuickEditAction.java:151)
     at org.intellij.plugins.intelliLang.inject.quickedit.QuickEditAction$MyHandler$4$1.run(QuickEditAction.java:331)
     at com.intellij.psi.impl.source.PostprocessReformattingAspect$2.compute(PostprocessReformattingAspect.java:101)
     at com.intellij.psi.impl.source.PostprocessReformattingAspect.disablePostprocessFormattingInside(PostprocessReformattingAspect.java:110)
     at com.intellij.psi.impl.source.PostprocessReformattingAspect.disablePostprocessFormattingInside(PostprocessReformattingAspect.java:98)
     at org.intellij.plugins.intelliLang.inject.quickedit.QuickEditAction$MyHandler$4.run(QuickEditAction.java:328)
     at com.intellij.openapi.command.WriteCommandAction$Simple.run(WriteCommandAction.java:171)
     at com.intellij.openapi.application.RunResult.run(RunResult.java:37)
     at com.intellij.openapi.command.WriteCommandAction$2$1.run(WriteCommandAction.java:122)
     at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:880)
     at com.intellij.openapi.command.WriteCommandAction$2.run(WriteCommandAction.java:120)
     at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:112)
     at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:88)
     at com.intellij.openapi.command.WriteCommandAction.performWriteCommandAction(WriteCommandAction.java:118)
     at com.intellij.openapi.command.WriteCommandAction.access$000(WriteCommandAction.java:34)
     at com.intellij.openapi.command.WriteCommandAction$1.run(WriteCommandAction.java:73)
     at com.intellij.openapi.command.WriteCommandAction.execute(WriteCommandAction.java:78)
     at org.intellij.plugins.intelliLang.inject.quickedit.QuickEditAction$MyHandler.commitToOriginal(QuickEditAction.java:325)
     at org.intellij.plugins.intelliLang.inject.quickedit.QuickEditAction$MyHandler.access$100(QuickEditAction.java:151)
     at org.intellij.plugins.intelliLang.inject.quickedit.QuickEditAction$MyHandler$2$1.run(QuickEditAction.java:197)
     at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:333)
     at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
     at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
     at java.awt.EventQueue.access$000(EventQueue.java:84)
     at java.awt.EventQueue$1.run(EventQueue.java:602)
     at java.awt.EventQueue$1.run(EventQueue.java:600)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
     at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
     at com.intellij.ide.IdeEventQueue.e(IdeEventQueue.java:686)
     at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:534)
     at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:416)
     at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:374)
     at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
     at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
     at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
0
Comment actions Permalink

Here is the ticket: http://youtrack.jetbrains.net/issue/WI-1732?projectKey=WI

If you remove ampersand, so no special characters/encode characters found in fragment (e.g. "myFunction('aaaaddddbbb');" ), then it works (updates main document) as intended.

0
Comment actions Permalink
As an aside, is there a quicker way to access this "edit fragment" feature, perhaps a hotkey?

No (I'm not 100% sure .. but close to it) as this is "Intention" and not "Action". If there would be any -- loook at File | Settings | Keymap .. but I see none here.

0
Comment actions Permalink

Ah, thanks. Hasn't been touched in 19 months though :(

0
Comment actions Permalink

I found it, you have to use

 

  • PsiFileFactory#createFileFromText(fileName, HTMLLanguage.INSTANCE, "..."

 

instead of 

 

  • PsiFileFactory#createFileFromText(fileName, HTMLFileType.INSTANCE, "..."

 

Apparently the editor switches to some reduced mode if you create a document from a psi file which just has a html file type. 

0
Comment actions Permalink

Sorry for the comment it was meant for another topic

0

Please sign in to leave a comment.