Indentation after pressing enter

Answered

I have a formatting issue with my custom language plugin that i'm not sure how to resolve.

After formatting the file, if I click between the braces it shows the caret at the correct location:

However, if i place my caret on the top brace and press enter, the caret doesn't indent properly

I'm guessing this is something to do with the Alignment setting, i've tried creating a new alignment for all of the children of the statement block, but this doesn't seem to affect the caret.

Does anyone have any suggestions on how to investigate/fix this?

0
3 comments

The solution was to implement getChildAttributes like so:

@NotNull
@Override
public ChildAttributes getChildAttributes(final int newIndex)
{
final LSLBlock previousBlock = newIndex == 0 ? null : getSubLSLBlocks().get(newIndex - 1);
final IElementType previousType = previousBlock == null ? null : previousBlock.getNode().getElementType();

if (previousBlock == null)
{
return new ChildAttributes(Indent.getNoneIndent(), null);
}

if (previousType == LSLTypes.BRACES_START || previousType == LSLTypes.BRACKETS_START)
{
// Indentation after first brace
return new ChildAttributes(Indent.getNormalIndent(), null);
}

if (!previousBlock.isIncomplete() && newIndex < getSubLSLBlocks().size() && previousType != TokenType.ERROR_ELEMENT)
{
// Indentation before last brace
return new ChildAttributes(previousBlock.getIndent(), previousBlock.getAlignment());
}

return new ChildAttributes(previousBlock.getIndent(), previousBlock.getAlignment());
}
2

Hi Thomas,

Thank you for sharing this simple yet useful implementation for handling enter key indentation.

😊

0

This method is from which class? Also do I need to add any extension point for this?

0

Please sign in to leave a comment.