Clone editor mechanism problems · Issue #199 · de-jcup/eclipse-bash-editor · GitHub
Skip to content

Clone editor mechanism problems #199

Closed

Description

@de-jcup

At eclipse marketplace at
https://marketplace.eclipse.org/comment/6937#comment-6937
a user mentioned a problem, this is just copied text to an issue:

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.

Activity

  1. de-jcup commented on Jun 5, 2020

    @de-jcup
    OwnerAuthor

    As long as editor changes are saved inside editor where changes are made, both editors are in sync.

    But when you do following:

    1. change something in editor1 and DO NOT save
    2. then change editor2 and DO save
    3. then try to save editor1
      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:

    image

    So after next save a dialog appears:

    image

  2. de-jcup commented on Jun 5, 2020

    @de-jcup
    OwnerAuthor

    For normal text editor all changes are directly changed into cloned instance without any safe:

    image

  3. added this to the 2.4.0 milestone on Jun 5, 2020
  4. jumbos87 commented on Jun 16, 2020

    @jumbos87

    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?

  5. de-jcup commented on Jun 18, 2020

    @de-jcup
    OwnerAuthor

    @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.

  6. jumbos87 commented on Jun 21, 2020

    @jumbos87

    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.

  7. de-jcup commented on Jun 23, 2020

    @de-jcup
    OwnerAuthor

    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:

    image

    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... ?

    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:

    image

    The example - and most other editors - do set a document provider inside constructor, so every editor has got its own document provider:
    image

    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.

  8. de-jcup commented on Jun 23, 2020

    @de-jcup
    OwnerAuthor

    Created https://bugs.eclipse.org/bugs/show_bug.cgi?id=564583 to request template change for example XML editor.

  9. de-jcup commented on Jun 25, 2020

    @de-jcup
    OwnerAuthor

    @jumbos87 : please read my investigations at #199 (comment) , I have found a solution, so it could help you too.

  10. jumbos87 commented on Jun 25, 2020

    @jumbos87

    @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!

  11. jumbos87 commented on Jun 28, 2020

    @jumbos87

    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.

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

  12. de-jcup commented on Jun 30, 2020

    @de-jcup
    OwnerAuthor

    From javadoc:

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

  13. self-assigned this
    on Jul 24, 2020
  14. added a commit that references this issue on Jun 28, 2026
    9be3036
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions