On 6/9/22 6:52 AM, Laszlo Kishalmi wrote:
You might also check how the editor handles the reload, and try to improve the caret persistence situation.

Laszlo, your pointer into CloneableEditorSupport saved lots of time, thanks. The key discovery is that during reload, "getPositionManager().documentOpened(openClose.docRef)" is used to adjust/fixup "org.openide.text.PositionRef"; PositionRef is an implementation of swing.text.Position that come from CES.createPositionRef. The positionManager handles adjusting PositionRef's from the old document to the new document. There is support for persisting PositionRef's.

jVi is swing based, runs standalone, and produces a jar which includes handling the persistence of regular swing posistions; the jar is used by the NetBeans layer. I'd never heard of a PositionRef, overriding jVi to use CES.createPositionRef fixed the jVi problem with reload.

Also, I can now confirm by observation that the CES.PositionRef maintains line/column, not offset, between old and new. If the number of lines is changed, then the positionRef is wrong by that number of lines; if the length of lines is changed, then the positionRef is correct.

In DocumentOpenClose around line 761 there is code to preserve caret positions; this code uses positions from Document.createPosition, not positions from CES. It also seems to be using offset. This may be related to the problems with caret positions that you mention. I'm not exactly sure what observed behavior you were referring to.

All these classes are in platform/openide.text/src/org/openide/text

Assuming there is a CES.RELOADED event; this is a way to save/restore line/col with caret
1)  FILE CHANGE EVENT
    create PositionRef for each caret's position
2)  CES.RELOADED EVENT
    restore caret position from PositionRef saved in 1).

Note that there is usually many saves in a row from 1). Restore is only done rarely with 2).

In any event, it sure seems like a CES.RELOADED EVENT is missing. Could it be that the reload code was a later addition and didn't get event representation. Or maybe thought that things could be handled transparently (famous last words).

Changing how caret is restored would be a behavioral change, but maybe that would be OK.

Below are all the events from FileObject, DataObject, CloneableEditorSupport. In the 2nd, changing with the editor, the first events are when a character is added to the file, the last events are when the file is written. The sequence of events ends with a FILE OBJECT EVENT.

In the 1st, external change, the only event is a FILE OBJECT EVENT. The stack trace shows that it is from a Watcher thread. Events starts with the FILE OBJECT EVENT.

======================= external change

FILE OBJECT EVENT: BaseFileObj$FileEventImpl[... ,expected=false]

"Pending refresh :: FILE_CHANGED /src/nb/NetBeansProjects/JavaLibrary1/src/play/NewClass.java"         at org.netbeans.modules.jvi.impl.NbBuffer$FoListen.fileChanged(NbBuffer.java:170)
        ...
>>>     at org.openide.filesystems.FileObject.refresh(FileObject.java:1233)
        at org.netbeans.modules.masterfs.watcher.Watcher$1.run(Watcher.java:415)         at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1418)         at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
        at org.openide.util.lookup.Lookups.executeWith(Lookups.java:278)
        at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)


======================= modify/write with editor


CES EVENT: java.beans.PropertyChangeEvent[propertyName=modified;
                oldValue=false; newValue=true; ]
DATA OBJECT EVENT: java.beans.PropertyChangeEvent[propertyName=modified;
                oldValue=false; newValue=true; ]
DATA OBJECT EVENT: java.beans.PropertyChangeEvent[propertyName=cookie ]
DATA OBJECT EVENT: java.beans.PropertyChangeEvent[propertyName=cookie ]
CES EVENT: java.beans.PropertyChangeEvent[propertyName=modified;
                oldValue=true; newValue=false; ]
DATA OBJECT EVENT: java.beans.PropertyChangeEvent[propertyName=modified;
                oldValue=true; newValue=false ]
FILE OBJECT EVENT: BaseFileObj$FileEventImpl[... ,expected=false]

"AWT-EventQueue-0 :: FILE_CHANGED /src/nb/NetBeansProjects/JavaLibrary1/src/play/NewClass.java"     at org.netbeans.modules.jvi.impl.NbBuffer$FoListen.fileChanged(NbBuffer.java:170)
    ...
    at org.openide.text.DataEditorSupport.saveDocument(DataEditorSupport.java:568)     at org.netbeans.modules.openide.loaders.SimpleES$SaveCookieImpl.save(SimpleES.java:202)




On 6/7/22 18:17, Ernie Rael wrote:
Hi all,

When NetBeans detects that a file has been changed externally, it updates the file. When this happens, my plugin usually /looses/ its javax.swing.text.Positions; they go to offset 0.

How can I get notified or detect that this is about to happen so I can try to preserve the marks. Notification that it just happened would be better than nothing.

Any hints on how to do this, or suggestions on where to look?

Thanks,
-ernie


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@netbeans.apache.org
For additional commands, e-mail: dev-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@netbeans.apache.org
For additional commands, e-mail: dev-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists






---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@netbeans.apache.org
For additional commands, e-mail: dev-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists



Reply via email to