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

After undo/redo, new text is inserted at the end #912

Closed
cengels opened this issue Mar 13, 2020 · 4 comments · Fixed by #915
Closed

After undo/redo, new text is inserted at the end #912

cengels opened this issue Mar 13, 2020 · 4 comments · Fixed by #915
Labels

Comments

@cengels
Copy link

cengels commented Mar 13, 2020

Expected Behavior

When a text change is undone or redone, the selection should stay where the caret is so that subsequent text insertions originate from the caret position.

Actual Behavior

When a text change is undone or redone, the selection jumps to the end of the document (from what I can tell, neither caretPosition nor anchor are affected). Subsequent text insertions (if the caret is not manually moved in the meantime) place new text at the end rather than at the caret position.

Note that, from what I can tell, this only occurs on text changes, not style changes.

Reproducible Demo

Occurs as-is in the latest version (revision c9a002b) of the RichTextDemo.

Steps:

  1. Open the RichTextDemo
  2. Write some text, preferably with multiple paragraphs
  3. Change some text in a position that is not the end (removing or adding characters both works)
  4. Undo the change
  5. Type another character
  6. The new character is inserted at the very end of the document

Might be related to #780 / #785.

@Jugen Jugen added the bug label Mar 13, 2020
@Jugen
Copy link
Collaborator

Jugen commented Mar 13, 2020

Thanks for reporting have started looking into it, will continue next week.

@Jugen
Copy link
Collaborator

Jugen commented Mar 18, 2020

Hi Christopher,
If you can, give this a spin and let me know if there are any problems.
Thanks.

@cengels
Copy link
Author

cengels commented Mar 19, 2020

Hey @Jugen, thanks for looking into this!

From what I can tell, the problem is indeed resolved. There is one oddity I noticed, however: when undoing a text removal or undoing a style change over a segment of text, the cursor is then placed at the beginning of that change segment. The standard behaviour for this kind of an undo change is to conclude the undo operation with the entire range of text being selected, so RichTextFX's behaviour feels a bit strange here.

I do realize, however, that this does not really fall within the purview of this issue. If it were possible to tell whether a change is an undo/redo or a normal text change (as in from a paste), this would definitely be something I would implement on my own, but I don't believe there is any way to distinguish the two, is there?

@Jugen
Copy link
Collaborator

Jugen commented Mar 20, 2020

If it were possible to tell whether a change is an undo/redo or a normal text change (as in from a paste)

The changes I made are in UndoUtils and are only invoked during undo/redo. So you could put something like area.selectRange( pos, len ); before/after the following line to accomplish what you want.

If I'm not mistaken I think len can be negative sometimes so you'll need to experiment and account for that.

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

Successfully merging a pull request may close this issue.

2 participants