(doc, change, update)
| 3270 | |
| 3271 | // Allow "beforeChange" event handlers to influence a change |
| 3272 | function filterChange(doc, change, update) { |
| 3273 | var obj = { |
| 3274 | canceled: false, |
| 3275 | from: change.from, |
| 3276 | to: change.to, |
| 3277 | text: change.text, |
| 3278 | origin: change.origin, |
| 3279 | cancel: function() { this.canceled = true; } |
| 3280 | }; |
| 3281 | if (update) obj.update = function(from, to, text, origin) { |
| 3282 | if (from) this.from = clipPos(doc, from); |
| 3283 | if (to) this.to = clipPos(doc, to); |
| 3284 | if (text) this.text = text; |
| 3285 | if (origin !== undefined) this.origin = origin; |
| 3286 | }; |
| 3287 | signal(doc, "beforeChange", doc, obj); |
| 3288 | if (doc.cm) signal(doc.cm, "beforeChange", doc.cm, obj); |
| 3289 | |
| 3290 | if (obj.canceled) return null; |
| 3291 | return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin}; |
| 3292 | } |
| 3293 | |
| 3294 | // Apply a change to a document, and add it to the document's |
| 3295 | // history, and propagating it to all linked documents. |
no test coverage detected
searching dependent graphs…