Ticket #4944: 4944_2.patch
File 4944_2.patch, 4.5 KB (added by , 13 years ago) |
---|
-
_source/plugins/pastefromword/filter/default.js
123 123 var cssLengthRelativeUnit = /^(\d[.\d]*)+(em|ex|px|gd|rem|vw|vh|vm|ch|mm|cm|in|pt|pc|deg|rad|ms|s|hz|khz){1}?/i; 124 124 var emptyMarginRegex = /^(?:\b0[^\s]*\s*){1,4}$/; 125 125 126 var listBaseIndent; 126 var listBaseIndent = 0, 127 previousListItemMargin; 127 128 128 129 CKEDITOR.plugins.pastefromword = 129 130 { … … 217 218 [ 'text-indent' ], 218 219 [ 'line-height' ], 219 220 // Resolve indent level from 'margin-left' value. 220 [ ( /^margin(:?-left)?$/ ), null, function( value)221 [ ( /^margin(:?-left)?$/ ), null, function( margin ) 221 222 { 222 223 // Be able to deal with component/short-hand form style. 223 var values = value.split( ' ' );224 value= values[ 3 ] || values[ 1 ] || values [ 0 ];225 value = parseInt( value, 10 );224 var values = margin.split( ' ' ); 225 margin = values[ 3 ] || values[ 1 ] || values [ 0 ]; 226 margin = parseInt( margin, 10 ); 226 227 227 // Figure out the indent unit by looking at the first list item. 228 !listBaseIndent && ( listBaseIndent = value ); 228 // Figure out the indent unit by looking at the first increament. 229 if ( !listBaseIndent && previousListItemMargin && margin > previousListItemMargin ) 230 listBaseIndent = margin - previousListItemMargin; 229 231 230 // Indent level start with one. 231 attrs[ 'cke:indent' ] = Math.floor( value / listBaseIndent ) + 1; 232 attrs[ 'cke:margin' ] = previousListItemMargin = margin; 232 233 } ] 233 234 ] )( attrs.style, element ) || '' ; 234 235 } … … 241 242 CKEDITOR.tools.extend( attrs, listBulletAttrs ); 242 243 return true; 243 244 } 244 // Indicate a list has ended.245 else246 listBaseIndent = 0;247 245 248 246 return false; 249 247 }, … … 349 347 350 348 child.name = 'cke:li'; 351 349 attributes[ 'cke:indent' ] = indentLevel; 350 previousListItemMargin = 0; 352 351 attributes[ 'cke:listtype' ] = element.name; 353 352 listStyleType && child.addStyle( 'list-style-type', listStyleType, true ); 354 353 } … … 386 385 listItem = child; 387 386 listItemAttrs = listItem.attributes; 388 387 listType = listItem.attributes[ 'cke:listtype' ]; 389 // The indent attribute might not present.390 listItemIndent = parseInt( listItemAttrs[ 'cke:indent' ], 10 ) || 0;391 388 389 // List item indent level might come from a real list indentation or 390 // been resolved from a pseudo list item's margin value, even get 391 // no indentation at all. 392 listItemIndent = parseInt( listItemAttrs[ 'cke:indent' ], 10 ) 393 || listBaseIndent && ( Math.ceil( listItemAttrs[ 'cke:margin' ] / listBaseIndent ) ) 394 || 1; 395 392 396 // Ignore the 'list-style-type' attribute if it's matched with 393 397 // the list root element's default style type. 394 398 listItemAttrs.style && ( listItemAttrs.style = … … 400 404 401 405 if ( !list ) 402 406 { 403 parentList =list = new CKEDITOR.htmlParser.element( listType );407 list = new CKEDITOR.htmlParser.element( listType ); 404 408 list.add( listItem ); 405 409 children[ i ] = list; 406 410 } … … 408 412 { 409 413 if ( listItemIndent > indent ) 410 414 { 411 parentList = list;412 415 list = new CKEDITOR.htmlParser.element( listType ); 413 416 list.add( listItem ); 414 417 lastListItem.add( list ); 415 418 } 416 419 else if ( listItemIndent < indent ) 417 420 { 418 list = parentList; 419 parentList = list.parent ? list.parent.parent : list; 421 // There might be a negative gap between two list levels. (#4944) 422 var diff = indent - listItemIndent, 423 parent = list.parent; 424 while( diff-- && parent ) 425 list = parent.parent; 426 420 427 list.add( listItem ); 421 428 } 422 429 else … … 431 438 else 432 439 list = null; 433 440 } 441 442 listBaseIndent = 0; 434 443 }, 435 444 436 445 /** … … 1130 1139 // Remove the dummy spans ( having no inline style ). 1131 1140 data = data.replace( /<span>/g, '' ); 1132 1141 1133 // Clean up certain stateful session variables.1134 listBaseIndent = 0;1135 1142 return data; 1136 1143 }; 1137 1144 })();