Ticket #1630: 1630_2_ref.patch
File 1630_2_ref.patch, 10.0 KB (added by , 15 years ago) |
---|
-
_source/plugins/undo/plugin.js
22 22 { 23 23 exec : function() 24 24 { 25 console.log('UNDO request') 25 26 if ( undoManager.undo() ) 26 27 { 27 28 editor.selectionChange(); … … 29 30 } 30 31 }, 31 32 state : CKEDITOR.TRISTATE_DISABLED, 32 canUndo : false 33 canUndo : false, 34 modes : { wysiwyg : 1, source : 1 } 33 35 }); 34 36 35 37 var redoCommand = editor.addCommand( 'redo', 36 38 { 37 39 exec : function() 38 40 { 41 console.log('REDO request') 39 42 if ( undoManager.redo() ) 40 43 { 41 44 editor.selectionChange(); … … 43 46 } 44 47 }, 45 48 state : CKEDITOR.TRISTATE_DISABLED, 46 canUndo : false 49 canUndo : false, 50 modes : { wysiwyg : 1, source : 1 } 47 51 }); 48 52 49 53 undoManager.onChange = function() … … 80 84 }); 81 85 }); 82 86 87 // Registering keydown on every source area recreation. 88 editor.on( 'contentSource', function( e ) 89 { 90 e.data.on( 'keydown', function( event ) 91 { 92 // Do not capture CTRL hotkeys. 93 if ( !event.data.$.ctrlKey && !event.data.$.metaKey ) 94 undoManager.type( event ); 95 }); 96 }); 97 83 98 // Always save an undo snapshot - the previous mode might have 84 99 // changed editor contents. 85 100 editor.on( 'beforeModeUnload', function() … … 87 102 editor.mode == 'wysiwyg' && undoManager.save( true ); 88 103 }); 89 104 90 // Make the undo manager available only in wysiwyg mode.91 editor.on( 'mode', function()92 {93 undoManager.enabled = editor.mode == 'wysiwyg';94 undoManager.onChange();95 });96 97 105 editor.ui.addButton( 'Undo', 98 106 { 99 107 label : editor.lang.undo, … … 122 130 { 123 131 var selection = editor.getSelection(); 124 132 125 this.contents = editor.getSnapshot(); 133 this.mode = {}; 134 this.mode[ editor.mode ] = { contents : editor.getSnapshot() }; 135 // TODO normalize bookmarks per mode ? 126 136 this.bookmarks = selection && selection.createBookmarks2( true ); 127 137 128 138 // In IE, we need to remove the expando attributes. 129 139 if ( CKEDITOR.env.ie ) 130 this. contents = this.contents.replace( /\s+_cke_expando=".*?"/g, '' );140 this.mode[ editor.mode ].contents = this.contents.replace( /\s+_cke_expando=".*?"/g, '' ); 131 141 } 132 142 133 143 Image.prototype = 134 144 { 135 equals : function( otherImage, contentOnly )145 equals : function( otherImage, contentOnly, editor ) 136 146 { 137 if ( this. contents != otherImage.contents)147 if ( this.getContents( editor ) != otherImage.getContents( editor ) ) 138 148 return false; 139 149 140 150 if ( contentOnly ) 141 151 return true; 142 152 153 // TODO normalize bookmarks per mode ? 143 154 var bookmarksA = this.bookmarks, 144 155 bookmarksB = otherImage.bookmarks; 145 156 … … 165 176 } 166 177 167 178 return true; 179 }, 180 181 getContents : function( editor ) 182 { 183 // Initialize actual editor's mode for this image if missing. 184 if ( !this.mode[ editor.mode ] ) 185 { 186 this.mode[ editor.mode ] = {}; 187 188 // Normalize data from first available mode. 189 for ( var i in this.mode ) 190 return this.mode[ editor.mode ].contents = editor.normalizeSnapshotData( this.mode[ i ].contents ); 191 } 192 return this.mode[ editor.mode ].contents; 168 193 } 169 194 }; 170 195 … … 174 199 function UndoManager( editor ) 175 200 { 176 201 this.editor = editor; 202 this.enabled = true; 177 203 178 204 // Reset the undo stack. 179 205 this.reset(); … … 318 344 }, 319 345 fireChange : function() 320 346 { 347 console.log( 'fireChange()') 321 348 this.hasUndo = !!this.getNextImage( true ); 322 349 this.hasRedo = !!this.getNextImage( false ); 323 350 // Reset typing … … 337 364 image = new Image( this.editor ); 338 365 339 366 // Check if this is a duplicate. In such case, do nothing. 340 if ( this.currentImage && image.equals( this.currentImage, onContentOnly ) )367 if ( this.currentImage && image.equals( this.currentImage, onContentOnly, this.editor ) ) 341 368 return false; 342 369 343 370 // Drop future snapshots. … … 359 386 360 387 restoreImage : function( image ) 361 388 { 362 this.editor.loadSnapshot( image. contents);389 this.editor.loadSnapshot( image.getContents( this.editor ) ); 363 390 364 if ( image.bookmarks ) 365 this.editor.getSelection().selectBookmarks( image.bookmarks ); 391 var selection = image.bookmarks && this.editor.getSelection(); 392 if ( selection ) 393 selection.selectBookmarks( image.bookmarks ); 394 // TODO range 366 395 else if ( CKEDITOR.env.ie ) 367 396 { 368 397 // IE BUG: If I don't set the selection to *somewhere* after setting … … 374 403 } 375 404 376 405 this.index = image.index; 377 406 console.log('UPDATE currentImage') 378 407 this.currentImage = image; 379 408 380 409 this.fireChange(); … … 387 416 currentImage = this.currentImage, 388 417 image, i; 389 418 419 console.log( 'getNextImage()' ); 420 390 421 if ( currentImage ) 391 422 { 423 console.log( 'currentImage.contents:\n', currentImage.getContents( this.editor ) ) 392 424 if ( isUndo ) 393 425 { 394 426 for ( i = this.index - 1 ; i >= 0 ; i-- ) 395 427 { 396 428 image = snapshots[ i ]; 397 if ( !currentImage.equals( image, true ) )429 if ( !currentImage.equals( image, true, this.editor ) ) 398 430 { 431 console.log( 'RETURN image.contents:\n', image.getContents( this.editor ) ) 399 432 image.index = i; 400 433 return image; 401 434 } 435 else console.log( 'image.contents:\n', image.getContents( this.editor ) ) 402 436 } 403 437 } 404 438 else … … 406 440 for ( i = this.index + 1 ; i < snapshots.length ; i++ ) 407 441 { 408 442 image = snapshots[ i ]; 409 if ( !currentImage.equals( image, true ) )443 if ( !currentImage.equals( image, true, this.editor ) ) 410 444 { 411 445 image.index = i; 412 446 return image; -
_source/plugins/sourcearea/plugin.js
15 15 init : function( editor ) 16 16 { 17 17 var sourcearea = CKEDITOR.plugins.sourcearea; 18 19 var fixForBody = ( editor.config.enterMode != CKEDITOR.ENTER_BR ) 20 ? editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' : false; 18 21 19 22 editor.on( 'editingBlockReady', function() 20 23 { … … 100 103 { 101 104 editor.mode = 'source'; 102 105 editor.fire( 'mode' ); 106 editor.fire( 'contentSource', textarea ); 103 107 }, 104 108 ( CKEDITOR.env.gecko || CKEDITOR.env.webkit ) ? 100 : 0 ); 105 109 }, … … 116 120 117 121 getSnapshotData : function() 118 122 { 123 var fixForBody = ( editor.config.enterMode != CKEDITOR.ENTER_BR ) 124 ? editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' : false; 125 console.log('REQUESTED undo snashot') 126 127 // if ( editor.dataProcessor ) 128 // { 129 // var rules = editor.dataProcessor.writer._.rules; 130 // // Reset rules to get non-formatted output. 131 // editor.dataProcessor.writer._.rules = []; 132 // var data = editor.dataProcessor.toDataFormat( textarea.getValue(), fixForBody ); 133 // editor.dataProcessor.writer._.rules = rules; 134 // return data; 135 // } 136 119 137 return textarea.getValue(); 120 138 }, 121 139 140 loadSnapshotData : function( data ) 141 { 142 textarea.setValue( data ); 143 144 console.log('LOADED undo snashot') 145 }, 146 147 normalizeSnapshotData : function( data ) 148 { 149 if ( editor.dataProcessor ) 150 data = editor.dataProcessor.toDataFormat( data, fixForBody ); 151 152 // TODO ? Strip the last blank paragraph within document. 153 // if ( editor.config.ignoreEmptyParagraph ) 154 // data = data.replace( emptyParagraphRegexp, '' ); 155 156 return data; 157 }, 158 122 159 unload : function( holderElement ) 123 160 { 124 161 editor.textarea = textarea = null; -
_source/plugins/editingblock/plugin.js
82 82 event.data = getMode( editor ).getSnapshotData(); 83 83 }); 84 84 85 editor.on( 'normalizeSnapshotData', function( event ) 86 { 87 if ( editor.mode ) 88 event.data = getMode( editor ).normalizeSnapshotData( event.data ); 89 }); 90 85 91 editor.on( 'loadSnapshot', function( event ) 86 92 { 87 93 if ( editor.mode ) -
_source/plugins/wysiwygarea/plugin.js
552 552 553 553 getSnapshotData : function() 554 554 { 555 console.log('REQUESTED undo snashot') 555 556 return iframe.getFrameDocument().getBody().getHtml(); 556 557 }, 557 558 … … 560 561 iframe.getFrameDocument().getBody().setHtml( data ); 561 562 }, 562 563 564 normalizeSnapshotData : function( data ) 565 { 566 return editor.dataProcessor 567 ? data = editor.dataProcessor.toHtml( data, fixForBody ) 568 : data; 569 }, 570 563 571 unload : function( holderElement ) 564 572 { 565 573 editor.window = editor.document = iframe = mainElement = isPendingFocus = null; -
_source/core/editor.js
474 474 execCommand : function( commandName, data ) 475 475 { 476 476 var command = this.getCommand( commandName ); 477 console.log('command.state: ' + command.state, command ) 477 478 478 479 var eventData = 479 480 { … … 559 560 return data; 560 561 }, 561 562 563 normalizeSnapshotData : function( data ) 564 { 565 return this.fire( 'normalizeSnapshotData', data ); 566 }, 567 562 568 loadSnapshot : function( snapshot ) 563 569 { 564 570 this.fire( 'loadSnapshot', snapshot );