(cm, n, how, aggressive)
| 11048 | // lines are not indented, and places where the mode returns Pass |
| 11049 | // are left alone. |
| 11050 | function indentLine(cm, n, how, aggressive) { |
| 11051 | var doc = cm.doc, |
| 11052 | state |
| 11053 | if (how == null) { |
| 11054 | how = "add" |
| 11055 | } |
| 11056 | if (how == "smart") { |
| 11057 | // Fall back to "prev" when the mode doesn't have an indentation |
| 11058 | // method. |
| 11059 | if (!doc.mode.indent) { |
| 11060 | how = "prev" |
| 11061 | } else { |
| 11062 | state = getContextBefore(cm, n).state |
| 11063 | } |
| 11064 | } |
| 11065 | |
| 11066 | var tabSize = cm.options.tabSize |
| 11067 | var line = getLine(doc, n), |
| 11068 | curSpace = countColumn(line.text, null, tabSize) |
| 11069 | if (line.stateAfter) { |
| 11070 | line.stateAfter = null |
| 11071 | } |
| 11072 | var curSpaceString = line.text.match(/^\s*/)[0], |
| 11073 | indentation |
| 11074 | if (!aggressive && !/\S/.test(line.text)) { |
| 11075 | indentation = 0 |
| 11076 | how = "not" |
| 11077 | } else if (how == "smart") { |
| 11078 | indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text) |
| 11079 | if (indentation == Pass || indentation > 150) { |
| 11080 | if (!aggressive) { |
| 11081 | return |
| 11082 | } |
| 11083 | how = "prev" |
| 11084 | } |
| 11085 | } |
| 11086 | if (how == "prev") { |
| 11087 | if (n > doc.first) { |
| 11088 | indentation = countColumn(getLine(doc, n - 1).text, null, tabSize) |
| 11089 | } else { |
| 11090 | indentation = 0 |
| 11091 | } |
| 11092 | } else if (how == "add") { |
| 11093 | indentation = curSpace + cm.options.indentUnit |
| 11094 | } else if (how == "subtract") { |
| 11095 | indentation = curSpace - cm.options.indentUnit |
| 11096 | } else if (typeof how == "number") { |
| 11097 | indentation = curSpace + how |
| 11098 | } |
| 11099 | indentation = Math.max(0, indentation) |
| 11100 | |
| 11101 | var indentString = "", |
| 11102 | pos = 0 |
| 11103 | if (cm.options.indentWithTabs) { |
| 11104 | for (var i = Math.floor(indentation / tabSize); i; --i) { |
| 11105 | pos += tabSize |
| 11106 | indentString += "\t" |
| 11107 | } |
no test coverage detected