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

Function CodeMirror

lib/web/CodeMirror/src/edit/CodeMirror.js:29–96  ·  view source on GitHub ↗
(place, options)

Source from the content-addressed store, hash-verified

27// that user code is usually dealing with.
28
29export function CodeMirror(place, options) {
30 if (!(this instanceof CodeMirror)) return new CodeMirror(place, options)
31
32 this.options = options = options ? copyObj(options) : {}
33 // Determine effective options based on given values and defaults.
34 copyObj(defaults, options, false)
35
36 let doc = options.value
37 if (typeof doc == "string") doc = new Doc(doc, options.mode, null, options.lineSeparator, options.direction)
38 else if (options.mode) doc.modeOption = options.mode
39 this.doc = doc
40
41 let input = new CodeMirror.inputStyles[options.inputStyle](this)
42 let display = this.display = new Display(place, doc, input, options)
43 display.wrapper.CodeMirror = this
44 themeChanged(this)
45 if (options.lineWrapping)
46 this.display.wrapper.className += " CodeMirror-wrap"
47 initScrollbars(this)
48
49 this.state = {
50 keyMaps: [], // stores maps added by addKeyMap
51 overlays: [], // highlighting overlays, as added by addOverlay
52 modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
53 overwrite: false,
54 delayingBlurEvent: false,
55 focused: false,
56 suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
57 pasteIncoming: -1, cutIncoming: -1, // help recognize paste/cut edits in input.poll
58 selectingText: false,
59 draggingText: false,
60 highlight: new Delayed(), // stores highlight worker timeout
61 keySeq: null, // Unfinished key sequence
62 specialChars: null
63 }
64
65 if (options.autofocus && !mobile) display.input.focus()
66
67 // Override magic textarea content restore that IE sometimes does
68 // on our hidden textarea on reload
69 if (ie && ie_version < 11) setTimeout(() => this.display.input.reset(true), 20)
70
71 registerEventHandlers(this)
72 ensureGlobalHandlers()
73
74 startOperation(this)
75 this.curOp.forceUpdate = true
76 attachDoc(this, doc)
77
78 if ((options.autofocus && !mobile) || this.hasFocus())
79 setTimeout(() => {
80 if (this.hasFocus() && !this.state.focused) onFocus(this)
81 }, 20)
82 else
83 onBlur(this)
84
85 for (let opt in optionHandlers) if (optionHandlers.hasOwnProperty(opt))
86 optionHandlers[opt](this, options[opt], Init)

Callers 1

fromTextAreaFunction · 0.90

Calls 13

copyObjFunction · 0.90
themeChangedFunction · 0.90
initScrollbarsFunction · 0.90
ensureGlobalHandlersFunction · 0.90
startOperationFunction · 0.90
attachDocFunction · 0.90
onFocusFunction · 0.90
onBlurFunction · 0.90
endOperationFunction · 0.90
registerEventHandlersFunction · 0.70
resetMethod · 0.65

Tested by

no test coverage detected