@@ -103,11 +103,13 @@ class Quill {
103
103
104
104
deleteText ( index , length , source ) {
105
105
[ index , length , , source ] = overload ( index , length , source ) ;
106
- let range = this . getSelection ( ) ;
107
- let change = this . editor . deleteText ( index , length , source ) ;
108
- range = shiftRange ( range , index , - 1 * length , source ) ;
109
- this . setSelection ( range , Emitter . sources . SILENT ) ;
110
- return change ;
106
+ return modify . call ( this , source , ( ) => {
107
+ let range = this . getSelection ( ) ;
108
+ let change = this . editor . deleteText ( index , length , source ) ;
109
+ range = shiftRange ( range , index , - 1 * length , source ) ;
110
+ this . setSelection ( range , Emitter . sources . SILENT ) ;
111
+ return change ;
112
+ } ) ;
111
113
}
112
114
113
115
disable ( ) {
@@ -128,39 +130,45 @@ class Quill {
128
130
}
129
131
130
132
format ( name , value , source = Emitter . sources . API ) {
131
- let range = this . getSelection ( true ) ;
132
- let change = new Delta ( ) ;
133
- if ( range == null ) return change ;
134
- if ( Parchment . query ( name , Parchment . Scope . BLOCK ) ) {
135
- change = this . formatLine ( range , name , value , source ) ;
136
- } else if ( range . length === 0 ) {
137
- this . selection . format ( name , value ) ;
133
+ return modify . call ( this , source , ( ) => {
134
+ let range = this . getSelection ( true ) ;
135
+ let change = new Delta ( ) ;
136
+ if ( range == null ) return change ;
137
+ if ( Parchment . query ( name , Parchment . Scope . BLOCK ) ) {
138
+ change = this . formatLine ( range , name , value , source ) ;
139
+ } else if ( range . length === 0 ) {
140
+ this . selection . format ( name , value ) ;
141
+ return change ;
142
+ } else {
143
+ change = this . formatText ( range , name , value , source ) ;
144
+ }
145
+ this . setSelection ( range , Emitter . sources . SILENT ) ;
138
146
return change ;
139
- } else {
140
- change = this . formatText ( range , name , value , source ) ;
141
- }
142
- this . setSelection ( range , Emitter . sources . SILENT ) ;
143
- return change ;
147
+ } ) ;
144
148
}
145
149
146
150
formatLine ( index , length , name , value , source ) {
147
151
let formats ;
148
152
[ index , length , formats , source ] = overload ( index , length , name , value , source ) ;
149
- let range = this . getSelection ( ) ;
150
- let change = this . editor . formatLine ( index , length , formats , source ) ;
151
- this . selection . setRange ( range , true , Emitter . sources . SILENT ) ;
152
- this . selection . scrollIntoView ( ) ;
153
- return change ;
153
+ return modify . call ( this , source , ( ) => {
154
+ let range = this . getSelection ( ) ;
155
+ let change = this . editor . formatLine ( index , length , formats , source ) ;
156
+ this . selection . setRange ( range , true , Emitter . sources . SILENT ) ;
157
+ this . selection . scrollIntoView ( ) ;
158
+ return change ;
159
+ } ) ;
154
160
}
155
161
156
162
formatText ( index , length , name , value , source ) {
157
163
let formats ;
158
164
[ index , length , formats , source ] = overload ( index , length , name , value , source ) ;
159
- let range = this . getSelection ( ) ;
160
- let change = this . editor . formatText ( index , length , formats , source ) ;
161
- this . selection . setRange ( range , true , Emitter . sources . SILENT ) ;
162
- this . selection . scrollIntoView ( ) ;
163
- return change ;
165
+ return modify . call ( this , source , ( ) => {
166
+ let range = this . getSelection ( ) ;
167
+ let change = this . editor . formatText ( index , length , formats , source ) ;
168
+ this . selection . setRange ( range , true , Emitter . sources . SILENT ) ;
169
+ this . selection . scrollIntoView ( ) ;
170
+ return change ;
171
+ } ) ;
164
172
}
165
173
166
174
getBounds ( index , length = 0 ) {
@@ -208,20 +216,25 @@ class Quill {
208
216
}
209
217
210
218
insertEmbed ( index , embed , value , source = Quill . sources . API ) {
211
- let range = this . getSelection ( ) ;
212
- let change = this . editor . insertEmbed ( index , embed , value , source ) ;
213
- range = shiftRange ( range , change , source ) ;
214
- this . setSelection ( range , Emitter . sources . SILENT ) ;
215
- return change ;
219
+ return modify . call ( this , source , ( ) => {
220
+ let range = this . getSelection ( ) ;
221
+ let change = this . editor . insertEmbed ( index , embed , value , source ) ;
222
+ range = shiftRange ( range , change , source ) ;
223
+ this . setSelection ( range , Emitter . sources . SILENT ) ;
224
+ return change ;
225
+ } ) ;
216
226
}
217
227
218
228
insertText ( index , text , name , value , source ) {
219
- let formats , range = this . getSelection ( ) ;
229
+ let formats ;
220
230
[ index , , formats , source ] = overload ( index , 0 , name , value , source ) ;
221
- let change = this . editor . insertText ( index , text , formats , source ) ;
222
- range = shiftRange ( range , index , text . length , source ) ;
223
- this . setSelection ( range , Emitter . sources . SILENT ) ;
224
- return change ;
231
+ return modify . call ( this , source , ( ) => {
232
+ let range = this . getSelection ( ) ;
233
+ let change = this . editor . insertText ( index , text , formats , source ) ;
234
+ range = shiftRange ( range , index , text . length , source ) ;
235
+ this . setSelection ( range , Emitter . sources . SILENT ) ;
236
+ return change ;
237
+ } ) ;
225
238
}
226
239
227
240
off ( ) {
@@ -241,15 +254,18 @@ class Quill {
241
254
}
242
255
243
256
removeFormat ( index , length , source ) {
244
- let range = this . getSelection ( ) ;
245
257
[ index , length , , source ] = overload ( index , length , source ) ;
246
- let change = this . editor . removeFormat ( index , length , source ) ;
247
- range = shiftRange ( range , change , source ) ;
248
- this . setSelection ( range , Emitter . sources . SILENT ) ;
249
- return change ;
258
+ return modify . call ( this , source , ( ) => {
259
+ let range = this . getSelection ( ) ;
260
+ let change = this . editor . removeFormat ( index , length , source ) ;
261
+ range = shiftRange ( range , change , source ) ;
262
+ this . setSelection ( range , Emitter . sources . SILENT ) ;
263
+ return change ;
264
+ } ) ;
250
265
}
251
266
252
267
setContents ( delta , source = Emitter . sources . API ) {
268
+ if ( this . container . classList . contains ( 'ql-disabled' ) && source === Emitter . sources . USER ) return ;
253
269
delta = new Delta ( delta ) . slice ( ) ;
254
270
let lastOp = delta . ops [ delta . ops . length - 1 ] ;
255
271
// Quill contents must always end with newline
@@ -282,6 +298,7 @@ class Quill {
282
298
}
283
299
284
300
updateContents ( delta , source = Emitter . sources . API ) {
301
+ if ( this . container . classList . contains ( 'ql-disabled' ) && source === Emitter . sources . USER ) return ;
285
302
let range = this . getSelection ( ) ;
286
303
if ( Array . isArray ( delta ) ) {
287
304
delta = new Delta ( delta . slice ( ) ) ;
@@ -372,6 +389,14 @@ function expandConfig(container, userConfig) {
372
389
return userConfig ;
373
390
}
374
391
392
+ function modify ( source , modifier ) {
393
+ let change = new Delta ( ) ;
394
+ if ( this . container . classList . contains ( 'ql-disabled' ) && source === Emitter . sources . USER ) {
395
+ return new Delta ( ) ;
396
+ }
397
+ return modifier ( ) ;
398
+ }
399
+
375
400
function overload ( index , length , name , value , source ) {
376
401
let formats = { } ;
377
402
if ( typeof index . index === 'number' && typeof index . length === 'number' ) {
0 commit comments