MCPcopy Create free account
hub / github.com/TextGeneratorio/text-generator.io / defineOptions

Function defineOptions

static/libs/codemirror.js:7597–7729  ·  view source on GitHub ↗
(CodeMirror)

Source from the content-addressed store, hash-verified

7595var optionHandlers = {};
7596
7597function defineOptions(CodeMirror) {
7598 var optionHandlers = CodeMirror.optionHandlers;
7599
7600 function option(name, deflt, handle, notOnInit) {
7601 CodeMirror.defaults[name] = deflt;
7602 if (handle) { optionHandlers[name] =
7603 notOnInit ? function (cm, val, old) {if (old != Init) { handle(cm, val, old); }} : handle; }
7604 }
7605
7606 CodeMirror.defineOption = option;
7607
7608 // Passed to option handlers when there is no old value.
7609 CodeMirror.Init = Init;
7610
7611 // These two are, on init, called from the constructor because they
7612 // have to be initialized before the editor can start at all.
7613 option("value", "", function (cm, val) { return cm.setValue(val); }, true);
7614 option("mode", null, function (cm, val) {
7615 cm.doc.modeOption = val;
7616 loadMode(cm);
7617 }, true);
7618
7619 option("indentUnit", 2, loadMode, true);
7620 option("indentWithTabs", false);
7621 option("smartIndent", true);
7622 option("tabSize", 4, function (cm) {
7623 resetModeState(cm);
7624 clearCaches(cm);
7625 regChange(cm);
7626 }, true);
7627
7628 option("lineSeparator", null, function (cm, val) {
7629 cm.doc.lineSep = val;
7630 if (!val) { return }
7631 var newBreaks = [], lineNo = cm.doc.first;
7632 cm.doc.iter(function (line) {
7633 for (var pos = 0;;) {
7634 var found = line.text.indexOf(val, pos);
7635 if (found == -1) { break }
7636 pos = found + val.length;
7637 newBreaks.push(Pos(lineNo, found));
7638 }
7639 lineNo++;
7640 });
7641 for (var i = newBreaks.length - 1; i >= 0; i--)
7642 { replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length)); }
7643 });
7644 option("specialChars", /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff]/g, function (cm, val, old) {
7645 cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
7646 if (old != Init) { cm.refresh(); }
7647 });
7648 option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function (cm) { return cm.refresh(); }, true);
7649 option("electricChars", true);
7650 option("inputStyle", mobile ? "contenteditable" : "textarea", function () {
7651 throw new Error("inputStyle can not (yet) be changed in a running editor") // FIXME
7652 }, true);
7653 option("spellcheck", false, function (cm, val) { return cm.getInputField().spellcheck = val; }, true);
7654 option("rtlMoveVisually", !windows);

Callers 1

codemirror.jsFile · 0.85

Calls 15

optionFunction · 0.85
loadModeFunction · 0.85
resetModeStateFunction · 0.85
clearCachesFunction · 0.85
regChangeFunction · 0.85
PosFunction · 0.85
replaceRangeFunction · 0.85
themeChangedFunction · 0.85
guttersChangedFunction · 0.85
getKeyMapFunction · 0.85
setGuttersForLineNumbersFunction · 0.85
compensateForHScrollFunction · 0.85

Tested by

no test coverage detected