MCPcopy Create free account
hub / github.com/TruthHun/BookStack / CodeMirror

Function CodeMirror

static/editor.md/lib/codemirror/lib/codemirror.js:59–122  ·  view source on GitHub ↗
(place, options)

Source from the content-addressed store, hash-verified

57 // that user code is usually dealing with.
58
59 function CodeMirror(place, options) {
60 if (!(this instanceof CodeMirror)) return new CodeMirror(place, options);
61
62 this.options = options = options ? copyObj(options) : {};
63 // Determine effective options based on given values and defaults.
64 copyObj(defaults, options, false);
65 setGuttersForLineNumbers(options);
66
67 var doc = options.value;
68 if (typeof doc == "string") doc = new Doc(doc, options.mode);
69 this.doc = doc;
70
71 var input = new CodeMirror.inputStyles[options.inputStyle](this);
72 var display = this.display = new Display(place, doc, input);
73 display.wrapper.CodeMirror = this;
74 updateGutters(this);
75 themeChanged(this);
76 if (options.lineWrapping)
77 this.display.wrapper.className += " CodeMirror-wrap";
78 if (options.autofocus && !mobile) display.input.focus();
79 initScrollbars(this);
80
81 this.state = {
82 keyMaps: [], // stores maps added by addKeyMap
83 overlays: [], // highlighting overlays, as added by addOverlay
84 modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
85 overwrite: false, focused: false,
86 suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
87 pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in input.poll
88 draggingText: false,
89 highlight: new Delayed(), // stores highlight worker timeout
90 keySeq: null // Unfinished key sequence
91 };
92
93 var cm = this;
94
95 // Override magic textarea content restore that IE sometimes does
96 // on our hidden textarea on reload
97 if (ie && ie_version < 11) setTimeout(function() { cm.display.input.reset(true); }, 20);
98
99 registerEventHandlers(this);
100 ensureGlobalHandlers();
101
102 startOperation(this);
103 this.curOp.forceUpdate = true;
104 attachDoc(this, doc);
105
106 if ((options.autofocus && !mobile) || cm.hasFocus())
107 setTimeout(bind(onFocus, this), 20);
108 else
109 onBlur(this);
110
111 for (var opt in optionHandlers) if (optionHandlers.hasOwnProperty(opt))
112 optionHandlers[opt](this, options[opt], Init);
113 maybeUpdateLineNumberWidth(this);
114 if (options.finishInit) options.finishInit(this);
115 for (var i = 0; i < initHooks.length; ++i) initHooks[i](this);
116 endOperation(this);

Callers 2

codemirror.jsFile · 0.70
merge.jsFile · 0.50

Calls 13

copyObjFunction · 0.70
setGuttersForLineNumbersFunction · 0.70
updateGuttersFunction · 0.70
themeChangedFunction · 0.70
initScrollbarsFunction · 0.70
registerEventHandlersFunction · 0.70
ensureGlobalHandlersFunction · 0.70
startOperationFunction · 0.70
attachDocFunction · 0.70
bindFunction · 0.70
onBlurFunction · 0.70

Tested by

no test coverage detected