diff --git a/src/script/data/indentation/cstyle.js b/src/script/data/indentation/cstyle.js --- a/src/script/data/indentation/cstyle.js +++ b/src/script/data/indentation/cstyle.js @@ -70,6 +70,7 @@ function findLeftBrace(line, column) { var cursor = document.anchor(line, column, '{'); + dbg(cursor); if (cursor.isValid()) { var parenthesisCursor = tryParenthesisBeforeBrace(cursor.line, cursor.column); if (parenthesisCursor.isValid()) @@ -751,9 +752,10 @@ if (!cursor) return -2; - var column = cursor.column; - var firstPos = document.firstColumn(line); - var lastPos = document.lastColumn(line); + var column = cursor.column; + var firstPos = document.firstColumn(line); + var prevFirstPos = document.firstColumn(line - 1); + var lastPos = document.lastColumn(line); dbg("firstPos: " + firstPos); dbg("column..: " + column); @@ -771,11 +773,16 @@ filler = -2; return filler; - } else if (firstPos == column - 1 && c == '}') { + } else if (firstPos == column - 1 && c == '}' && document.charAt(line, column - 1) == '}') { + // unindent after closing brace, but not when brace is auto inserted (i.e., behind cursor) var indentation = findLeftBrace(line, firstPos); if (indentation == -1) indentation = -2; return indentation; + } else if (firstPos == column - 1 && c == '}' && firstPos > prevFirstPos) { + // align indentation to previous line when creating new block with auto brackets enabled + // prevents over-indentation for if blocks and loops + return prevFirstPos; } else if (cfgSnapSlash && c == '/' && lastPos == column - 1) { // try to snap the string "* /" to "*/" var currentString = document.line(line);