Ticket #8617: 8617-3.diff
File 8617-3.diff, 3.8 KB (added by , 12 years ago) |
---|
-
_source/plugins/selection/plugin.js
127 127 canUndo : false 128 128 }; 129 129 130 function createFillingChar( doc )130 function createFillingChar( doc, selection ) 131 131 { 132 removeFillingChar( doc );132 removeFillingChar( doc, selection ); 133 133 134 134 var fillingChar = doc.createText( '\u200B' ); 135 135 doc.setCustomData( 'cke-fillingChar', fillingChar ); … … 143 143 } 144 144 145 145 // Checks if a filling char has been used, eventualy removing it (#1272). 146 function checkFillingChar( doc )146 function checkFillingChar( doc, selection ) 147 147 { 148 148 var fillingChar = doc && getFillingChar( doc ); 149 149 if ( fillingChar ) … … 151 151 // Use this flag to avoid removing the filling char right after 152 152 // creating it. 153 153 if ( fillingChar.getCustomData( 'ready' ) ) 154 removeFillingChar( doc );154 removeFillingChar( doc, selection ); 155 155 else 156 156 fillingChar.setCustomData( 'ready', 1 ); 157 157 } 158 158 } 159 159 160 function removeFillingChar( doc )160 function removeFillingChar( doc, selection ) 161 161 { 162 162 var fillingChar = doc && doc.removeCustomData( 'cke-fillingChar' ); 163 163 if ( fillingChar ) 164 164 { 165 // Create a bookmark for the cursor so we can restore its position 166 // after removing the filling character. 167 // 168 // See #8617 Cursor jumps on Backspace in Chrome 169 // http://dev.ckeditor.com/ticket/8617 170 var bookmark = ( selection ) ? selection.createBookmarks() : null; 171 165 172 // We can't simply remove the filling node because the user 166 173 // will actually enlarge it when typing, so we just remove the 167 174 // invisible char from it. 168 175 fillingChar.setText( fillingChar.getText().replace( /\u200B/g, '' ) ); 169 fillingChar = 0; 176 177 if ( bookmark ) 178 selection.selectBookmarks( bookmark ); 170 179 } 171 180 } 172 181 … … 178 187 // (#1272). Here we set the events that should invalidate that char. 179 188 if ( CKEDITOR.env.webkit ) 180 189 { 181 editor.on( 'selectionChange', function() { checkFillingChar( editor.document ); } );182 editor.on( 'beforeSetMode', function() { removeFillingChar( editor.document ); } );190 editor.on( 'selectionChange', function() { checkFillingChar( editor.document, editor.getSelection() ); } ); 191 editor.on( 'beforeSetMode', function() { removeFillingChar( editor.document, editor.getSelection() ); } ); 183 192 editor.on( 'key', function( e ) 184 193 { 185 194 // Remove the filling char before some keys get … … 191 200 case 37 : // LEFT-ARROW 192 201 case 39 : // RIGHT-ARROW 193 202 case 8 : // BACKSPACE 194 removeFillingChar( editor.document );203 removeFillingChar( editor.document, editor.getSelection() ); 195 204 } 196 205 }, null, null, 10 ); 197 206 … … 1415 1424 { 1416 1425 sel.removeAllRanges(); 1417 1426 // Remove any existing filling char first. 1418 CKEDITOR.env.webkit && removeFillingChar( this.document );1427 CKEDITOR.env.webkit && removeFillingChar( this.document, this ); 1419 1428 } 1420 1429 1421 1430 for ( var i = 0 ; i < ranges.length ; i++ ) … … 1472 1481 { 1473 1482 // Append a zero-width space so WebKit will not try to 1474 1483 // move the selection by itself (#1272). 1475 var fillingChar = createFillingChar( this.document );1484 var fillingChar = createFillingChar( this.document, this ); 1476 1485 range.insertNode( fillingChar ) ; 1477 1486 1478 1487 var next = fillingChar.getNext(); … … 1482 1491 // Let's remove it in this case. 1483 1492 if ( next && !fillingChar.getPrevious() && next.type == CKEDITOR.NODE_ELEMENT && next.getName() == 'br' ) 1484 1493 { 1485 removeFillingChar( this.document );1494 removeFillingChar( this.document, this ); 1486 1495 range.moveToPosition( next, CKEDITOR.POSITION_BEFORE_START ); 1487 1496 } 1488 1497 else