(doc, change, update)
| 21 | |
| 22 | // Allow "beforeChange" event handlers to influence a change |
| 23 | function filterChange(doc, change, update) { |
| 24 | let obj = { |
| 25 | canceled: false, |
| 26 | from: change.from, |
| 27 | to: change.to, |
| 28 | text: change.text, |
| 29 | origin: change.origin, |
| 30 | cancel: () => obj.canceled = true |
| 31 | } |
| 32 | if (update) obj.update = (from, to, text, origin) => { |
| 33 | if (from) obj.from = clipPos(doc, from) |
| 34 | if (to) obj.to = clipPos(doc, to) |
| 35 | if (text) obj.text = text |
| 36 | if (origin !== undefined) obj.origin = origin |
| 37 | } |
| 38 | signal(doc, "beforeChange", doc, obj) |
| 39 | if (doc.cm) signal(doc.cm, "beforeChange", doc.cm, obj) |
| 40 | |
| 41 | if (obj.canceled) { |
| 42 | if (doc.cm) doc.cm.curOp.updateInput = 2 |
| 43 | return null |
| 44 | } |
| 45 | return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin} |
| 46 | } |
| 47 | |
| 48 | // Apply a change to a document, and add it to the document's |
| 49 | // history, and propagating it to all linked documents. |
no test coverage detected