(cm, n, how, aggressive)
| 2761 | // API UTILITIES |
| 2762 | |
| 2763 | function indentLine(cm, n, how, aggressive) { |
| 2764 | var doc = cm.doc, state; |
| 2765 | if (how == null) how = "add"; |
| 2766 | if (how == "smart") { |
| 2767 | if (!cm.doc.mode.indent) how = "prev"; |
| 2768 | else state = getStateBefore(cm, n); |
| 2769 | } |
| 2770 | |
| 2771 | var tabSize = cm.options.tabSize; |
| 2772 | var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize); |
| 2773 | if (line.stateAfter) line.stateAfter = null; |
| 2774 | var curSpaceString = line.text.match(/^\s*/)[0], indentation; |
| 2775 | if (!aggressive && !/\S/.test(line.text)) { |
| 2776 | indentation = 0; |
| 2777 | how = "not"; |
| 2778 | } else if (how == "smart") { |
| 2779 | indentation = cm.doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text); |
| 2780 | if (indentation == Pass) { |
| 2781 | if (!aggressive) return; |
| 2782 | how = "prev"; |
| 2783 | } |
| 2784 | } |
| 2785 | if (how == "prev") { |
| 2786 | if (n > doc.first) indentation = countColumn(getLine(doc, n-1).text, null, tabSize); |
| 2787 | else indentation = 0; |
| 2788 | } else if (how == "add") { |
| 2789 | indentation = curSpace + cm.options.indentUnit; |
| 2790 | } else if (how == "subtract") { |
| 2791 | indentation = curSpace - cm.options.indentUnit; |
| 2792 | } else if (typeof how == "number") { |
| 2793 | indentation = curSpace + how; |
| 2794 | } |
| 2795 | indentation = Math.max(0, indentation); |
| 2796 | |
| 2797 | var indentString = "", pos = 0; |
| 2798 | if (cm.options.indentWithTabs) |
| 2799 | for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";} |
| 2800 | if (pos < indentation) indentString += spaceStr(indentation - pos); |
| 2801 | |
| 2802 | if (indentString != curSpaceString) |
| 2803 | replaceRange(cm.doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input"); |
| 2804 | else if (doc.sel.head.line == n && doc.sel.head.ch < curSpaceString.length) |
| 2805 | setSelection(doc, Pos(n, curSpaceString.length), Pos(n, curSpaceString.length), 1); |
| 2806 | line.stateAfter = null; |
| 2807 | } |
| 2808 | |
| 2809 | function changeLine(cm, handle, op) { |
| 2810 | var no = handle, line = handle, doc = cm.doc; |
no test coverage detected