Ticket #1990: 1990_2.patch

File 1990_2.patch, 20.5 KB (added by Frederico Caldeira Knabben, 16 years ago)
  • _whatsnew.html

     
    115115                <li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/1792">#1792</a>] In IE,
    116116                        the browser was able to enter in an infinite loop when working with multiple editors
    117117                        in the same page. </li>
     118                <li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/1990">#1990</a>] In IE,
     119                        dialogs using API calls which deals with the selection, like InsertHtml now can
     120                        be sure the selection will be placed in the correct position.</li>
    118121        </ul>
    119122        <h3>
    120123                Version 2.6 Beta 1</h3>
  • editor/_source/commandclasses/fcklistcommands.js

     
    145145                                if ( rangeQueue == null )
    146146                                {
    147147                                        rangeQueue = [] ;
    148                                         var selectionObject = FCK.EditorWindow.getSelection() ;
     148                                        var selectionObject = FCKSelection.GetSelection() ;
    149149                                        if ( selectionObject && listGroups.length == 0 )
    150150                                                rangeQueue.push( selectionObject.getRangeAt( 0 ) ) ;
    151151                                        for ( var i = 1 ; selectionObject && i < selectionObject.rangeCount ; i++ )
  • editor/_source/internals/fck.js

     
    660660
    661661                var elementName = element.nodeName.toLowerCase() ;
    662662
     663                FCKSelection.Restore() ;
     664
    663665                // Create a range for the selection. V3 will have a new selection
    664666                // object that may internally supply this feature.
    665667                var range = new FCKDomRange( this.EditorWindow ) ;
     
    863865        {
    864866                // Prevent the caret from going between the body and the padding node in Firefox.
    865867                // i.e. <body>|<p></p></body>
    866                 var sel = FCK.EditorWindow.getSelection() ;
     868                var sel = FCKSelection.GetSelection() ;
    867869                if ( sel && sel.rangeCount == 1 )
    868870                {
    869871                        var range = sel.getRangeAt( 0 ) ;
  • editor/_source/internals/fck_gecko.js

     
    8888
    8989                var moveCursor = function()
    9090                {
    91                         var selection = FCK.EditorWindow.getSelection() ;
     91                        var selection = FCKSelection.GetSelection() ;
    9292                        var range = selection.getRangeAt(0) ;
    9393                        if ( ! range || ! range.collapsed )
    9494                                return ;
     
    448448FCK._ExecCheckEmptyBlock = function()
    449449{
    450450        FCK._FillEmptyBlock( FCK.EditorDocument.body.firstChild ) ;
    451         var sel = FCK.EditorWindow.getSelection() ;
     451        var sel = FCKSelection.GetSelection() ;
    452452        if ( !sel || sel.rangeCount < 1 )
    453453                return ;
    454454        var range = sel.getRangeAt( 0 );
  • editor/_source/internals/fck_ie.js

     
    9393function Doc_OnSelectionChange()
    9494{
    9595        // Don't fire the event if no document is loaded.
    96         if ( FCK.EditorDocument )
     96        if ( !FCK.IsSelectionChangeLocked && FCK.EditorDocument )
    9797                FCK.Events.FireEvent( "OnSelectionChange" ) ;
    9898}
    9999
     
    155155        FCKUndo.SaveUndoStep() ;
    156156
    157157        // Gets the actual selection.
    158         var oSel = FCK.EditorDocument.selection ;
     158        var oSel = FCKSelection.GetSelection() ;
    159159
    160160        // Deletes the actual selection contents.
    161161        if ( oSel.type.toLowerCase() == 'control' )
  • editor/_source/internals/fckdialog.js

     
    7676        }
    7777
    7878        return {
    79                 SelectionData : null,
    80 
    8179                /**
    8280                 * Opens a dialog window using the standard dialog template.
    8381                 */
     
    9391                                Page : dialogPage,
    9492                                Editor : window,
    9593                                CustomValue : customValue,              // Optional
    96                                 SelectionData : null,
    9794                                TopWindow : topWindow
    9895                        }
    9996
    100                         var currentInstance = FCK.ToolbarSet.CurrentInstance ;
     97                        FCK.ToolbarSet.CurrentInstance.Selection.Save() ;
    10198
    102                         // IE doens't support multiple selections, even if in different
    103                         // IFRAMEs, like the dialog, so the current selection must be saved to
    104                         // be restored in the dialog code.
    105                         if ( FCKBrowserInfo.IsIE && !topDialog )
    106                         {
    107                                 // Ensures the editor has the selection focus. (#1801)
    108                                 currentInstance.Focus() ;
    109 
    110                                 var editorDocument = ( currentInstance.EditMode == FCK_EDITMODE_WYSIWYG ?
    111                                                 currentInstance.EditorDocument :
    112                                                 FCKTools.GetElementDocument( currentInstance.EditingArea.Textarea ) ) ;
    113                                 var selection = editorDocument.selection ;
    114                                 var range ;
    115 
    116                                 if ( selection )
    117                                 {
    118                                         range = selection.createRange() ;
    119 
    120                                         // Ensure that the range comes from the editor document.
    121                                         if ( range )
    122                                         {
    123                                                 if ( range.parentElement && FCKTools.GetElementDocument( range.parentElement() ) != editorDocument )
    124                                                         range = null ;
    125                                                 else if ( range.item && FCKTools.GetElementDocument( range.item(0) )!= editorDocument )
    126                                                         range = null ;
    127                                         }
    128                                 }
    129 
    130                                 this.SelectionData = range ;
    131                         }
    132 
    13399                        // Calculate the dialog position, centering it on the screen.
    134100                        var viewSize = FCKTools.GetViewPaneSize( topWindow ) ;
    135101                        var scrollPosition = FCKTools.GetScrollPosition( topWindow ) ;
     
    183149                        else                                                    // First Dialog.
    184150                        {
    185151                                // Set the Focus in the browser, so the "OnBlur" event is not
    186                                 // fired. In IE, there is no need to d othat because the dialog
     152                                // fired. In IE, there is no need to do that because the dialog
    187153                                // already moved the selection to the editing area before
    188154                                // closing (EnsureSelection). Also, the Focus() call here
    189155                                // causes memory leak on IE7 (weird).
     
    193159                                this.HideMainCover() ;
    194160                                // Bug #1918: Assigning topDialog = null directly causes IE6 to crash.
    195161                                setTimeout( function(){ topDialog = null ; }, 0 ) ;
    196                                 this.SelectionData = null ;
     162
     163                                // Release the previously saved selection.
     164                                FCK.ToolbarSet.CurrentInstance.Selection.Release() ;
    197165                        }
    198166                },
    199167
  • editor/_source/internals/fckselection_gecko.js

     
    3030        // Check if the actual selection is a Control (IMG, TABLE, HR, etc...).
    3131
    3232        var sel ;
    33         try { sel = FCK.EditorWindow.getSelection() ; } catch (e) {}
     33        try { sel = this.GetSelection() ; } catch (e) {}
    3434
    3535        if ( sel && sel.rangeCount == 1 )
    3636        {
     
    5151// element (object like and image or a table) is selected.
    5252FCKSelection.GetSelectedElement = function()
    5353{
    54         var selection = !!FCK.EditorWindow && FCK.EditorWindow.getSelection() ;
     54        var selection = !!FCK.EditorWindow && this.GetSelection() ;
    5555        if ( !selection || selection.rangeCount < 1 )
    5656                return null ;
    5757
     
    7272                return FCKSelection.GetSelectedElement().parentNode ;
    7373        else
    7474        {
    75                 var oSel = FCK.EditorWindow.getSelection() ;
     75                var oSel = this.GetSelection() ;
    7676                if ( oSel )
    7777                {
    7878                        // make the common case fast - for collapsed/nearly collapsed selections just return anchor.parent.
     
    117117                return FCKSelection.GetSelectedElement().parentNode ;
    118118        else
    119119        {
    120                 var oSel = FCK.EditorWindow.getSelection() ;
     120                var oSel = this.GetSelection() ;
    121121                if ( oSel && oSel.rangeCount > 0 )
    122122                {
    123123                        var range = oSel.getRangeAt( startBoundary ? 0 : ( oSel.rangeCount - 1 ) ) ;
     
    135135        var oRange = FCK.EditorDocument.createRange() ;
    136136        oRange.selectNode( element ) ;
    137137
    138         var oSel = FCK.EditorWindow.getSelection() ;
     138        var oSel = this.GetSelection() ;
    139139        oSel.removeAllRanges() ;
    140140        oSel.addRange( oRange ) ;
    141141}
    142142
    143143FCKSelection.Collapse = function( toStart )
    144144{
    145         var oSel = FCK.EditorWindow.getSelection() ;
     145        var oSel = this.GetSelection() ;
    146146
    147147        if ( toStart == null || toStart === true )
    148148                oSel.collapseToStart() ;
     
    156156        var oContainer = this.GetSelectedElement() ;
    157157        if ( ! oContainer && FCK.EditorWindow )
    158158        {
    159                 try             { oContainer = FCK.EditorWindow.getSelection().getRangeAt(0).startContainer ; }
     159                try             { oContainer = this.GetSelection().getRangeAt(0).startContainer ; }
    160160                catch(e){}
    161161        }
    162162
     
    176176
    177177        var oContainer = this.GetSelectedElement() ;
    178178        if ( ! oContainer )
    179                 oContainer = FCK.EditorWindow.getSelection().getRangeAt(0).startContainer ;
     179                oContainer = this.GetSelection().getRangeAt(0).startContainer ;
    180180
    181181        while ( oContainer )
    182182        {
     
    191191FCKSelection.Delete = function()
    192192{
    193193        // Gets the actual selection.
    194         var oSel = FCK.EditorWindow.getSelection() ;
     194        var oSel = this.GetSelection() ;
    195195
    196196        // Deletes the actual selection contents.
    197197        for ( var i = 0 ; i < oSel.rangeCount ; i++ )
     
    201201
    202202        return oSel ;
    203203}
     204
     205/**
     206 * Returns the native selection object.
     207 */
     208FCKSelection.GetSelection = function()
     209{
     210        return FCK.EditorWindow.getSelection() ;
     211}
     212
     213// The following are IE only features (we don't need then in other browsers
     214// currently).
     215FCKSelection.Save = function()
     216{}
     217FCKSelection.Restore = function()
     218{}
     219FCKSelection.Release = function()
     220{}
  • editor/_source/internals/fckselection_ie.js

     
    2828        // So we'd better check the object returned by createRange() rather than by looking at the type.
    2929        try
    3030        {
    31                 var ieType = FCK.EditorDocument.selection.type ;
     31                var ieType = FCKSelection.GetSelection().type ;
    3232                if ( ieType == 'Control' || ieType == 'Text' )
    3333                        return ieType ;
    3434
    35                 if ( FCK.EditorDocument.selection.createRange().parentElement )
     35                if ( this.GetSelection().createRange().parentElement )
    3636                        return 'Text' ;
    3737        }
    3838        catch(e)
     
    4949{
    5050        if ( this.GetType() == 'Control' )
    5151        {
    52                 var oRange = FCK.EditorDocument.selection.createRange() ;
     52                var oRange = this.GetSelection().createRange() ;
    5353
    5454                if ( oRange && oRange.item )
    55                         return FCK.EditorDocument.selection.createRange().item(0) ;
     55                        return this.GetSelection().createRange().item(0) ;
    5656        }
    5757        return null ;
    5858} ;
     
    6969                        return null ;
    7070
    7171                default :
    72                         return FCK.EditorDocument.selection.createRange().parentElement() ;
     72                        return this.GetSelection().createRange().parentElement() ;
    7373        }
    7474} ;
    7575
     
    101101FCKSelection.SelectNode = function( node )
    102102{
    103103        FCK.Focus() ;
    104         FCK.EditorDocument.selection.empty() ;
     104        this.GetSelection().empty() ;
    105105        var oRange ;
    106106        try
    107107        {
     
    124124        FCK.Focus() ;
    125125        if ( this.GetType() == 'Text' )
    126126        {
    127                 var oRange = FCK.EditorDocument.selection.createRange() ;
     127                var oRange = this.GetSelection().createRange() ;
    128128                oRange.collapse( toStart == null || toStart === true ) ;
    129129                oRange.select() ;
    130130        }
     
    135135{
    136136        var oContainer ;
    137137
    138         if ( FCK.EditorDocument.selection.type == "Control" )
     138        if ( this.GetSelection().type == "Control" )
    139139        {
    140140                oContainer = this.GetSelectedElement() ;
    141141        }
    142142        else
    143143        {
    144                 var oRange  = FCK.EditorDocument.selection.createRange() ;
     144                var oRange  = this.GetSelection().createRange() ;
    145145                oContainer = oRange.parentElement() ;
    146146        }
    147147
     
    162162        if ( ! FCK.EditorDocument )
    163163                return null ;
    164164
    165         if ( FCK.EditorDocument.selection.type == "Control" )
     165        if ( this.GetSelection().type == "Control" )
    166166        {
    167                 oRange = FCK.EditorDocument.selection.createRange() ;
     167                oRange = this.GetSelection().createRange() ;
    168168                for ( i = 0 ; i < oRange.length ; i++ )
    169169                {
    170170                        if (oRange(i).parentNode)
     
    176176        }
    177177        else
    178178        {
    179                 oRange  = FCK.EditorDocument.selection.createRange() ;
     179                oRange  = this.GetSelection().createRange() ;
    180180                oNode = oRange.parentElement() ;
    181181        }
    182182
     
    189189FCKSelection.Delete = function()
    190190{
    191191        // Gets the actual selection.
    192         var oSel = FCK.EditorDocument.selection ;
     192        var oSel = this.GetSelection() ;
    193193
    194194        // Deletes the actual selection contents.
    195195        if ( oSel.type.toLowerCase() != "none" )
     
    199199
    200200        return oSel ;
    201201} ;
     202
     203/**
     204 * Returns the native selection object.
     205 */
     206FCKSelection.GetSelection = function()
     207{
     208        this.Restore() ;
     209        return FCK.EditorDocument.selection ;
     210}
     211
     212FCKSelection.Save = function()
     213{
     214        // Ensures the editor has the selection focus. (#1801)
     215        FCK.Focus() ;
     216
     217        var editorDocument = FCK.EditorDocument ;
     218       
     219        if ( !editorDocument )
     220                return ;
     221
     222        var selection = editorDocument.selection ;
     223        var range ;
     224
     225        if ( selection )
     226        {
     227                range = selection.createRange() ;
     228
     229                // Ensure that the range comes from the editor document.
     230                if ( range )
     231                {
     232                        if ( range.parentElement && FCKTools.GetElementDocument( range.parentElement() ) != editorDocument )
     233                                range = null ;
     234                        else if ( range.item && FCKTools.GetElementDocument( range.item(0) )!= editorDocument )
     235                                range = null ;
     236                }
     237        }
     238
     239        this.SelectionData = range ;
     240}
     241
     242FCKSelection.Restore = function()
     243{
     244        if ( this.SelectionData )
     245        {
     246                FCK.IsSelectionChangeLocked = true ;
     247
     248                try
     249                {
     250                        this.SelectionData.select() ;
     251                }
     252                catch ( e ) {}
     253
     254                FCK.IsSelectionChangeLocked = false ;
     255        }
     256}
     257
     258FCKSelection.Release = function()
     259{
     260        delete this.SelectionData ;                     
     261}
  • editor/_source/internals/fcktablehandler_gecko.js

     
    2525{
    2626        var aCells = new Array() ;
    2727
    28         var oSelection = FCK.EditorWindow.getSelection() ;
     28        var oSelection = FCKSelection.GetSelection() ;
    2929
    3030        // If the selection is a text.
    3131        if ( oSelection.rangeCount == 1 && oSelection.anchorNode.nodeType == 3 )
  • editor/_source/internals/fcktablehandler_ie.js

     
    3131
    3232        var aCells = new Array() ;
    3333
    34         var oRange = FCK.EditorDocument.selection.createRange() ;
     34        var oRange = FCKSelection.GetSelection().createRange() ;
    3535//      var oParent = oRange.parentElement() ;
    3636        var oParent = FCKSelection.GetParentElement() ;
    3737
  • editor/_source/internals/fckundo.js

     
    3131
    3232FCKUndo._GetBookmark = function()
    3333{
     34        FCKSelection.Restore() ;
     35
    3436        var range = new FCKDomRange( FCK.EditorWindow ) ;
    3537        try
    3638        {
  • editor/dialog/common/fck_dialog_common.js

     
    280280                                oldNode.parentNode.removeChild( oldNode ) ;
    281281                                oldNode = null ;
    282282
    283                                 if ( oEditor.FCKDialog.SelectionData )
     283                                if ( oEditor.FCK.Selection.SelectionData )
    284284                                {
    285                                         // Trick to refresh the selection object and avoid error in fckdialog.html Selection.EnsureSelection
     285                                        // Trick to refresh the selection object and avoid error in
     286                                        // fckdialog.html Selection.EnsureSelection
    286287                                        var oSel = oEditor.FCK.EditorDocument.selection ;
    287                                         oEditor.FCKDialog.SelectionData = oSel.createRange() ; // Now oSel.type will be 'None' reflecting the real situation
     288                                        oEditor.FCK.Selection.SelectionData = oSel.createRange() ; // Now oSel.type will be 'None' reflecting the real situation
    288289                                }
    289290                        }
    290291                        oNewNode = oEditor.FCK.InsertElement( oNewNode ) ;
    291292
    292                         // FCKDialog.SelectionData is broken by now since we've deleted the previously selected element.
    293                         // So we need to reassign it.
    294                         if ( oEditor.FCKDialog.SelectionData )
     293                        // FCK.Selection.SelectionData is broken by now since we've
     294                        // deleted the previously selected element. So we need to reassign it.
     295                        if ( oEditor.FCK.Selection.SelectionData )
    295296                        {
    296297                                var range = oEditor.FCK.EditorDocument.body.createControlRange() ;
    297298                                range.add( oNewNode ) ;
    298                                 oEditor.FCKDialog.SelectionData = range ;
     299                                oEditor.FCK.Selection.SelectionData = range ;
    299300                        }
    300301                }
    301302                else
  • editor/dialog/fck_image/fck_image.js

     
    250250                        oLink.href = sLnkUrl ;
    251251                else                    // Creating a new link.
    252252                {
    253                         dialog.Selection.EnsureSelection() ;
    254 
    255253                        if ( !bHasImage )
    256254                                oEditor.FCKSelection.SelectNode( oImage ) ;
    257255
  • editor/dialog/fck_link/fck_link.js

     
    638638        }
    639639
    640640        // Select the (first) link.
    641         dialog.Selection.EnsureSelection() ;
    642641        oEditor.FCKSelection.SelectNode( aLinks[0] );
    643642
    644643        return true ;
  • editor/dialog/fck_smiley.html

     
    4949
    5050function InsertSmiley( url )
    5151{
    52         dialog.Selection.EnsureSelection() ;
    53 
    5452        oEditor.FCKUndo.SaveUndoStep() ;
    5553
    5654        var oImg = oEditor.FCK.InsertElement( 'img' ) ;
  • editor/dialog/fck_specialchar.html

     
    4343function insertChar(charValue)
    4444{
    4545        oEditor.FCKUndo.SaveUndoStep() ;
    46         parent.Selection.EnsureSelection() ;
    4746        oEditor.FCK.InsertHtml( charValue || "" ) ;
    4847        window.parent.Cancel() ;
    4948}
  • editor/dialog/fck_tablecell.html

     
    3636var oDOM = oEditor.FCK.EditorDocument ;
    3737
    3838// Array of selected Cells
    39 dialog.Selection.EnsureSelection() ;
    4039var aCells = oEditor.FCKTableHandler.GetSelectedCells() ;
    4140
    4241window.onload = function()
  • editor/fckdialog.html

     
    375375}() ;
    376376
    377377// Selection related functions.
    378 var Selection = function()
     378//(Became simple shortcuts after the fix for #1990)
     379var Selection =
    379380{
    380         return {
    381                 /**
    382                  * Ensures that the editing area contains an active selection. This is a
    383                  * requirement for IE, as it looses the selection when the focus moves to other
    384                  * frames.
    385                  */
    386                 EnsureSelection : function()
    387                 {
    388                         if ( FCKDialog.SelectionData )
    389                         {
    390                                 try
    391                                 {
    392                                         FCKDialog.SelectionData.select() ;
    393                                 }
    394                                 catch ( e ) {}
    395                         }
    396                 },
     381        /**
     382         * Ensures that the editing area contains an active selection. This is a
     383         * requirement for IE, as it looses the selection when the focus moves to other
     384         * frames.
     385         */
     386        EnsureSelection : function()
     387        {
     388                FCK.Selection.Restore() ;
     389        },
    397390
    398                 /**
    399                  * Get the FCKSelection object for the editor instance.
    400                  */
    401                 GetSelection : function()
    402                 {
    403                         this.EnsureSelection() ;
    404                         return FCK.Selection ;
    405                 },
     391        /**
     392         * Get the FCKSelection object for the editor instance.
     393         */
     394        GetSelection : function()
     395        {
     396                return FCK.Selection ;
     397        },
    406398
    407                 /**
    408                  * Get the selected element in the editing area (for object selections).
    409                  */
    410                 GetSelectedElement : function()
    411                 {
    412                         return this.GetSelection().GetSelectedElement() ;
    413                 }
    414         } ;
    415 }() ;
     399        /**
     400         * Get the selected element in the editing area (for object selections).
     401         */
     402        GetSelectedElement : function()
     403        {
     404                return FCK.Selection.GetSelectedElement() ;
     405        }
     406}
    416407
    417408// Tab related functions.
    418409var Tabs = function()
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy