(doc, change, update)
| 5274 | |
| 5275 | // Allow "beforeChange" event handlers to influence a change |
| 5276 | function filterChange(doc, change, update) { |
| 5277 | var obj = { |
| 5278 | canceled: false, |
| 5279 | from: change.from, |
| 5280 | to: change.to, |
| 5281 | text: change.text, |
| 5282 | origin: change.origin, |
| 5283 | cancel: function () { return obj.canceled = true; } |
| 5284 | }; |
| 5285 | if (update) { obj.update = function (from, to, text, origin) { |
| 5286 | if (from) { obj.from = clipPos(doc, from); } |
| 5287 | if (to) { obj.to = clipPos(doc, to); } |
| 5288 | if (text) { obj.text = text; } |
| 5289 | if (origin !== undefined) { obj.origin = origin; } |
| 5290 | }; } |
| 5291 | signal(doc, "beforeChange", doc, obj); |
| 5292 | if (doc.cm) { signal(doc.cm, "beforeChange", doc.cm, obj); } |
| 5293 | |
| 5294 | if (obj.canceled) { |
| 5295 | if (doc.cm) { doc.cm.curOp.updateInput = 2; } |
| 5296 | return null |
| 5297 | } |
| 5298 | return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin} |
| 5299 | } |
| 5300 | |
| 5301 | // Apply a change to a document, and add it to the document's |
| 5302 | // history, and propagating it to all linked documents. |
no test coverage detected