(doc, change, update)
| 3234 | |
| 3235 | // Allow "beforeChange" event handlers to influence a change |
| 3236 | function filterChange(doc, change, update) { |
| 3237 | var obj = { |
| 3238 | canceled: false, |
| 3239 | from: change.from, |
| 3240 | to: change.to, |
| 3241 | text: change.text, |
| 3242 | origin: change.origin, |
| 3243 | cancel: function() { this.canceled = true; } |
| 3244 | }; |
| 3245 | if (update) obj.update = function(from, to, text, origin) { |
| 3246 | if (from) this.from = clipPos(doc, from); |
| 3247 | if (to) this.to = clipPos(doc, to); |
| 3248 | if (text) this.text = text; |
| 3249 | if (origin !== undefined) this.origin = origin; |
| 3250 | }; |
| 3251 | signal(doc, "beforeChange", doc, obj); |
| 3252 | if (doc.cm) signal(doc.cm, "beforeChange", doc.cm, obj); |
| 3253 | |
| 3254 | if (obj.canceled) return null; |
| 3255 | return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin}; |
| 3256 | } |
| 3257 | |
| 3258 | // Apply a change to a document, and add it to the document's |
| 3259 | // history, and propagating it to all linked documents. |
no test coverage detected