Opened 13 years ago
Closed 13 years ago
#8617 closed Bug (fixed)
Cursor jumps on Backspace in Chrome
Reported by: | sheaujye2359 | Owned by: | Garry Yao |
---|---|---|---|
Priority: | Normal | Milestone: | CKEditor 3.6.3 |
Component: | Core : Selection | Version: | 3.5.3 |
Keywords: | Chrome | Cc: | Frederico Caldeira Knabben, camden.michael@… |
Description
- Type ABC
- Select a Font Family
- Type DEF
- Select a Different Font Family
- Type GHI
By now the cursor should be after "I", pressing backspace should delete "I", but cursor quickly moved to after "F" and delete "F" weirdly.
This only happens on Chrome, NOT Safari, Nightly build is the same.
Attachments (7)
Change History (41)
comment:1 Changed 13 years ago by
Keywords: | Backspace removed |
---|---|
Status: | new → confirmed |
Version: | 3.6.2 → 3.5.3 |
comment:2 Changed 13 years ago by
@sheaujye2359 - if this is not what you are getting and TC to reproduce your issue please leave a comment.
comment:3 Changed 13 years ago by
#8627 was merked as duplicate.
Another TC:
When entering a sentence with emphasis - italic or bold - after completing the emphasized text, then some more - if you hit backspace the cursor is positioned at the beginning of the emphasis and backspaces occur there.
comment:4 Changed 13 years ago by
The one more use case (provided by @karena):
- Type any text and select it with ctrl-shift-left arrow
- Apply any font name
- Unselect text with right arrow key
- Hit Enter and type text, select it with ctrl-shift-left arrow and apply another font name
Note that range is collapsed, cursor jumped to start of the paragraph and font name is not applied.
I noticed that setting new text to filling char node (fillingChar.setText()) collapses the range.
comment:6 Changed 13 years ago by
TC from #8697 has helped me to find more simple way to reproduce the issue:
- In empty editor choose font style (bold for example)
- type word like “ckeditor” (don't click behind text) and press right arrow key
Result:
Cursor will move behind second letter c^keditor
. It looks that CKEditor sees cursor in different place comparing it to what you see on screen.
comment:7 Changed 13 years ago by
Hi We debugged this issue and realized that the issue is in the selection plugin in the 'removeFillingChar' function In Chrome this sets the all native selection offsets to 0, meaning the beginning of the span. We reproduced this bug with Spans and Enter-key
A patch would be appreciated ASAP as this is very urgent for us. Thank you
Changed 13 years ago by
Attachment: | 8617.patch added |
---|
comment:9 Changed 13 years ago by
Owner: | set to Garry Yao |
---|---|
Status: | confirmed → review |
comment:11 Changed 13 years ago by
few changes to the patch:
- if the offset is before the no space char then we don't need to change the offset
- I don't see any reason to change the focusOffset only if the anchorOffset has changed
- don't change offset 0
here is the altered code (I don't have it checked out from SVN)
function removeFillingChar( doc ) { var fillingChar = doc && doc.removeCustomData( 'cke-fillingChar' ); if ( fillingChar ) { var sel = doc.getSelection(); // Text selection position might get mangled by // subsequent dom modification. #8617[1] var bm = getFixedBookmark(doc, sel, fillingChar); // We can't simply remove the filling node because the user // will actually enlarge it when typing, so we just remove the // invisible char from it. fillingChar.setText( fillingChar.getText().replace( /\u200B/g, '' ) ); fillingChar = 0; bm && sel.selectBookmarks( [ bm ] ); } } function getFixedBookmark(doc, sel, fillingChar){ var nativeSel = sel.getNative(); if(nativeSel.type != 'None'){ var bm = sel.createBookmarks2()[ 0 ]; var anchorFillingCharIndex = (nativeSel.anchorNode && nativeSel.anchorNode.data) ? nativeSel.anchorNode.data.indexOf('\u200B') : -1; var focusFillingCharIndex = (nativeSel.focusNode && nativeSel.focusNode.data) ? nativeSel.focusNode.data.indexOf('\u200B') : -1; if ( anchorFillingCharIndex > -1 && nativeSel.anchorOffset > anchorFillingCharIndex){ bm.startOffset--; } if(!nativeSel.isCollapsed && focusFillingCharIndex > -1 && nativeSel.focusOffset > focusFillingCharIndex){ bm.endOffset--; } } return bm; }
comment:12 Changed 13 years ago by
We created a patch for this issue at the Atlantic that is a bit more concise than the ones posted — I'm curious whether we're missing something. I'm attaching it for review. Below is an overview of the diff (leading whitespace stripped for readability):
Index: _source/plugins/selection/plugin.js =================================================================== --- _source/plugins/selection/plugin.js (revision 7354) +++ _source/plugins/selection/plugin.js (revision ) @@ -182,6 +182,14 @@ editor.on( 'beforeSetMode', function() { removeFillingChar( editor.document ); } ); editor.on( 'key', function( e ) { + // Create a bookmark for the cursor so we can restore its position + // after removing the filling character. + // + // See #8617 Cursor jumps on Backspace in Chrome + // http://dev.ckeditor.com/ticket/8617 + var selection = editor.getSelection(); + var bookmark = ( selection ) ? selection.createBookmarks() : null; + // Remove the filling char before some keys get // executed, so they'll not get blocked by it. switch ( e.data.keyCode ) @@ -193,6 +201,9 @@ case 8 : // BACKSPACE removeFillingChar( editor.document ); } + + if ( bookmark ) + selection.selectBookmarks( bookmark ); }, null, null, 10 ); var fillingCharBefore,
Changed 13 years ago by
Attachment: | 8617-2.patch added |
---|
comment:14 Changed 13 years ago by
Turns out I was missing something — createBookmarks/selectBookmarks wasn't being called for every instance of removeFillingChar, which caused some unexpected behavior. I'm attaching an amended patch.
Two notes on the patch posted by garry.yao: There appears to be a strange double quote on line 176, and line 177 has the typo
if ( !nativeSel.isCollpased
Changed 13 years ago by
Attachment: | 8617-3.diff added |
---|
comment:15 Changed 13 years ago by
there is a side effect.. try selecting some color writing something pressing enter twice -> you lose the color
or just choose color and press enter once
it happens because when the span is empty on selectBookmars the selection moves out of the span
Changed 13 years ago by
Attachment: | 8617_1.patch added |
---|
Character which caused editor not to load was removed.
comment:16 Changed 13 years ago by
#8756 was marked as duplicate.
Another TC from that ticket:
- Paste
<p><span>just some text</span></p>
- Press enter and type something
- press enter
Second line will jump to third.
comment:18 Changed 13 years ago by
Cc: | Frederico Caldeira Knabben added |
---|
Changed 13 years ago by
Attachment: | 8617_2.patch added |
---|
comment:19 Changed 13 years ago by
New patch addresses the following comments from @alissa:
- enter key to continue inline style;
- Keystroke immediately after opening style;
Manual tc added: http://ckeditor.t/tt/8617/1.html
comment:20 Changed 13 years ago by
Status: | review → review_failed |
---|
:/ it looks like the patch has been committed by mistake: [7376]. Can you check it, eventually putting things in order?
comment:21 Changed 13 years ago by
Status: | review_failed → review |
---|
Oops, trunk is now fixed for review.
comment:22 Changed 13 years ago by
Cc: | camden.michael@… added |
---|
comment:23 Changed 13 years ago by
Component: | General → Core : Selection |
---|---|
Status: | review → review_failed |
The patch seems to solve several of the issues.
But I'm still able to reproduce comment:4 and the following similar TC:
- CTRL+B to start bold.
- ENTER
- Type ABC.
- SHIFT+HOME or CTRL+SHIFT+LEFT to select ABC.
- ENTER
comment:24 Changed 13 years ago by
Milestone: | → CKEditor 3.6.3 |
---|
Changed 13 years ago by
Attachment: | 8617_3.patch added |
---|
comment:25 Changed 13 years ago by
Status: | review_failed → review |
---|
New patch change to intercept char code instead of keystroke, covering more keystrokes combination like shift-enter, shift-home, ctrl-arrow, alt-arrow...while we also need to understand it's impossible to exhaust all possible control-key combinations, e.g. Ctrl-A.
comment:26 follow-ups: 27 28 Changed 13 years ago by
I'm not sure if this is related to this patch, but I have found the following behavior after applying the patch (8617_3);
- Write out a line of text, "Hello world"
- Use SHIFT+HOME to select the text, and then apply bold (CTRL+B)
- Press 'END' to get the end of the line, and press enter
- Write out another line of text, "Hello world" (line should be bold)
- Press enter twice
Result: A single space will be created after the second line
Expected result: Two empty lines should be created after the second line because enter was pressed twice
comment:27 Changed 13 years ago by
Replying to mrfr0g:
I'm not sure if this is related to this patch, but I have found the following behavior after applying the patch (8617_3);
- Write out a line of text, "Hello world"
- Use SHIFT+HOME to select the text, and then apply bold (CTRL+B)
- Press 'END' to get the end of the line, and press enter
- Write out another line of text, "Hello world" (line should be bold)
- Press enter twice
Result: A single space will be created after the second line
Expected result: Two empty lines should be created after the second line because enter was pressed twice
WFM, can u reduce a bit the tc? thx.
comment:28 Changed 13 years ago by
Replying to mrfr0g:
Well... the TC is not so complex, but it works for me as well.
comment:29 follow-ups: 30 33 Changed 13 years ago by
I've attached a patch that I believe covers the test cases discussed so far. It's a slight modification of the patch in comment:11.
Changed 13 years ago by
Attachment: | 8617_4.patch added |
---|
comment:30 Changed 13 years ago by
Replying to fdintino:
I've attached a patch that I believe covers the test cases discussed so far. It's a slight modification of the patch in comment:11.
Thanks for the new patch, but it fails with at least the comment:23 TC. I didn't test others.
comment:31 Changed 13 years ago by
Status: | review → review_passed |
---|
R+ on attachment:8617_3.patch for now.
@fdintino and others, if we feel it can be done in a different way, just let us know.
comment:32 Changed 13 years ago by
Hm, it looks like you're right about that test case; concur on the decision re: 8617_3.patch.
comment:33 Changed 13 years ago by
Replying to fdintino:
I've attached a patch that I believe covers the test cases discussed so far. It's a slight modification of the patch in comment:11.
You patch does allow the cursor to move out of the line, but it takes an additional enter key press to move out of the bold style and create a new line. Please see the following screencast, http://screencast-o-matic.com/watch/cleo2ABDz
comment:34 Changed 13 years ago by
Resolution: | → fixed |
---|---|
Status: | review_passed → closed |
I was not able to reproduc eyour issue but something very similar.
To reproduce:
By now the cursor should be after "F", pressing backspace should delete "F", but cursor quickly moved and joins ABC and DEF together.
This issue has been reproducible from CKEditor 3.5.3 rev [6461] (it's rev for CKE 3.5.2 it was probably included in 3.5.3.)
Tested on Chrome 16.0.912.75