Opened 16 years ago
Closed 15 years ago
#3372 closed Bug (fixed)
Undo / Redo Text Selection Bug
Reported by: | J. Heard | Owned by: | Tobiasz Cudnik |
---|---|---|---|
Priority: | Normal | Milestone: | CKEditor 3.0 |
Component: | Core : Undo & Redo | Version: | FCKeditor 2.6.3 |
Keywords: | Confirmed Review+ | Cc: |
Description (last modified by )
Steps to reproduce:
- Type in a line of text
- Press Enter
- Type another line of text.
- Select the second line of text.
- Press the "backspace" key and delete all of the highlighted text, or just simply press backspace to delete all of the text.
- Press Ctrl-Z or the Undo toolbar button
Observation: Only some of the deleted text is restored after pressing undo, and in some cases the entire second line of text is deleted. The behavior is sporadic, but reproducible. I've also noticed that if you have a lot of content in the editor, after calling the undo command the very last line of text will vanish.
Expected: The highlighted / deleted text should be restored as it was prior to deletion and the remainder of the content remains unchanged.
Notes: Redo performs in the same odd fashion. First noticed this behavior in the 2.6.3 version, but it's also reproducible in the nightly build:
http://www.fckeditor.net/nightly/fckeditor/_samples/default.html
Attachments (8)
Change History (34)
comment:1 Changed 16 years ago by
Keywords: | undo redo bug removed |
---|---|
Priority: | High → Normal |
comment:2 Changed 16 years ago by
Description: | modified (diff) |
---|---|
Keywords: | Confirmed added |
Milestone: | → CKEditor 3.0 |
comment:3 Changed 16 years ago by
Owner: | set to Garry Yao |
---|---|
Status: | new → assigned |
comment:4 Changed 16 years ago by
Owner: | changed from Garry Yao to Tobiasz Cudnik |
---|---|
Status: | assigned → new |
comment:5 Changed 16 years ago by
Status: | new → assigned |
---|
comment:6 Changed 16 years ago by
Keywords: | Pending added; Confirmed removed |
---|
Can't reproduce it on r3495. Can someone provide content which caused this issue ?
It's also possible that it was fixed during those 4 weeks since the report with some other ticket. But this would have to be in both V3 and V2...
comment:7 Changed 16 years ago by
Keywords: | Confirmed added; Pending removed |
---|
I'm still able to reproduce it with the current trunk. We can't preload the editor to test it, as it much probably depends on the character counting logic of the undo plugin.
It happens with long lines of text. Here you have a screencast of it, with FF3:
http://screencast.com/t/Jw9W4b2WbIz
Note that, after the BACKSPACE deleted the selected text, the undo action doesn't restore the text until the "END" word. Further undo and redo calls will never restore that text.
comment:8 Changed 16 years ago by
A new stable TC can be found here (with voice):
http://screencast.com/t/fWFO1E4pxiN
Reproducible in the exact same way in FF3 and IE7.
Changed 16 years ago by
Attachment: | 3372.patch added |
---|
comment:9 Changed 16 years ago by
Keywords: | Review? added |
---|
comment:10 Changed 16 years ago by
Keywords: | Review- added; Review? removed |
---|
The capturing of Control Keystroke within the undo system is definitely a good move, while it's better if we can also support other key like 'arrows' and 'del' etc. A general DFA of undo system will be like:
- When you're not typing:
- You press a /\w/, go to 2.
- You press a modify key, take snap, record the pressed key, go to 3.
- When you're typing:
- If you press a /\w/, you're still typing;
- If you press a modify key, same as 1.2
- When you're modifying:
- If you press a /\w/, take snap, go to 2;
- If you press a modify key and it's same as last, go to 3;
- If you press a modify key and it's diff from last, same as 1.2
comment:11 Changed 16 years ago by
Another TC
- Type in a line of text
- Press Enter
- Type another line of text.
- Select the second line of text.
- Press "Shift-Home" to select to the beginning, and press "Del" to delete all of the highlighted text.
- Press Ctrl-Z or the Undo toolbar button
Changed 16 years ago by
Attachment: | 3372_2.patch added |
---|
comment:12 Changed 16 years ago by
Keywords: | Review? added; Review- removed |
---|
TC for backspace
- In empty editor type "foo"
- Press backspace
- Press Ctrl+z
TC for delete
- In empty editor type "foo"
- Press left arrow
- Press delete
- Press Ctrl+z
Capturing arrows is possible with attached patch by uncommenting L13 and change of L220 to:
if ( !( beforeTypeImage.equals( currentSnapshot ) ) )
Although this would slow down comparison and there won't be any benefit (there'is no bookmarks for carret position, only for selection).
comment:13 Changed 16 years ago by
Keywords: | Review- added; Review? removed |
---|
The patch works, two minor issues identified:
- Sorry for unclear explanation of the 'Arrow Keys', actually they shouldn't cause snapshot but they're responsible for reseting typing state, take the following TC as example:
- Delete all contents and begin to type some characters;
- Navigate into the middle of the existed text line with 'Arrow Left';
- Begin to type some characters from this new position;
- Perform 'undo'.
- Expected Result: There should be two undo points saved;
- Actual Result: There's only one snap.
- Plz comment out the following keymap OR refactor them into constants, make sure there's no magic number:
var modifierCodes = { 8:1, 46:1/*, 39:1, 40:1, 38:1, 37:1*/ };
Changed 16 years ago by
Attachment: | 3372_4.patch added |
---|
comment:14 Changed 16 years ago by
Keywords: | Review? added; Review- removed |
---|
Now i see you point and i agree with it. I'm attaching another patch which covers this case and explains used keycodes.
comment:15 Changed 16 years ago by
Keywords: | Review- added; Review? removed |
---|
We're closing, but yet another problem left: The Modifier Key counting is mixed with Character Key counting, which is wrong, proved by the following TC:
- Delete all contents;
- Type 'word' as a line;
- Press 'Backspace' to delete to the beginning of the line;
- Type 'another' in the same line;
- Expected Result: When press undo, the document should be empty.
- Actual Result:There's no snapshot before the newly typed line, do when pressed undo, the document has 'word' a a line;
Changed 16 years ago by
Attachment: | 3372_5.patch added |
---|
comment:16 Changed 16 years ago by
Keywords: | Review? added; Review- removed |
---|
This patch covers you TC and additionally this one:
- In empty editor type "foo foo foo"
- Select second word with mouse like this "foo foo foo"
- Start typing
- Press Ctrl+z
- Expected result is state from (2).
comment:18 Changed 16 years ago by
Keywords: | Review- added; Review? removed |
---|
Much better with 3372_5, but the only problem left is that we should reset the DFA about typing after a regular 'save', e.g. after insert a textfield. I'm attaching a updated patch with this purpose.
Changed 16 years ago by
Attachment: | 3372_6_ref.patch added |
---|
comment:19 Changed 16 years ago by
I've also adding necessary comments which I though match with your codes, but correct me of course.
Changed 16 years ago by
Attachment: | 3372_6.patch added |
---|
comment:20 Changed 16 years ago by
Keywords: | Review? added; Review- removed |
---|
I've checked you changes, added a bit of new lines to make code more readable and i'm attaching the patch.
Seems everything works right now and definitely the ticket's bug is fixed.
comment:21 Changed 16 years ago by
Keywords: | Review- added; Review? removed |
---|
Sorry for that I've just spotted another issue with the patch at L202:
isSelected = !this.editor.getSelection().getRanges()[0].collapsed // Check selection for every keystroke.
This should be avoided as Fred said - native range retrieving without properly cached is an heavy operation, and we're now treating this for every keystroke, it will definitely has an impact on the overall PF.
Based on this, I think we should find a replacing approach, e.g. reset the state on every native selection change instead of manual checking here, how do you think?
comment:22 Changed 16 years ago by
I guess the selection change is something similar with 'Shift Key' handling logic which has impact right on the 'startedTyping' variable.
comment:23 Changed 15 years ago by
After talk with Garry i've moved selection case to separate ticket #3691.
I'm attaching patch without selection undo support.
Changed 15 years ago by
Attachment: | 3372_7.patch added |
---|
comment:24 Changed 15 years ago by
Keywords: | Review? added; Review- removed |
---|
comment:25 Changed 15 years ago by
Keywords: | Review+ added; Review? removed |
---|
I confirm this problem with V2 and V3, in both IE and FF.