Ticket #7106: 7106.patch

File 7106.patch, 5.6 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/selection/plugin.js

     
    146146                                                                                }
    147147                                                                                catch (e)
    148148                                                                                {}
    149                                                                         }
     149                                                                                }
    150150
    151151                                                                        savedRange = null;
    152152                                                                }
     
    12881288                                var bookmark = this.createBookmark();
    12891289
    12901290                                // Create marker tags for the start and end boundaries.
    1291                                 var startNode = bookmark.startNode;
     1291                                var startNode = bookmark.startNode,
     1292                                        ieRange;
    12921293
    1293                                 var endNode;
    1294                                 if ( !collapsed )
    1295                                         endNode = bookmark.endNode;
     1294                                try
     1295                                {
     1296                                        var endNode;
     1297                                        if ( !collapsed )
     1298                                                endNode = bookmark.endNode;
    12961299
    1297                                 // Create the main range which will be used for the selection.
    1298                                 var ieRange = this.document.$.body.createTextRange();
     1300                                        // Create the main range which will be used for the selection.
     1301                                        ieRange = this.document.$.body.createTextRange();
    12991302
    1300                                 // Position the range at the start boundary.
    1301                                 ieRange.moveToElementText( startNode.$ );
    1302                                 ieRange.moveStart( 'character', 1 );
     1303                                        // Position the range at the start boundary.
     1304                                        ieRange.moveToElementText( startNode.$ );
     1305                                        ieRange.moveStart( 'character', 1 );
    13031306
    1304                                 if ( endNode )
    1305                                 {
    1306                                         // Create a tool range for the end.
    1307                                         var ieRangeEnd = this.document.$.body.createTextRange();
     1307                                        if ( endNode )
     1308                                        {
     1309                                                // Create a tool range for the end.
     1310                                                var ieRangeEnd = this.document.$.body.createTextRange();
    13081311
    1309                                         // Position the tool range at the end.
    1310                                         ieRangeEnd.moveToElementText( endNode.$ );
     1312                                                // Position the tool range at the end.
     1313                                                ieRangeEnd.moveToElementText( endNode.$ );
    13111314
    1312                                         // Move the end boundary of the main range to match the tool range.
    1313                                         ieRange.setEndPoint( 'EndToEnd', ieRangeEnd );
    1314                                         ieRange.moveEnd( 'character', -1 );
    1315                                 }
    1316                                 else
    1317                                 {
    1318                                         // The isStartMarkerAlone logic comes from V2. It guarantees that the lines
    1319                                         // will expand and that the cursor will be blinking on the right place.
    1320                                         // Actually, we are using this flag just to avoid using this hack in all
    1321                                         // situations, but just on those needed.
    1322                                         var next = startNode.getNext( notWhitespaces );
    1323                                         isStartMarkerAlone = ( !( next && next.getText && next.getText().match( fillerTextRegex ) )     // already a filler there?
    1324                                                                                   && ( forceExpand || !startNode.hasPrevious() || ( startNode.getPrevious().is && startNode.getPrevious().is( 'br' ) ) ) );
     1315                                                // Move the end boundary of the main range to match the tool range.
     1316                                                ieRange.setEndPoint( 'EndToEnd', ieRangeEnd );
     1317                                                ieRange.moveEnd( 'character', -1 );
     1318                                        }
     1319                                        else
     1320                                        {
     1321                                                // The isStartMarkerAlone logic comes from V2. It guarantees that the lines
     1322                                                // will expand and that the cursor will be blinking on the right place.
     1323                                                // Actually, we are using this flag just to avoid using this hack in all
     1324                                                // situations, but just on those needed.
     1325                                                var next = startNode.getNext( notWhitespaces );
     1326                                                isStartMarkerAlone = ( !( next && next.getText && next.getText().match( fillerTextRegex ) )     // already a filler there?
     1327                                                                                          && ( forceExpand || !startNode.hasPrevious() || ( startNode.getPrevious().is && startNode.getPrevious().is( 'br' ) ) ) );
    13251328
    1326                                         // Append a temporary <span>&#65279;</span> before the selection.
    1327                                         // This is needed to avoid IE destroying selections inside empty
    1328                                         // inline elements, like <b></b> (#253).
    1329                                         // It is also needed when placing the selection right after an inline
    1330                                         // element to avoid the selection moving inside of it.
    1331                                         dummySpan = this.document.createElement( 'span' );
    1332                                         dummySpan.setHtml( '&#65279;' );        // Zero Width No-Break Space (U+FEFF). See #1359.
    1333                                         dummySpan.insertBefore( startNode );
     1329                                                // Append a temporary <span>&#65279;</span> before the selection.
     1330                                                // This is needed to avoid IE destroying selections inside empty
     1331                                                // inline elements, like <b></b> (#253).
     1332                                                // It is also needed when placing the selection right after an inline
     1333                                                // element to avoid the selection moving inside of it.
     1334                                                dummySpan = this.document.createElement( 'span' );
     1335                                                dummySpan.setHtml( '&#65279;' );        // Zero Width No-Break Space (U+FEFF). See #1359.
     1336                                                dummySpan.insertBefore( startNode );
    13341337
    1335                                         if ( isStartMarkerAlone )
    1336                                         {
    1337                                                 // To expand empty blocks or line spaces after <br>, we need
    1338                                                 // instead to have any char, which will be later deleted using the
    1339                                                 // selection.
    1340                                                 // \ufeff = Zero Width No-Break Space (U+FEFF). (#1359)
    1341                                                 this.document.createText( '\ufeff' ).insertBefore( startNode );
    1342                                         }
    1343                                 }
    1344 
    1345                                 // Remove the markers (reset the position, because of the changes in the DOM tree).
    1346                                 this.setStartBefore( startNode );
    1347                                 startNode.remove();
     1338                                                if ( isStartMarkerAlone )
     1339                                                {
     1340                                                        // To expand empty blocks or line spaces after <br>, we need
     1341                                                        // instead to have any char, which will be later deleted using the
     1342                                                        // selection.
     1343                                                        // \ufeff = Zero Width No-Break Space (U+FEFF). (#1359)
     1344                                                        this.document.createText( '\ufeff' ).insertBefore( startNode );
     1345                                                }
     1346                                        }
     1347                                }
     1348                                catch( er ){}
     1349                                // Make sure the bookmark nodes are removed even if making the selection fails. (#7106)
     1350                                finally
     1351                                {
     1352                                        // Remove the markers (reset the position, because of the changes in the DOM tree).
     1353                                        this.setStartBefore( startNode );
     1354                                        startNode.remove();
     1355                                }
    13481356
    13491357                                if ( collapsed )
    13501358                                {
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy