(doc, change, update)
| 4332 | |
| 4333 | // Allow "beforeChange" event handlers to influence a change |
| 4334 | function filterChange(doc, change, update) { |
| 4335 | var obj = { |
| 4336 | canceled: false, |
| 4337 | from: change.from, |
| 4338 | to: change.to, |
| 4339 | text: change.text, |
| 4340 | origin: change.origin, |
| 4341 | cancel: function() { this.canceled = true; } |
| 4342 | }; |
| 4343 | if (update) obj.update = function(from, to, text, origin) { |
| 4344 | if (from) this.from = clipPos(doc, from); |
| 4345 | if (to) this.to = clipPos(doc, to); |
| 4346 | if (text) this.text = text; |
| 4347 | if (origin !== undefined) this.origin = origin; |
| 4348 | }; |
| 4349 | signal(doc, "beforeChange", doc, obj); |
| 4350 | if (doc.cm) signal(doc.cm, "beforeChange", doc.cm, obj); |
| 4351 | |
| 4352 | if (obj.canceled) return null; |
| 4353 | return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin}; |
| 4354 | } |
| 4355 | |
| 4356 | // Apply a change to a document, and add it to the document's |
| 4357 | // history, and propagating it to all linked documents. |
no test coverage detected