You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In most editors in Eclipse (e.g., the Java editor), one can "clone editor" and end up with two editors to the same file (especially useful for editing different parts of the same file). In this application, using "clone editor" ends up with separate instances or something such that making changes in one editor instance are not reflected in other. Furthermore, it makes it such that one cannot switch editor instances if one has saved in one of them as the other is out of sync with the file system.
Hi,
Any solution or WA for this annoying bug? It indeed doesn't happen in simple text or Java editor but it does happen in editors of other plugins.
What surprises me is that this is basic Eclipse framework feature, how it's behavior changes when working on different editor types?
@jumbos87 I think some of the changes inside the editor has this effect- it extends basic editor class which does not have the problem. Maybe it's is something with the underlying document.
When you have the issue - a workaround is always just to save the content before switching to cloned part - so it's in snyc. Currently I am extreme busy, but I will try to fix this on next milestone.
I'm asking because I'm developing my own plugin based on another open-source plugin, so if you'll find a clue as to what which class/function causes the issue I would appreciate if you share.
Thanks.
After some investigation I found out that the problem is the usage of different document providers. I created a very simple editor plugin, which does extend text editor and does nothing special except following:
So setting a new document provider for every editor is the problem.
From documentation of IDocumentProvider:
... Text editors use document providers to bridge the gap between their input elements and the documents they work on. A single document provider may be shared between multiple editors; the methods take the editors' input elements as a parameter. ...
Debug information
SimpleTextEditor without setting document provider in constructor, a cloned, or splitted editor (CTRL +_ ) calls setDocumentProvider(IEditorInput input) twice where resolved document provider was both times same instance - in my case org.eclipse.ui.editors.text.TextFileDocumentProvider@66ee4640 and synchronization works out of the box.
What about Example codes
Normally eclipse plugin developers create (at least) their first plugins by the eclipse plugin project wizard, so what about the examples... ?
and creating an example plugin with project wizard and creating the default XML Editor the problem exists:
The example - and most other editors - do set a document provider inside constructor, so every editor has got its own document provider:
So I will create an issue at https://bugs.eclipse.org/bugs/ - the generated examples should not have problems with clone / split editor function
Solution
Either provide a shared document provider for all instances, or decide on editor input which document provider has to be used and reuse same provider between editors for same input.
@de-jcup you're the man!
I found the setDocumentProvider in my constructor as well and indeed after comment out, the splitted editors are in sync and work like magic.
However, I'll need to uncomment it because my provider creates my extended Document and I can't use the default Document that Eclipse creates by default. So, like you said, I need to reuse same provider if same file is already open. Need to think of a robust way to do it.
Thanks a lot!
Either provide a shared document provider for all instances, or decide on editor input which document provider has to be used and reuse same provider between editors for same input.
I fixed the code to use a static provider in my extended TextEditor class, so it is shared for all instances. Do you see any reason to reuse provider based on same input (instead of one for all)?
In most editors in Eclipse (e.g., the Java editor), one can "clone editor" and end up with two editors to the same file (especially useful for editing different parts of the same file). In this application, using "clone editor" ends up with separate instances or something such that making changes in one editor instance are not reflected in other. Furthermore, it makes it such that one cannot switch editor instances if one has saved in one of them as the other is out of sync with the file system.
So normally on every call the provider is given input as a parameter.
The only reason I am using 2 different (but also shared) providers is, because I handle some input types different, but these are always handled in same way on cloned editors.
IMHO it is not necessary to lookup for same input and map to dedicated provider (to reuse) - per definition a provider is stateless (as far as I know).
Activity
de-jcup commentedon Jun 5, 2020
As long as editor changes are saved inside editor where changes are made, both editors are in sync.
But when you do following:
Then we have a sync problem shown as a message dialog in eclipse:
This happens also for "Toggle split editor vertical/horizontal" and not only for clone editor action - next example shows this for a vertical split:
So after next save a dialog appears:
de-jcup commentedon Jun 5, 2020
For normal text editor all changes are directly changed into cloned instance without any safe:
jumbos87 commentedon Jun 16, 2020
Hi,
Any solution or WA for this annoying bug? It indeed doesn't happen in simple text or Java editor but it does happen in editors of other plugins.
What surprises me is that this is basic Eclipse framework feature, how it's behavior changes when working on different editor types?
de-jcup commentedon Jun 18, 2020
@jumbos87 I think some of the changes inside the editor has this effect- it extends basic editor class which does not have the problem. Maybe it's is something with the underlying document.
When you have the issue - a workaround is always just to save the content before switching to cloned part - so it's in snyc. Currently I am extreme busy, but I will try to fix this on next milestone.
jumbos87 commentedon Jun 21, 2020
I'm asking because I'm developing my own plugin based on another open-source plugin, so if you'll find a clue as to what which class/function causes the issue I would appreciate if you share.
Thanks.
de-jcup commentedon Jun 23, 2020
Investigation
After some investigation I found out that the problem is the usage of different document providers. I created a very simple editor plugin, which does extend text editor and does nothing special except following:
So setting a new document provider for every editor is the problem.
From documentation of
IDocumentProvider:Debug information
SimpleTextEditor without setting document provider in constructor, a cloned, or splitted editor (
CTRL+_) callssetDocumentProvider(IEditorInput input)twice where resolved document provider was both times same instance - in my caseorg.eclipse.ui.editors.text.TextFileDocumentProvider@66ee4640and synchronization works out of the box.What about Example codes
Normally eclipse plugin developers create (at least) their first plugins by the eclipse plugin project wizard, so what about the examples... ?
I found out that the problem is also existing when using
https://www.eclipse.org/downloads/packages/release/2020-06/r/eclipse-ide-rcp-and-rap-developers
and creating an example plugin with project wizard and creating the default XML Editor the problem exists:
The example - and most other editors - do set a document provider inside constructor, so every editor has got its own document provider:

So I will create an issue at https://bugs.eclipse.org/bugs/ - the generated examples should not have problems with clone / split editor function
Solution
Either provide a shared document provider for all instances, or decide on editor input which document provider has to be used and reuse same provider between editors for same input.
de-jcup commentedon Jun 23, 2020
Created https://bugs.eclipse.org/bugs/show_bug.cgi?id=564583 to request template change for example XML editor.
de-jcup commentedon Jun 25, 2020
@jumbos87 : please read my investigations at #199 (comment) , I have found a solution, so it could help you too.
jumbos87 commentedon Jun 25, 2020
@de-jcup you're the man!
I found the setDocumentProvider in my constructor as well and indeed after comment out, the splitted editors are in sync and work like magic.
However, I'll need to uncomment it because my provider creates my extended Document and I can't use the default Document that Eclipse creates by default. So, like you said, I need to reuse same provider if same file is already open. Need to think of a robust way to do it.
Thanks a lot!
jumbos87 commentedon Jun 28, 2020
I fixed the code to use a static provider in my extended TextEditor class, so it is shared for all instances. Do you see any reason to reuse provider based on same input (instead of one for all)?
de-jcup commentedon Jun 30, 2020
From javadoc:
So normally on every call the provider is given input as a parameter.
The only reason I am using 2 different (but also shared) providers is, because I handle some input types different, but these are always handled in same way on cloned editors.
IMHO it is not necessary to lookup for same input and map to dedicated provider (to reuse) - per definition a provider is stateless (as far as I know).
Changed document provider to shared instances, closes de-jcup#199