Skip to content

Commit

Permalink
Merge pull request #1490 from supercollider/topic/fix-newlines-before…
Browse files Browse the repository at this point in the history
…-closing-bracket

ide: better newline behavior within brackets
  • Loading branch information
telephon committed May 26, 2015
2 parents d4d2abc + 3090eff commit ed6442f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion editors/sc-ide/widgets/code_editor/sc_editor.cpp
Expand Up @@ -174,8 +174,15 @@ void ScCodeEditor::keyPressEvent( QKeyEvent *e )
{
QTextBlock cursorBlock = cursor.block();
int cursorPosInBlock = cursor.position() - cursorBlock.position();

TokenIterator prevToken = TokenIterator::leftOf(cursorBlock, cursorPosInBlock);
TokenIterator nextToken = TokenIterator::rightOf(cursorBlock, cursorPosInBlock);
if ( nextToken.block() == cursorBlock && nextToken.type() == Token::ClosingBracket )

if ( nextToken.block() == cursorBlock
&& nextToken.type() == Token::ClosingBracket
&& prevToken.type() != Token::ClosingBracket // no double-newline if cursor is between closing brackets, i.e. ])
&& !(prevToken.block().firstLineNumber() < nextToken.block().firstLineNumber()) // no double-nl if only whitespace to the left
)
{
cursor.beginEditBlock();
cursor.insertBlock();
Expand Down

0 comments on commit ed6442f

Please sign in to comment.