(doc, change, update)
| 5231 | |
| 5232 | // Allow "beforeChange" event handlers to influence a change |
| 5233 | function filterChange(doc, change, update) { |
| 5234 | var obj = { |
| 5235 | canceled: false, |
| 5236 | from: change.from, |
| 5237 | to: change.to, |
| 5238 | text: change.text, |
| 5239 | origin: change.origin, |
| 5240 | cancel: function () { return obj.canceled = true; } |
| 5241 | }; |
| 5242 | if (update) { obj.update = function (from, to, text, origin) { |
| 5243 | if (from) { obj.from = clipPos(doc, from); } |
| 5244 | if (to) { obj.to = clipPos(doc, to); } |
| 5245 | if (text) { obj.text = text; } |
| 5246 | if (origin !== undefined) { obj.origin = origin; } |
| 5247 | }; } |
| 5248 | signal(doc, "beforeChange", doc, obj); |
| 5249 | if (doc.cm) { signal(doc.cm, "beforeChange", doc.cm, obj); } |
| 5250 | |
| 5251 | if (obj.canceled) { |
| 5252 | if (doc.cm) { doc.cm.curOp.updateInput = 2; } |
| 5253 | return null |
| 5254 | } |
| 5255 | return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin} |
| 5256 | } |
| 5257 | |
| 5258 | // Apply a change to a document, and add it to the document's |
| 5259 | // history, and propagating it to all linked documents. |
no test coverage detected