| 286 | // Webkit require actual text content to move selection into |
| 287 | // this collapsed element. (#3708) |
| 288 | if( CKEDITOR.env.webkit ) |
| 289 | { |
| 290 | var bogusText = collapsedElement.append( document.createText( '\ufeff' ) ); |
| 291 | |
| 292 | function onInputRemoveBogus( evt ) |
| 293 | { |
| 294 | document.removeListener( 'keyup', arguments.callee ); |
| 295 | document.removeListener( 'mouseup', arguments.callee ); |
| 296 | |
| 297 | var keyCode = evt.data.getKey(), |
| 298 | bogusText = collapsedElement.getFirst(); |
| 299 | // Skip control keys ( they might be keyboard shortcut), |
| 300 | // reschedule a check. |
| 301 | if ( keyCode == 17 // Ctrl |
| 302 | || keyCode == 16 // Shift |
| 303 | || keyCode == 18 // Alt |
| 304 | ) |
| 305 | { |
| 306 | checkNextInput(); |
| 307 | return; |
| 308 | } |
| 309 | // If there's more character existed inside the text node |
| 310 | // beside bogus, it indicate the style element is no longer |
| 311 | // empty. |
| 312 | else if( bogusText.getText().length != 1 ) |
| 313 | { |
| 314 | // The bogus text has been merged with newly inputted char, |
| 315 | // split it out, move selection after it, then remove it. |
| 316 | bogusText = bogusText.split( 1 ).getPrevious(); |
| 317 | range.moveToPosition( bogusText, CKEDITOR.POSITION_AFTER_END ); |
| 318 | bogusText.remove(); |
| 319 | range.select(); |
| 320 | } |
| 321 | // The input is somewhere else, keep the style element empty. |
| 322 | else |
| 323 | bogusText.remove(); |
| 324 | } |
| 325 | |
| 326 | // Check after any subsequent mouse and keyboard actions, to validate if |
| 327 | // it happened inside the style. |
| 328 | function checkNextInput() |
| 329 | { |
| 330 | document.on( 'keyup', onInputRemoveBogus ); |
| 331 | document.on( 'mouseup', onInputRemoveBogus ); |
| 332 | } |
| 333 | // It's possible we're now inside a key event thread, |
| 334 | // e.g. shortcutKey, so skip this turn. |
| 335 | window.setTimeout( checkNextInput, 300 ); |
| 336 | } |