Changeset View
Changeset View
Standalone View
Standalone View
src/script/data/indentation/cstyle.js
Show First 20 Lines • Show All 757 Lines • ▼ Show 20 Line(s) | 751 | { | |||
---|---|---|---|---|---|
758 | 758 | | |||
759 | var column = cursor.column; | 759 | var column = cursor.column; | ||
760 | var firstPos = document.firstColumn(line); | 760 | var firstPos = document.firstColumn(line); | ||
761 | var prevFirstPos = document.firstColumn(line - 1); | 761 | var prevFirstPos = document.firstColumn(line - 1); | ||
762 | var lastPos = document.lastColumn(line); | 762 | var lastPos = document.lastColumn(line); | ||
763 | 763 | | |||
764 | dbg("firstPos: " + firstPos); | 764 | dbg("firstPos: " + firstPos); | ||
765 | dbg("column..: " + column); | 765 | dbg("column..: " + column); | ||
766 | dbg("char : " + c); | ||||
766 | 767 | | |||
767 | if (firstPos == column - 1 && c == '{') { | 768 | if (firstPos == column - 1 && c == '{') { | ||
768 | // todo: maybe look for if etc. | 769 | // todo: maybe look for if etc. | ||
769 | var filler = tryBrace(line); | 770 | var filler = tryBrace(line); | ||
770 | if (filler == -1) | 771 | if (filler == -1) | ||
771 | filler = tryCKeywords(line, true); | 772 | filler = tryCKeywords(line, true); | ||
772 | if (filler == -1) | 773 | if (filler == -1) | ||
773 | filler = tryCComment(line); // checks, whether we had a "*/" | 774 | filler = tryCComment(line); // checks, whether we had a "*/" | ||
Show All 11 Lines | 781 | } else if (firstPos == column - 1 && c == '}' && document.charAt(line, column - 1) == '}') { | |||
785 | return indentation; | 786 | return indentation; | ||
786 | } else if (firstPos == column - 1 && c == '}' && firstPos > prevFirstPos) { | 787 | } else if (firstPos == column - 1 && c == '}' && firstPos > prevFirstPos) { | ||
787 | // align indentation to previous line when creating new block with auto brackets enabled | 788 | // align indentation to previous line when creating new block with auto brackets enabled | ||
788 | // prevents over-indentation for if blocks and loops | 789 | // prevents over-indentation for if blocks and loops | ||
789 | return prevFirstPos; | 790 | return prevFirstPos; | ||
790 | } else if (cfgSnapSlash && c == '/' && lastPos == column - 1) { | 791 | } else if (cfgSnapSlash && c == '/' && lastPos == column - 1) { | ||
791 | // try to snap the string "* /" to "*/" | 792 | // try to snap the string "* /" to "*/" | ||
792 | var currentString = document.line(line); | 793 | var currentString = document.line(line); | ||
793 | if (currentString.search(/^(\s*)\*\s+\/\s*$/) != -1) { | 794 | if (/^(\s*)\*\s+\/\s*$/.test(currentString)) { | ||
794 | currentString = RegExp.$1 + "*/"; | 795 | currentString = RegExp.$1 + "*/"; | ||
795 | document.editBegin(); | 796 | document.editBegin(); | ||
796 | document.removeLine(line); | 797 | document.removeLine(line); | ||
797 | document.insertLine(line, currentString); | 798 | document.insertLine(line, currentString); | ||
798 | view.setCursorPosition(line, currentString.length); | 799 | view.setCursorPosition(line, currentString.length); | ||
799 | document.editEnd(); | 800 | document.editEnd(); | ||
800 | } | 801 | } | ||
801 | return -2; | 802 | return -2; | ||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |