MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / filterChange

Function filterChange

lib/web/CodeMirror/src/model/changes.js:23–46  ·  view source on GitHub ↗
(doc, change, update)

Source from the content-addressed store, hash-verified

21
22// Allow "beforeChange" event handlers to influence a change
23function 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.

Callers 2

makeChangeFunction · 0.70
makeChangeFromHistoryFunction · 0.70

Calls 2

clipPosFunction · 0.90
signalFunction · 0.90

Tested by

no test coverage detected