MCPcopy
hub / github.com/csev/py4e / CodeMirror

Function CodeMirror

tools/pythonauto/static/codemirrorepl/codemirrorepl.js:211–2113  ·  view source on GitHub ↗
(place, givenOptions)

Source from the content-addressed store, hash-verified

209 // This is the function that produces an editor instance. Its
210 // closure is used to store the editor state.
211 function CodeMirror(place, givenOptions) {
212 // Determine effective options based on given values and defaults.
213 var options = {}, defaults = CodeMirror.defaults;
214 for (var opt in defaults)
215 if (defaults.hasOwnProperty(opt))
216 options[opt] = (givenOptions && givenOptions.hasOwnProperty(opt) ? givenOptions : defaults)[opt];
217
218 // The element in which the editor lives.
219 var wrapper = document.createElement("div");
220 wrapper.className = "CodeMirror" + (options.lineWrapping ? " CodeMirror-wrap" : "");
221 // This mess creates the base DOM structure for the editor.
222 wrapper.innerHTML =
223 '<div style="overflow: hidden; position: relative; width: 3px; height: 0px;">' + // Wraps and hides input textarea
224 '<textarea style="position: absolute; padding: 0; width: 1px; height: 1em" wrap="off" ' +
225 'autocorrect="off" autocapitalize="off"></textarea></div>' +
226 '<div class="CodeMirror-scroll" tabindex="-1">' +
227 '<div style="position: relative">' + // Set to the height of the text, causes scrolling
228 '<div style="position: relative">' + // Moved around its parent to cover visible view
229 '<div class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div>' +
230 // Provides positioning relative to (visible) text origin
231 '<div class="CodeMirror-lines"><div style="position: relative; z-index: 0">' +
232 '<div style="position: absolute; width: 100%; height: 0; overflow: hidden; visibility: hidden;"></div>' +
233 '<pre class="CodeMirror-cursor">&#160;</pre>' + // Absolutely positioned blinky cursor
234 '<div style="position: relative; z-index: -1"></div><div></div>' + // DIVs containing the selection and the actual code
235 '</div></div></div></div></div>';
236 if (place.appendChild) place.appendChild(wrapper); else place(wrapper);
237 // I've never seen more elegant code in my life.
238 var inputDiv = wrapper.firstChild, input = inputDiv.firstChild,
239 scroller = wrapper.lastChild, code = scroller.firstChild,
240 mover = code.firstChild, gutter = mover.firstChild, gutterText = gutter.firstChild,
241 lineSpace = gutter.nextSibling.firstChild, measure = lineSpace.firstChild,
242 cursor = measure.nextSibling, selectionDiv = cursor.nextSibling,
243 lineDiv = selectionDiv.nextSibling;
244 themeChanged(); keyMapChanged();
245 // Needed to hide big blue blinking cursor on Mobile Safari
246 if (ios) input.style.width = "0px";
247 if (!webkit) lineSpace.draggable = true;
248 lineSpace.style.outline = "none";
249 if (options.tabindex != null) input.tabIndex = options.tabindex;
250 if (options.autofocus) focusInput();
251 if (!options.gutter && !options.lineNumbers) gutter.style.display = "none";
252 // Needed to handle Tab key in KHTML
253 if (khtml) inputDiv.style.height = "1px", inputDiv.style.position = "absolute";
254
255 // Check for problem with IE innerHTML not working when we have a
256 // P (or similar) parent node.
257 try { stringWidth("x"); }
258 catch (e) {
259 if (e.message.match(/runtime/i))
260 e = new Error("A CodeMirror inside a P-style element does not work in Internet Explorer. (innerHTML bug)");
261 throw e;
262 }
263
264 // Delayed object wrap timeouts, making sure only one is active. blinker holds an interval.
265 var poll = new Delayed(), highlight = new Delayed(), blinker;
266
267 // mode holds a mode API object. doc is the tree of Line objects,
268 // work an array of lines that should be parsed, and history the

Callers 1

codemirrorepl.jsFile · 0.70

Calls 15

stringWidthFunction · 0.85
setValueFunction · 0.85
connectFunction · 0.85
replaceSelectionFunction · 0.85
gutterChangedFunction · 0.85
matchBracketsFunction · 0.85
localCoordsFunction · 0.85
pageCoordsFunction · 0.85
eltOffsetFunction · 0.85
setLineHiddenFunction · 0.85
paddingLeftFunction · 0.85
setCursorFunction · 0.85

Tested by

no test coverage detected