(doc, change, update)
| 4153 | |
| 4154 | // Allow "beforeChange" event handlers to influence a change |
| 4155 | function filterChange(doc, change, update) { |
| 4156 | var obj = { |
| 4157 | canceled: false, |
| 4158 | from: change.from, |
| 4159 | to: change.to, |
| 4160 | text: change.text, |
| 4161 | origin: change.origin, |
| 4162 | cancel: function() { this.canceled = true; } |
| 4163 | }; |
| 4164 | if (update) obj.update = function(from, to, text, origin) { |
| 4165 | if (from) this.from = clipPos(doc, from); |
| 4166 | if (to) this.to = clipPos(doc, to); |
| 4167 | if (text) this.text = text; |
| 4168 | if (origin !== undefined) this.origin = origin; |
| 4169 | }; |
| 4170 | signal(doc, "beforeChange", doc, obj); |
| 4171 | if (doc.cm) signal(doc.cm, "beforeChange", doc.cm, obj); |
| 4172 | |
| 4173 | if (obj.canceled) return null; |
| 4174 | return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin}; |
| 4175 | } |
| 4176 | |
| 4177 | // Apply a change to a document, and add it to the document's |
| 4178 | // history, and propagating it to all linked documents. |
no test coverage detected