|
15 | 15 | if ( sel.getType() == CKEDITOR.SELECTION_NONE )
|
16 | 16 | return;
|
17 | 17 |
|
18 |
| - // Before doing anything, save a locked copy to be used for later recovery. |
19 |
| - sel.lock(); |
20 |
| - this._.lastSelection = sel; |
| 18 | + this.fire( 'selectionCheck', sel ); |
21 | 19 |
|
22 | 20 | var currentPath = this.elementPath();
|
23 | 21 | if ( !currentPath.compare( this._.selectionPreviousPath ) ) {
|
|
206 | 204 | restoreSel = 0;
|
207 | 205 | }, null, null, -1 );
|
208 | 206 |
|
| 207 | + var lastSel; |
| 208 | + // Save a fresh copy of the selection. |
| 209 | + function saveSel() { |
| 210 | + lastSel = editor.getSelection( 1 ); |
| 211 | + lastSel.lock(); |
| 212 | + } |
| 213 | + |
| 214 | + // For IE, we can retrieve the last correct DOM selection upon the "beforedeactivate" event. |
| 215 | + // For the rest, a more frequent check is required for each selection change made. |
| 216 | + if ( CKEDITOR.env.ie ) |
| 217 | + editable.attachListener( editable, 'beforedeactivate', saveSel, null, null, -1 ); |
| 218 | + else |
| 219 | + editable.attachListener( editor, 'selectionCheck', saveSel, null, null, -1 ); |
| 220 | + |
209 | 221 | editable.attachListener( editable, 'blur', function() {
|
210 |
| - editor.lockSelection(); |
| 222 | + editor.lockSelection( lastSel ); |
211 | 223 | restoreSel = 1;
|
212 | 224 | }, null, null, -1 );
|
213 | 225 |
|
|
497 | 509 | *
|
498 | 510 | * @method
|
499 | 511 | * @member CKEDITOR.editor
|
| 512 | + * @param {CKEDITOR.dom.selection} [sel] Specify the selection to be locked. |
500 | 513 | * @returns {Boolean} `true` if selection was locked.
|
501 | 514 | */
|
502 |
| - CKEDITOR.editor.prototype.lockSelection = function() { |
503 |
| - if ( !this._.savedSelection ) { |
504 |
| - var sel = this.getSelection( 1 ); |
505 |
| - sel = sel.getType() == CKEDITOR.SELECTION_NONE ? this._.lastSelection : sel; |
506 |
| - if ( sel ) { |
| 515 | + CKEDITOR.editor.prototype.lockSelection = function( sel ) { |
| 516 | + sel = sel || this.getSelection( 1 ); |
| 517 | + if ( sel.getType() != CKEDITOR.SELECTION_NONE ) { |
507 | 518 | !sel.isLocked && sel.lock();
|
508 | 519 | this._.savedSelection = sel;
|
509 | 520 | return true;
|
510 | 521 | }
|
511 |
| - } |
512 |
| - |
513 | 522 | return false;
|
514 | 523 | };
|
515 | 524 |
|
|
731 | 740 | // object even when type == 'None' is returned by IE.
|
732 | 741 | // So we'd better check the object returned by
|
733 | 742 | // createRange() rather than by looking at the type.
|
734 |
| - if ( sel.createRange().parentElement ) |
| 743 | + if ( sel.createRange().parentElement() ) |
735 | 744 | type = CKEDITOR.SELECTION_TEXT;
|
736 | 745 | } catch ( e ) {}
|
737 | 746 |
|
|
1519 | 1528 | }
|
1520 | 1529 | }
|
1521 | 1530 |
|
1522 |
| - // Fakes the IE DOM event "selectionchange" on editable. |
1523 |
| - this.root.fire( 'selectionchange' ); |
1524 | 1531 | this.reset();
|
1525 | 1532 |
|
| 1533 | + // Fakes the IE DOM event "selectionchange" on editable. |
| 1534 | + this.root.fire( 'selectionchange' ); |
1526 | 1535 | },
|
1527 | 1536 |
|
1528 | 1537 | /**
|
|
0 commit comments