MCPcopy
hub / github.com/hokein/electron-sample-apps / indentLine

Function indentLine

mini-code-editor/cm/lib/codemirror.js:1317–1348  ·  view source on GitHub ↗
(n, how)

Source from the content-addressed store, hash-verified

1315 }
1316
1317 function indentLine(n, how) {
1318 if (!how) how = "add";
1319 if (how == "smart") {
1320 if (!mode.indent) how = "prev";
1321 else var state = getStateBefore(n);
1322 }
1323
1324 var line = getLine(n), curSpace = line.indentation(options.tabSize),
1325 curSpaceString = line.text.match(/^\s*/)[0], indentation;
1326 if (how == "prev") {
1327 if (n) indentation = getLine(n-1).indentation(options.tabSize);
1328 else indentation = 0;
1329 }
1330 else if (how == "smart") indentation = mode.indent(state, line.text.slice(curSpaceString.length), line.text);
1331 else if (how == "add") indentation = curSpace + options.indentUnit;
1332 else if (how == "subtract") indentation = curSpace - options.indentUnit;
1333 indentation = Math.max(0, indentation);
1334 var diff = indentation - curSpace;
1335
1336 if (!diff) {
1337 if (sel.from.line != n && sel.to.line != n) return;
1338 var indentString = curSpaceString;
1339 }
1340 else {
1341 var indentString = "", pos = 0;
1342 if (options.indentWithTabs)
1343 for (var i = Math.floor(indentation / options.tabSize); i; --i) {pos += options.tabSize; indentString += "\t";}
1344 while (pos < indentation) {++pos; indentString += " ";}
1345 }
1346
1347 replaceRange(indentString, {line: n, ch: 0}, {line: n, ch: curSpaceString.length});
1348 }
1349
1350 function loadMode() {
1351 mode = CodeMirror.getMode(options, options.mode);

Callers 3

CodeMirrorFunction · 0.85
onKeyPressFunction · 0.85
indentSelectedFunction · 0.85

Calls 3

getStateBeforeFunction · 0.85
getLineFunction · 0.85
replaceRangeFunction · 0.85

Tested by

no test coverage detected