Skip to content

Commit a5f8c73

Browse files
committed
Merge branch 't/12750b'
2 parents 3f0ab19 + 55ac525 commit a5f8c73

File tree

3 files changed

+232
-5
lines changed

3 files changed

+232
-5
lines changed

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Fixed Issues:
77

88
* [#12747](http://dev.ckeditor.com/ticket/12747): [IE8-10] Fixed: Opening a drop-down for a specific selection when editor is maximized results in incorrect drop-down panel position.
99
* [#12735](http://dev.ckeditor.com/ticket/12735): Fixed: [`Config.fillEmptyBlocks`](http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-fillEmptyBlocks) should only apply when outputting data.
10+
* [#12750](http://dev.ckeditor.com/ticket/12750): Fixed: [Paste from Word](http://ckeditor.com/addon/pastefromword): strikethrough and underscore should have the same color as font.
1011

1112
## CKEditor 4.4.6
1213

@@ -75,7 +76,7 @@ Fixed Issues:
7576
Fixed Issues:
7677

7778
* [#12268](http://dev.ckeditor.com/ticket/12268): Cleanup of [UI Color](http://ckeditor.com/addon/uicolor) YUI styles. Thanks to [CasherWest](https://github.com/CasherWest)!
78-
* [#12263](http://dev.ckeditor.com/ticket/12263): Fixed: [Paste from Word]((http://ckeditor.com/addon/pastefromword)) filter does not properly normalize semicolons style text. Thanks to [Alin Purcaru](https://github.com/mesmerizero)!
79+
* [#12263](http://dev.ckeditor.com/ticket/12263): Fixed: [Paste from Word](http://ckeditor.com/addon/pastefromword) filter does not properly normalize semicolons style text. Thanks to [Alin Purcaru](https://github.com/mesmerizero)!
7980
* [#12243](http://dev.ckeditor.com/ticket/12243): Fixed: Text formatting lost when pasting from Word. Thanks to [Alin Purcaru](https://github.com/mesmerizero)!
8081
* [#111739](http://dev.ckeditor.com/ticket/11739): Fixed: `keypress` listeners should not be used in the undo manager. A complete rewrite of keyboard handling in the undo manager was made. Numerous smaller issues were fixed, among others:
8182
* [#10926](http://dev.ckeditor.com/ticket/10926): [Chrome@Android] Fixed: Typing does not record snapshots and does not fire the [`editor.change`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-change) event.

plugins/pastefromword/filter/default.js

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,37 @@
636636

637637
// A filter which will be used to apply inline css style according the stylesheet
638638
// definition rules, is generated lazily when filtering.
639-
applyStyleFilter: null
639+
applyStyleFilter: null,
640640

641+
// Move element close to the child text elements.
642+
// Return `1` is element was moved, `0` otherwise.
643+
moveToText: function( element ) {
644+
var children = element.children,
645+
isEmpty = !children.length,
646+
hasTextOnly = ( children.length == 1 && children[ 0 ].type == CKEDITOR.NODE_TEXT );
647+
648+
// Do not move elements marked as moved. Otherwise we will have infinite loop if two elements
649+
// (<s> and <u>) would try to move.
650+
if ( element._.moved || isEmpty || hasTextOnly ) {
651+
return 0;
652+
}
653+
654+
// Wrap every child text node.
655+
element.forEach( function( node ) {
656+
if ( node.type == CKEDITOR.NODE_TEXT ) {
657+
658+
var wrapper = new CKEDITOR.htmlParser.element( element.name, element.attributes );
659+
wrapper._.moved = 1;
660+
661+
node.wrapWith( wrapper );
662+
}
663+
} );
664+
665+
// Replace element with children.
666+
element.name = null;
667+
668+
return 1;
669+
}
641670
},
642671

643672
getRules: function( editor, filter ) {
@@ -652,6 +681,7 @@
652681
createListBulletMarker = this.utils.createListBulletMarker,
653682
flattenList = filters.flattenList,
654683
assembleList = filters.assembleList,
684+
moveToText = filters.moveToText,
655685
isListBulletIndicator = this.utils.isListBulletIndicator,
656686
containsNothingButSpaces = this.utils.isContainingOnlySpaces,
657687
resolveListItem = this.utils.resolveList,
@@ -817,7 +847,7 @@
817847
delete element.name;
818848
element.add( new CKEDITOR.htmlParser.element( 'br' ) );
819849
} else {
820-
elementMigrateFilter( config['format_' + ( config.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' )] )( element );
850+
elementMigrateFilter( config[ 'format_' + ( config.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ] )( element );
821851
}
822852
},
823853

@@ -957,11 +987,22 @@
957987
// Migrate basic style formats to editor configured ones.
958988
b: elementMigrateFilter( config.coreStyles_bold ),
959989
i: elementMigrateFilter( config.coreStyles_italic ),
960-
u: elementMigrateFilter( config.coreStyles_underline ),
961-
s: elementMigrateFilter( config.coreStyles_strike ),
962990
sup: elementMigrateFilter( config.coreStyles_superscript ),
963991
sub: elementMigrateFilter( config.coreStyles_subscript ),
964992

993+
// Move <s> and <u> close to the text elements so other styles (like color) will be applied also
994+
// on underline and strike. Call `elementMigrateFilter` on elements which were not moved (#12750).
995+
s: function( element ) {
996+
if ( !moveToText( element ) ) {
997+
elementMigrateFilter( config.coreStyles_strike )( element );
998+
}
999+
},
1000+
u: function( element ) {
1001+
if ( !moveToText( element ) ) {
1002+
elementMigrateFilter( config.coreStyles_underline )( element );
1003+
}
1004+
},
1005+
9651006
// Remove full paths from links to anchors.
9661007
a: function( element ) {
9671008
var attrs = element.attributes;
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/* bender-tags: editor,unit */
2+
/* bender-ckeditor-plugins: pastefromword,toolbar,basicstyles,font,colorbutton */
3+
/* bender-include: %BASE_PATH%plugins/clipboard/_helpers/pasting.js */
4+
/* global assertPasteEvent */
5+
6+
( function() {
7+
'use strict';
8+
9+
var editorsDefinitions = {
10+
classic: {
11+
name: 'classic',
12+
config: {
13+
pasteFromWordRemoveFontStyles: false,
14+
allowedContent: true
15+
}
16+
},
17+
customStyle: {
18+
name: 'customStyle',
19+
config: {
20+
pasteFromWordRemoveFontStyles: false,
21+
coreStyles_strike: {
22+
element: 'sub',
23+
overrides: 'strike'
24+
},
25+
coreStyles_underline: {
26+
element: 'sup',
27+
overrides: 'underline'
28+
},
29+
allowedContent: true
30+
}
31+
}
32+
};
33+
34+
function createPasteTest( editor, input, output ) {
35+
return function() {
36+
assertPasteEvent( editor, { dataValue: input }, { dataValue: output }, '', true );
37+
};
38+
}
39+
40+
// jscs:disable maximumLineLength
41+
bender.tools.setUpEditors( editorsDefinitions, function( editors ) {
42+
bender.test( {
43+
'test strike': createPasteTest(
44+
editors.classic,
45+
// Input
46+
'<p class="MsoNormal"><s>foo<o:p></o:p></s></p>',
47+
// Output
48+
'<p><s>foo</s></p>'
49+
),
50+
51+
'test underline': createPasteTest(
52+
editors.classic,
53+
// Input
54+
'<p class="MsoNormal"><u>foo<o:p></o:p></u></p>',
55+
// Output
56+
'<p><u>foo</u></p>'
57+
),
58+
59+
'test strike, underline': createPasteTest(
60+
editors.classic,
61+
// Input
62+
'<p class="MsoNormal"><s><u>foo<o:p></o:p></u></s></p>',
63+
// Output
64+
'<p><s><u>foo</u></s></p>'
65+
),
66+
'test strike, color': createPasteTest(
67+
editors.classic,
68+
// Input
69+
'<p class="MsoNormal"><s><span style="color:red">foo<o:p></o:p></span></s></p>',
70+
// Output
71+
'<p><span style="color:red;"><s>foo</s></span></p>'
72+
),
73+
74+
'test underline, color': createPasteTest(
75+
editors.classic,
76+
// Input
77+
'<p class="MsoNormal"><u><span style="color:red">foo<o:p></o:p></span></u></p>',
78+
// Output
79+
'<p><span style="color:red;"><u>foo</u></span></p>'
80+
),
81+
82+
'test strike, underline, color': createPasteTest(
83+
editors.classic,
84+
// Input
85+
'<p class="MsoNormal"><s><u><span style="color:red">foo<o:p></o:p></span></u></s></p>',
86+
// Output
87+
'<p><span style="color:red;"><s><u>foo</u></s></span></p>'
88+
),
89+
'test strike, color, font, size, bold': createPasteTest(
90+
editors.classic,
91+
// Input
92+
'<p class="MsoNormal"><b><s><span style="font-size:22.2pt;line-height:107%;font-family:&quot;Comic Sans MS&quot;;\ncolor:red">foo<o:p></o:p></span></s></b></p>',
93+
// Output
94+
'<p><strong><span style="color:red;"><span style="font-family:comic sans ms;"><span style="font-size:22.2pt;"><s>foo</s></span></span></span></strong></p>'
95+
),
96+
97+
'test underline, color, font, size, bold': createPasteTest(
98+
editors.classic,
99+
// Input
100+
'<p class="MsoNormal"><b><u><span style="font-size:22.2pt;line-height:107%;font-family:&quot;Comic Sans MS&quot;;\ncolor: red">foo<o:p></o:p></span></u></b></p>',
101+
// Output
102+
'<p><strong><span style="color:red;"><span style="font-family:comic sans ms;"><span style="font-size:22.2pt;"><u>foo</u></span></span></span></strong></p>'
103+
),
104+
105+
'test strike, underline, color, font, size, bold': createPasteTest(
106+
editors.classic,
107+
// Input
108+
'<p class="MsoNormal"><b><s><u><span style="font-size:22.2pt;line-height:107%;font-family:&quot;Comic Sans MS&quot;;\ncolor: red">foo<o:p></o:p></span></u></s></b></p>',
109+
// Output
110+
'<p><strong><span style="color:red;"><span style="font-family:comic sans ms;"><span style="font-size:22.2pt;"><s><u>foo</u></s></span></span></span></strong></p>'
111+
),
112+
113+
'test empty paragraph end, strike, underline, color': createPasteTest(
114+
editors.classic,
115+
// Input
116+
'<p class="MsoNormal"><s><u><span style="color:red">Foo<o:p></o:p></span></u></s></p>' +
117+
'<p class="MsoNormal"><s><u><span style="color:red">&nbsp;</span></u></s></p>' +
118+
'<p class="MsoNormal"><s><u><span style="color:red">bar<o:p></o:p></span></u></s></p>',
119+
// Output
120+
'<p><span style="color:red;"><s><u>Foo</u></s></span></p>' +
121+
'<p>&nbsp;</p>' +
122+
'<p><span style="color:red;"><s><u>bar</u></s></span></p>'
123+
),
124+
125+
'test empty paragraph middle, strike, underline, color': createPasteTest(
126+
editors.classic,
127+
// Input
128+
'<p class="MsoNormal"><s><u><span style="color:red">Foo<o:p></o:p></span></u></s></p>' +
129+
'<p class="MsoNormal"><s><u><span style="color:red">&nbsp;</span></u></s></p>',
130+
// Output
131+
'<p><span style="color:red;"><s><u>Foo</u></s></span></p>' +
132+
'<p>&nbsp;</p>'
133+
),
134+
135+
'test two colors, strike, underline': createPasteTest(
136+
editors.classic,
137+
// Input
138+
'<p class="MsoNormal"><s><u><span style="color:red">Foo </span><span style="color:green">bar</span><span style="color:red"><o:p></o:p></span></u></s></p>',
139+
// Output
140+
'<p><span style="color:red;"><s><u>Foo </u></s></span><span style="color:green;"><s><u>bar</u></s></span><span style="color:red;"></span></p>'
141+
),
142+
143+
'test customStyle, strike': createPasteTest(
144+
editors.customStyle,
145+
// Input
146+
'<p class="MsoNormal"><s>foo<o:p></o:p></s></p>',
147+
// Output
148+
'<p><sub>foo</sub></p>'
149+
),
150+
151+
'test customStyle, underline': createPasteTest(
152+
editors.customStyle,
153+
// Input
154+
'<p class="MsoNormal"><u>foo<o:p></o:p></u></p>',
155+
// Output
156+
'<p><sup>foo</sup></p>'
157+
),
158+
159+
'test customStyle, strike, color': createPasteTest(
160+
editors.customStyle,
161+
// Input
162+
'<p class="MsoNormal"><s><span style="color:red">foo<o:p></o:p></span></s></p>',
163+
// Output
164+
'<p><span style="color:red;"><sub>foo</sub></span></p>'
165+
),
166+
167+
'test customStyle, underline, color': createPasteTest(
168+
editors.customStyle,
169+
// Input
170+
'<p class="MsoNormal"><u><span style="color:red">foo<o:p></o:p></span></u></p>',
171+
// Output
172+
'<p><span style="color:red;"><sup>foo</sup></span></p>'
173+
),
174+
175+
'test customStyle, strike, underline, color, font, size, bold': createPasteTest(
176+
editors.customStyle,
177+
// Input
178+
'<p class="MsoNormal"><b><s><u><span style="font-size:22.2pt;line-height:107%;font-family:&quot;Comic Sans MS&quot;;\ncolor:red">foo<o:p></o:p></span></u></s></b></p>',
179+
// Output
180+
'<p><strong><span style="color:red;"><span style="font-family:comic sans ms;"><span style="font-size:22.2pt;"><sub><sup>foo</sup></sub></span></span></span></strong></p>'
181+
)
182+
} );
183+
} );
184+
// jscs:enable
185+
} )();

0 commit comments

Comments
 (0)