(doc, change, update)
| 4355 | |
| 4356 | // Allow "beforeChange" event handlers to influence a change |
| 4357 | function filterChange(doc, change, update) { |
| 4358 | var obj = { |
| 4359 | canceled: false, |
| 4360 | from: change.from, |
| 4361 | to: change.to, |
| 4362 | text: change.text, |
| 4363 | origin: change.origin, |
| 4364 | cancel: function() { this.canceled = true; } |
| 4365 | }; |
| 4366 | if (update) obj.update = function(from, to, text, origin) { |
| 4367 | if (from) this.from = clipPos(doc, from); |
| 4368 | if (to) this.to = clipPos(doc, to); |
| 4369 | if (text) this.text = text; |
| 4370 | if (origin !== undefined) this.origin = origin; |
| 4371 | }; |
| 4372 | signal(doc, "beforeChange", doc, obj); |
| 4373 | if (doc.cm) signal(doc.cm, "beforeChange", doc.cm, obj); |
| 4374 | |
| 4375 | if (obj.canceled) return null; |
| 4376 | return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin}; |
| 4377 | } |
| 4378 | |
| 4379 | // Apply a change to a document, and add it to the document's |
| 4380 | // history, and propagating it to all linked documents. |
no test coverage detected