Changeset View
Changeset View
Standalone View
Standalone View
src/script/data/indentation/cstyle.js
Show First 20 Lines • Show All 747 Lines • ▼ Show 20 Line(s) | 747 | if (c == ';' || !triggerCharacters.contains(c)) | |||
---|---|---|---|---|---|
748 | return -2; | 748 | return -2; | ||
749 | 749 | | |||
750 | var cursor = view.cursorPosition(); | 750 | var cursor = view.cursorPosition(); | ||
751 | if (!cursor) | 751 | if (!cursor) | ||
752 | return -2; | 752 | return -2; | ||
753 | 753 | | |||
754 | var column = cursor.column; | 754 | var column = cursor.column; | ||
755 | var firstPos = document.firstColumn(line); | 755 | var firstPos = document.firstColumn(line); | ||
756 | var prevFirstPos = document.firstColumn(line - 1); | ||||
756 | var lastPos = document.lastColumn(line); | 757 | var lastPos = document.lastColumn(line); | ||
brauch: please don't use this alignment style, just one space before and after the = | |||||
757 | 758 | | |||
758 | dbg("firstPos: " + firstPos); | 759 | dbg("firstPos: " + firstPos); | ||
759 | dbg("column..: " + column); | 760 | dbg("column..: " + column); | ||
760 | 761 | | |||
761 | if (firstPos == column - 1 && c == '{') { | 762 | if (firstPos == column - 1 && c == '{') { | ||
762 | // todo: maybe look for if etc. | 763 | // todo: maybe look for if etc. | ||
763 | var filler = tryBrace(line); | 764 | var filler = tryBrace(line); | ||
764 | if (filler == -1) | 765 | if (filler == -1) | ||
765 | filler = tryCKeywords(line, true); | 766 | filler = tryCKeywords(line, true); | ||
766 | if (filler == -1) | 767 | if (filler == -1) | ||
767 | filler = tryCComment(line); // checks, whether we had a "*/" | 768 | filler = tryCComment(line); // checks, whether we had a "*/" | ||
768 | if (filler == -1) | 769 | if (filler == -1) | ||
769 | filler = tryStatement(line); | 770 | filler = tryStatement(line); | ||
770 | if (filler == -1) | 771 | if (filler == -1) | ||
771 | filler = -2; | 772 | filler = -2; | ||
772 | 773 | | |||
773 | return filler; | 774 | return filler; | ||
774 | } else if (firstPos == column - 1 && c == '}') { | 775 | } else if (firstPos == column - 1 && c == '}' && document.charAt(line, column - 1) == '}') { | ||
776 | // unindent after closing brace, but not when brace is auto inserted (i.e., behind cursor) | ||||
775 | var indentation = findLeftBrace(line, firstPos); | 777 | var indentation = findLeftBrace(line, firstPos); | ||
776 | if (indentation == -1) | 778 | if (indentation == -1) | ||
777 | indentation = -2; | 779 | indentation = -2; | ||
778 | return indentation; | 780 | return indentation; | ||
781 | } else if (firstPos == column - 1 && c == '}' && firstPos > prevFirstPos) { | ||||
782 | // align indentation to previous line when creating new block with auto brackets enabled | ||||
783 | // prevents over-indentation for if blocks and loops | ||||
784 | return prevFirstPos; | ||||
779 | } else if (cfgSnapSlash && c == '/' && lastPos == column - 1) { | 785 | } else if (cfgSnapSlash && c == '/' && lastPos == column - 1) { | ||
780 | // try to snap the string "* /" to "*/" | 786 | // try to snap the string "* /" to "*/" | ||
781 | var currentString = document.line(line); | 787 | var currentString = document.line(line); | ||
782 | if (currentString.search(/^(\s*)\*\s+\/\s*$/) != -1) { | 788 | if (currentString.search(/^(\s*)\*\s+\/\s*$/) != -1) { | ||
783 | currentString = RegExp.$1 + "*/"; | 789 | currentString = RegExp.$1 + "*/"; | ||
784 | document.editBegin(); | 790 | document.editBegin(); | ||
785 | document.removeLine(line); | 791 | document.removeLine(line); | ||
786 | document.insertLine(line, currentString); | 792 | document.insertLine(line, currentString); | ||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |
please don't use this alignment style, just one space before and after the =