MCPcopy Create free account
hub / github.com/breck7/scroll / filterChange

Function filterChange

external/.scrollLibs.js:7096–7135  ·  view source on GitHub ↗
(doc, change, update)

Source from the content-addressed store, hash-verified

7094
7095 // Allow "beforeChange" event handlers to influence a change
7096 function filterChange(doc, change, update) {
7097 var obj = {
7098 canceled: false,
7099 from: change.from,
7100 to: change.to,
7101 text: change.text,
7102 origin: change.origin,
7103 cancel: function () {
7104 return (obj.canceled = true)
7105 }
7106 }
7107 if (update) {
7108 obj.update = function (from, to, text, origin) {
7109 if (from) {
7110 obj.from = clipPos(doc, from)
7111 }
7112 if (to) {
7113 obj.to = clipPos(doc, to)
7114 }
7115 if (text) {
7116 obj.text = text
7117 }
7118 if (origin !== undefined) {
7119 obj.origin = origin
7120 }
7121 }
7122 }
7123 signal(doc, "beforeChange", doc, obj)
7124 if (doc.cm) {
7125 signal(doc.cm, "beforeChange", doc.cm, obj)
7126 }
7127
7128 if (obj.canceled) {
7129 if (doc.cm) {
7130 doc.cm.curOp.updateInput = 2
7131 }
7132 return null
7133 }
7134 return { from: obj.from, to: obj.to, text: obj.text, origin: obj.origin }
7135 }
7136
7137 // Apply a change to a document, and add it to the document's
7138 // history, and propagating it to all linked documents.

Callers 2

makeChangeFunction · 0.85
loopFunction · 0.85

Calls 2

clipPosFunction · 0.85
signalFunction · 0.85

Tested by

no test coverage detected