Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly move focus to panel that is being edited when undoing #371

Open
raquelalegre opened this issue Apr 11, 2019 · 1 comment
Open
Assignees
Labels

Comments

@raquelalegre
Copy link
Contributor

Replicate:

  1. Open arabic file
  2. Edit arabic pane
  3. Edit non-arabic pane
  4. Undo changes one by one

You will notice the caret positioning itself in the beginning of the second line of the non-arabic pane after undoing all arabic pane changes. However this is counter intuitive and can make users confused when the add text again after undoing.

Focus should be always in the panel where we are undoing.

This can probably be fixed by explicitly putting the focus in the correct panel in the override undo() method of AtfAreaController.

@giordano
Copy link
Contributor

Ok, this is extremely tricky. I'm going to report here some of my attempts so far in case I come up with the same ideas in the coming days.

It's not clear to me who sets the position of the caret when undoing: AtfAreaController.undo() doesn't do much apart from calling self.undo_manager.undo(). The call to self.syntax_highlight() is not the culprit, I just removed it in my tests but I am still able to reproduce the issue. Apparently the position of the caret is controlled by swing.

Helped by Anastasis, I wrote this class, mostly for debugging:

class NewEdit(CompoundEdit):

    # override protected method with this weird secret thing
    def lastEdit(self):
        return self.super__lastEdit()

    # add a getter for a protected field
    def getEdits(self):
        field = CompoundEdit.getDeclaredField("edits")
        field.setAccessible(True)
        return field.get(self)

    def firstEdit(self):
        return self.getEdits()[0]

The firstEdit should give us the first edit of the compound, so hopefully the first edit to be undone. The idea was that by calling this method in AtfAreaController.undo() we can get information about what is the StyledDocument where the next edit to be undone is, and perhaps the position of the edit in order to move the caret there. However, calling this method in AtfAreaController.undo() shows that this is always the same edit until the undo stack is cleared.

@giordano giordano mentioned this issue May 23, 2019
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants