(cm, n, how, aggressive)
| 8034 | // lines are not indented, and places where the mode returns Pass |
| 8035 | // are left alone. |
| 8036 | function indentLine(cm, n, how, aggressive) { |
| 8037 | var doc = cm.doc, state; |
| 8038 | if (how == null) { how = "add"; } |
| 8039 | if (how == "smart") { |
| 8040 | // Fall back to "prev" when the mode doesn't have an indentation |
| 8041 | // method. |
| 8042 | if (!doc.mode.indent) { how = "prev"; } |
| 8043 | else { state = getContextBefore(cm, n).state; } |
| 8044 | } |
| 8045 | |
| 8046 | var tabSize = cm.options.tabSize; |
| 8047 | var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize); |
| 8048 | if (line.stateAfter) { line.stateAfter = null; } |
| 8049 | var curSpaceString = line.text.match(/^\s*/)[0], indentation; |
| 8050 | if (!aggressive && !/\S/.test(line.text)) { |
| 8051 | indentation = 0; |
| 8052 | how = "not"; |
| 8053 | } else if (how == "smart") { |
| 8054 | indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text); |
| 8055 | if (indentation == Pass || indentation > 150) { |
| 8056 | if (!aggressive) { return } |
| 8057 | how = "prev"; |
| 8058 | } |
| 8059 | } |
| 8060 | if (how == "prev") { |
| 8061 | if (n > doc.first) { indentation = countColumn(getLine(doc, n-1).text, null, tabSize); } |
| 8062 | else { indentation = 0; } |
| 8063 | } else if (how == "add") { |
| 8064 | indentation = curSpace + cm.options.indentUnit; |
| 8065 | } else if (how == "subtract") { |
| 8066 | indentation = curSpace - cm.options.indentUnit; |
| 8067 | } else if (typeof how == "number") { |
| 8068 | indentation = curSpace + how; |
| 8069 | } |
| 8070 | indentation = Math.max(0, indentation); |
| 8071 | |
| 8072 | var indentString = "", pos = 0; |
| 8073 | if (cm.options.indentWithTabs) |
| 8074 | { for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";} } |
| 8075 | if (pos < indentation) { indentString += spaceStr(indentation - pos); } |
| 8076 | |
| 8077 | if (indentString != curSpaceString) { |
| 8078 | replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input"); |
| 8079 | line.stateAfter = null; |
| 8080 | return true |
| 8081 | } else { |
| 8082 | // Ensure that, if the cursor was in the whitespace at the start |
| 8083 | // of the line, it is moved to the end of that space. |
| 8084 | for (var i$1 = 0; i$1 < doc.sel.ranges.length; i$1++) { |
| 8085 | var range = doc.sel.ranges[i$1]; |
| 8086 | if (range.head.line == n && range.head.ch < curSpaceString.length) { |
| 8087 | var pos$1 = Pos(n, curSpaceString.length); |
| 8088 | replaceOneSelection(doc, i$1, new Range(pos$1, pos$1)); |
| 8089 | break |
| 8090 | } |
| 8091 | } |
| 8092 | } |
| 8093 | } |
no test coverage detected