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

Method poll

lib/web/CodeMirror/src/input/TextareaInput.js:224–271  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

222 // seen text (can be empty), which is stored in prevInput (we must
223 // not reset the textarea when typing, because that breaks IME).
224 poll() {
225 let cm = this.cm, input = this.textarea, prevInput = this.prevInput
226 // Since this is called a *lot*, try to bail out as cheaply as
227 // possible when it is clear that nothing happened. hasSelection
228 // will be the case when there is a lot of text in the textarea,
229 // in which case reading its value would be expensive.
230 if (this.contextMenuPending || !cm.state.focused ||
231 (hasSelection(input) && !prevInput && !this.composing) ||
232 cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq)
233 return false
234
235 let text = input.value
236 // If nothing changed, bail.
237 if (text == prevInput && !cm.somethingSelected()) return false
238 // Work around nonsensical selection resetting in IE9/10, and
239 // inexplicable appearance of private area unicode characters on
240 // some key combos in Mac (#2689).
241 if (ie && ie_version >= 9 && this.hasSelection === text ||
242 mac && /[\uf700-\uf7ff]/.test(text)) {
243 cm.display.input.reset()
244 return false
245 }
246
247 if (cm.doc.sel == cm.display.selForContextMenu) {
248 let first = text.charCodeAt(0)
249 if (first == 0x200b && !prevInput) prevInput = "\u200b"
250 if (first == 0x21da) { this.reset(); return this.cm.execCommand("undo") }
251 }
252 // Find the part of the input that is actually new
253 let same = 0, l = Math.min(prevInput.length, text.length)
254 while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same
255
256 runInOp(cm, () => {
257 applyTextInput(cm, text.slice(same), prevInput.length - same,
258 null, this.composing ? "*compose" : null)
259
260 // Don't leave long text in the textarea, since it makes further polling slow
261 if (text.length > 1000 || text.indexOf("\n") > -1) input.value = this.prevInput = ""
262 else this.prevInput = text
263
264 if (this.composing) {
265 this.composing.range.clear()
266 this.composing.range = cm.markText(this.composing.start, cm.getCursor("to"),
267 {className: "CodeMirror-composing"})
268 }
269 })
270 return true
271 }
272
273 ensurePolled() {
274 if (this.pollingFast && this.poll()) this.pollingFast = false

Callers 15

slowPollMethod · 0.95
ensurePolledMethod · 0.95
codemirror.jsFile · 0.45
pFunction · 0.45
initMethod · 0.45
pMethod · 0.45
updateMethod · 0.45
calcShapesMethod · 0.45
computePathsMethod · 0.45
leaveMethod · 0.45
debugTakeMethod · 0.45

Calls 10

resetMethod · 0.95
runInOpFunction · 0.90
applyTextInputFunction · 0.90
operationFunction · 0.90
somethingSelectedMethod · 0.80
indexOfMethod · 0.80
resetMethod · 0.65
testMethod · 0.45
minMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected