Skip to content
This repository has been archived by the owner on Apr 10, 2021. It is now read-only.

paste - undo - redo combination causes a weirdly formatted file #87

Open
FinBoWa opened this issue Sep 18, 2015 · 14 comments
Open

paste - undo - redo combination causes a weirdly formatted file #87

FinBoWa opened this issue Sep 18, 2015 · 14 comments

Comments

@FinBoWa
Copy link

FinBoWa commented Sep 18, 2015

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.

@Yserz
Copy link
Member

Yserz commented Sep 18, 2015

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

@FinBoWa
Copy link
Author

FinBoWa commented Sep 21, 2015

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.

@Yserz Yserz closed this as completed in 83a5766 Oct 4, 2015
@Yserz
Copy link
Member

Yserz commented Oct 4, 2015

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 Yserz reopened this Oct 4, 2015
@FinBoWa
Copy link
Author

FinBoWa commented Oct 5, 2015

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.

@Yserz
Copy link
Member

Yserz commented Oct 5, 2015

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 :)

@FinBoWa
Copy link
Author

FinBoWa commented Oct 6, 2015

@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
Copy link
Author

FinBoWa commented Oct 6, 2015

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.

@Yserz
Copy link
Member

Yserz commented Oct 6, 2015

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 added a commit that referenced this issue Oct 6, 2015
@Yserz
Copy link
Member

Yserz commented Oct 6, 2015

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.

@Carlgo11
Copy link

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

@Chris2011
Copy link
Contributor

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

@ghost
Copy link

ghost commented Dec 13, 2017

Have same issues with version 0.10.3, on Java file.

@Chris2011
Copy link
Contributor

Could be related to this too: #111

@Chris2011
Copy link
Contributor

Smth new here?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants