@@ -58,13 +58,35 @@ export function usePasteHandler( props ) {
58
58
const isInternal =
59
59
event . clipboardData . getData ( 'rich-text' ) === 'true' ;
60
60
61
+ function pasteInline ( content ) {
62
+ const transformed = formatTypes . reduce (
63
+ ( accumulator , { __unstablePasteRule } ) => {
64
+ // Only allow one transform.
65
+ if ( __unstablePasteRule && accumulator === value ) {
66
+ accumulator = __unstablePasteRule ( value , {
67
+ html,
68
+ plainText,
69
+ } ) ;
70
+ }
71
+
72
+ return accumulator ;
73
+ } ,
74
+ value
75
+ ) ;
76
+ if ( transformed !== value ) {
77
+ onChange ( transformed ) ;
78
+ } else {
79
+ const valueToInsert = create ( { html : content } ) ;
80
+ addActiveFormats ( valueToInsert , value . activeFormats ) ;
81
+ onChange ( insert ( value , valueToInsert ) ) ;
82
+ }
83
+ }
84
+
61
85
// If the data comes from a rich text instance, we can directly use it
62
86
// without filtering the data. The filters are only meant for externally
63
87
// pasted content and remove inline styles.
64
88
if ( isInternal ) {
65
- const pastedValue = create ( { html } ) ;
66
- addActiveFormats ( pastedValue , value . activeFormats ) ;
67
- onChange ( insert ( value , pastedValue ) ) ;
89
+ pasteInline ( html ) ;
68
90
return ;
69
91
}
70
92
@@ -135,28 +157,7 @@ export function usePasteHandler( props ) {
135
157
} ) ;
136
158
137
159
if ( typeof content === 'string' ) {
138
- const transformed = formatTypes . reduce (
139
- ( accumlator , { __unstablePasteRule } ) => {
140
- // Only allow one transform.
141
- if ( __unstablePasteRule && accumlator === value ) {
142
- accumlator = __unstablePasteRule ( value , {
143
- html,
144
- plainText,
145
- } ) ;
146
- }
147
-
148
- return accumlator ;
149
- } ,
150
- value
151
- ) ;
152
-
153
- if ( transformed !== value ) {
154
- onChange ( transformed ) ;
155
- } else {
156
- const valueToInsert = create ( { html : content } ) ;
157
- addActiveFormats ( valueToInsert , value . activeFormats ) ;
158
- onChange ( insert ( value , valueToInsert ) ) ;
159
- }
160
+ pasteInline ( content ) ;
160
161
} else if ( content . length > 0 ) {
161
162
if ( onReplace && isEmpty ( value ) ) {
162
163
onReplace ( content , content . length - 1 , - 1 ) ;
0 commit comments