MCPcopy Index your code
hub / github.com/ronreiter/interactive-tutorials / indentLine

Function indentLine

static/js/codemirror/codemirror.js:2472–2508  ·  view source on GitHub ↗
(cm, n, how, aggressive)

Source from the content-addressed store, hash-verified

2470 // API UTILITIES
2471
2472 function indentLine(cm, n, how, aggressive) {
2473 var doc = cm.doc;
2474 if (!how) how = "add";
2475 if (how == "smart") {
2476 if (!cm.doc.mode.indent) how = "prev";
2477 else var state = getStateBefore(cm, n);
2478 }
2479
2480 var tabSize = cm.options.tabSize;
2481 var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
2482 var curSpaceString = line.text.match(/^\s*/)[0], indentation;
2483 if (how == "smart") {
2484 indentation = cm.doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
2485 if (indentation == Pass) {
2486 if (!aggressive) return;
2487 how = "prev";
2488 }
2489 }
2490 if (how == "prev") {
2491 if (n > doc.first) indentation = countColumn(getLine(doc, n-1).text, null, tabSize);
2492 else indentation = 0;
2493 } else if (how == "add") {
2494 indentation = curSpace + cm.options.indentUnit;
2495 } else if (how == "subtract") {
2496 indentation = curSpace - cm.options.indentUnit;
2497 }
2498 indentation = Math.max(0, indentation);
2499
2500 var indentString = "", pos = 0;
2501 if (cm.options.indentWithTabs)
2502 for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";}
2503 if (pos < indentation) indentString += spaceStr(indentation - pos);
2504
2505 if (indentString != curSpaceString)
2506 replaceRange(cm.doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input");
2507 line.stateAfter = null;
2508 }
2509
2510 function changeLine(cm, handle, op) {
2511 var no = handle, line = handle, doc = cm.doc;

Callers 2

onKeyPressFunction · 0.85
codemirror.jsFile · 0.85

Calls 8

getStateBeforeFunction · 0.85
getLineFunction · 0.85
countColumnFunction · 0.85
spaceStrFunction · 0.85
replaceRangeFunction · 0.85
PosFunction · 0.85
indentMethod · 0.80
matchMethod · 0.45

Tested by

no test coverage detected