-
Notifications
You must be signed in to change notification settings - Fork 236
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
Position of Caret and Selection are not updated correctly when change occurs at their current position #761
Comments
As in (assuming
|
I've recorded the problem, you can took a look here: https://drive.google.com/open?id=1WqPV4vah2imL-w5vwkiTs06zT_3WqVeF So yes, I think you're right. Just wanted to help clarify it. |
Thanks for the video. However, it'll be easier for me to debug and fix this if you submit a reproducible copy-and-paste demo like this one rather than a video showing the same thing. Could you do that instead? |
Here. Edit: |
Update: I've been using RichTextFX to highlight syntax in my program. The Ctrl-Z functionality works even weirder in that case. It seems to just undo highlighting instead of actually remove text. You can reproduce the strangeness in your JavaKeywords demo. |
Thanks for giving that additional bit. I know it's a bit pointless since I can probably infer that from your comments, but again, it just makes my job that much easier so I can focus on the issue and not on how to reproduce it. That being said, here's why it occurs. Two or more areas can render the same document. This allows one to simulate the "split document" feature of Microsoft Word. In other words, I can use one area to see the "top" part of the document and another area to see the "bottom" part of the document. However, when one area adds/removes text to the document, the other areas' carets and selections' positions should be updated so that they still "point" to the same place as before:
So, we need to update the positions to still work. We do that by subscribing to the
If we did, that would put it in the wrong place. However, this is not always desirable, such as the case you're experiencing. Since the text being add is at the start of the area and the caret is at the start of the area, the code does not move the caret when it should in that situation. I believe this could be fixed if we changed the code to move the caret (and selection) as well when both the change's position and the caret's (and selection's) position is at 0. However, I cannot think of a case off the top of my head when doing that would cause a new bug.
Oh, whoops! That's easy to explain. The area's default UndoManager undoes rich text changes (e.g. any change to the text, be it just text changes or style changes or style and text changes). So, that can be resolved by using: // plainUndoManager, or whatever that static method is called
UndoManager<PlainTextChange> um = UndoUtils.plainUndoManager(area);
area.setUndoManager(um); Please open a new issue so we can track that separately from this one. |
Actually, I wonder whether this is just a bug. Even if one typed text when the position wasn't at 0, deleted it, and hit CTRL+Z, the bug would still occur:
If so, then this line should be |
Sure, when I get a moment to make a reproducible test I will. In the meantime, I'll try your solution first and see if it works. |
This doesn't appear to be compatible with InlineCssTextArea. Is there an alternative version that works with that particular implementation? EDIT: Hold on, I'll actually go ahead and make the new issue since this is still giving me trouble. |
You can use the snapshot version right now (see ReadMe) as it includes this fix. |
I am able to replicate this if you type into a StyleClassedTextArea, then press CTRL-Z, then begin typing again, the cursor gets reset to the start of the text in latest version (0.9.1). |
If you type into a StyleClassedTextArea, then press CTRL-Z, then begin typing again, the cursor gets reset to the start of the text.
Code:
Also, if there's no way to fix this, is there a way to just disable CTRL-Z entirely?
The text was updated successfully, but these errors were encountered: