Ticket #3475: 3475.patch

File 3475.patch, 1.1 KB (added by Garry Yao, 11 years ago)
  • _source/plugins/styles/plugin.js

     
    10291029
    10301030        function applyStyle( document, remove )
    10311031        {
    1032                 // Get all ranges from the selection.
    1033                 var selection = document.getSelection();
    1034                 var ranges = selection.getRanges();
     1032                // Creating bookmarks here, since the range might be
     1033                // mangled during processing.
     1034                var selection = document.getSelection(),
     1035                        ranges = selection.getRanges(),
     1036                        bookmarks = selection.createBookmarks();
    10351037                var func = remove ? this.removeFromRange : this.applyToRange;
    10361038
    1037                 // Apply the style to the ranges.
    1038                 for ( var i = 0 ; i < ranges.length ; i++ )
     1039                // Apply the style to the ranges in reverse order to avoid
     1040                // range changes could impact on others. (#3475)
     1041                for ( var i = ranges.length - 1 ; i >= 0 ; i-- )
    10391042                        func.call( this, ranges[ i ] );
    10401043
    1041                 // Select the ranges again.
    1042                 selection.selectRanges( ranges );
     1044                selection.selectBookmarks( bookmarks );
    10431045        }
    10441046})();
    10451047
© 2003 – 2019 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy