editorconfig-netbeans icon indicating copy to clipboard operation
editorconfig-netbeans copied to clipboard

paste - undo - redo combination causes a weirdly formatted file

Open FinBoWa opened this issue 9 years ago • 14 comments

This happens at least on PHP projects with the latest version and not always.

Steps to repro:

  1. open file for example an xml file
  2. paste something to it, preferably a block with the wrong indentation
  3. save
  4. undo
  5. save

You are likely to end up a file that displayed with broken indentations.

FinBoWa avatar Sep 18 '15 06:09 FinBoWa

Hey, thx for reporting! Can you post a picture of that bug?

Yserz avatar Sep 18 '15 18:09 Yserz

Below is what happens:

formatting-bug

File used for demoing the issue is an layout configuration xml file from Magento. But this behavior will happen on php files also.

After the file gets mall formatted you can't undo it back to a working state.

Frankly I had problems on getting the issue to fire but saving with redoing / undoing changes and saving will cause a file to break.

FinBoWa avatar Sep 21 '15 07:09 FinBoWa

Hey, I couldn't reproduce this issue but I committed some code which fixes a possible cause for this. Would you mind to try out the fix from the sources?

Yserz avatar Oct 04 '15 10:10 Yserz

Tried to open the project form the sources but probably missing some necessary bits on my netbeans

 Some problems were encountered while processing the POMs:
 [ERROR] Unresolveable build extension: Plugin org.codehaus.mojo:nbm-maven-plugin:3.13 or one of its dependencies could not be resolved: The following artifacts could not be resolved: org.codehaus.mojo:nbm-maven-plugin:jar:3.13, org.codehaus.plexus:plexus-utils:jar:1.1: The repository system is offline but the artifact org.codehaus.mojo:nbm-maven-plugin:jar:3.13 is not available in the local repository. 

Any tips as I'll probably try again in the next 24 hours.

FinBoWa avatar Oct 05 '15 07:10 FinBoWa

I guess you had no internet :P That's mandatory for maven to get the related dependencies. Another option is that the repository for plexus-utils 1.1 was down for a while. This version number actually reminds me that we could update some dependencies but that's another story :)

Yserz avatar Oct 05 '15 18:10 Yserz

@Yserz I just neglegted to press the "resolve" button on the "Resolve Project problems" :)

Im presuming that I got the build to install the updated version and I get the issue much easier now.

Presumably this error relates to the issue:

java.lang.NullPointerException at com.welovecoding.nbeditorconfig.processor.FileInfo.lambda$null$2(FileInfo.java:46) at com.welovecoding.nbeditorconfig.processor.FileInfo$$Lambda$38/2072241570.run(Unknown Source) at org.netbeans.editor.GuardedDocument.runAtomic(GuardedDocument.java:323) at org.openide.text.NbDocument.runAtomic(NbDocument.java:436) at com.welovecoding.nbeditorconfig.processor.FileInfo.lambda$getCaret$3(FileInfo.java:45) at com.welovecoding.nbeditorconfig.processor.FileInfo$$Lambda$37/1724303092.run(Unknown Source) at com.welovecoding.nbeditorconfig.processor.FileInfo.getCaret(FileInfo.java:50) at com.welovecoding.nbeditorconfig.io.writer.StyledDocumentWriter.writeWithEditorKit(StyledDocumentWriter.java:126) at com.welovecoding.nbeditorconfig.processor.WriteEditorAction.run(WriteEditorAction.java:26) at org.openide.filesystems.EventControl.runAtomicAction(EventControl.java:127) at org.openide.filesystems.FileSystem.runAtomicAction(FileSystem.java:641) at org.openide.filesystems.FileUtil.runAtomicAction(FileUtil.java:431) at com.welovecoding.nbeditorconfig.processor.EditorConfigProcessor.lambda$null$0(EditorConfigProcessor.java:253) at com.welovecoding.nbeditorconfig.processor.EditorConfigProcessor$$Lambda$42/1751159954.run(Unknown Source) at org.netbeans.editor.GuardedDocument.runAtomic(GuardedDocument.java:323) at org.openide.text.NbDocument.runAtomic(NbDocument.java:436) at com.welovecoding.nbeditorconfig.processor.EditorConfigProcessor.lambda$updateChangesInEditorWindow$1(EditorConfigProcessor.java:251) at com.welovecoding.nbeditorconfig.processor.EditorConfigProcessor$$Lambda$41/492807662.run(Unknown Source) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:749) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:702) at java.awt.EventQueue$3.run(EventQueue.java:696) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.awt.EventQueue.dispatchEvent(EventQueue.java:719) at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159) [catch] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

FinBoWa avatar Oct 06 '15 11:10 FinBoWa

Hopefully with this you can repro the issue if you use this file:

https://gist.github.com/FinBoWa/dd0034fbd516977e527d

Open that file in a php project.

  1. copy a whole block to the clib board. for example the first node you see
  2. paste that to a logical place
  3. save
  4. undo

It will break the presentation of the document.

If it doesn't happen on the first undo try, just paste the same block again. Also closing and reopening and then doing undo save should start causing issues.

I actually got it to eat ALL the contents of the xml file now.

Not sure does this happen with a project that contains only few files.

FinBoWa avatar Oct 06 '15 11:10 FinBoWa

Sounds like I made it even worse :o The main issue is with the ´StyledDocumentWriter´ right here ´com.welovecoding.nbeditorconfig.io.writer.StyledDocumentWriter.writeWithEditorKit(StyledDocumentWriter.java:126)´. It seems someone else is writing to the file while we are writing. Are you using Win, Mac or Linux?

Yserz avatar Oct 06 '15 18:10 Yserz

I pushed a pretty raw fix for this issue. It will fire exceptions but at least it will not break the file. Unfortunately I don't have time to investigate into this in more detail today :( If you encounter exceptions when clicking somewhere in the lower end of the document closing and reopening of the document helps.

Yserz avatar Oct 06 '15 21:10 Yserz

@Yserz That didn't fix it. I have the same issue.

Carlgo11 avatar Oct 31 '16 00:10 Carlgo11

Same issue, I tested a JSON file. It is really weird.

Chris2011 avatar Nov 08 '17 16:11 Chris2011

Have same issues with version 0.10.3, on Java file.

ghost avatar Dec 13 '17 07:12 ghost

Could be related to this too: https://github.com/welovecoding/editorconfig-netbeans/issues/111

Chris2011 avatar Dec 13 '17 08:12 Chris2011

Smth new here?

Chris2011 avatar Jun 06 '18 06:06 Chris2011