what is the correct way to implement indent after "enter"

I'm trying to add an indent in my simple "if block" that looks exactly like in java. I tried with formatters, which doesn't seem to be the way to go. Now i'm trying with enter processors and handlers/delegates, but no luck still, they don't seem to trigger at all. Is there an example or documentation on how to do it?

1 comment
Comment actions Permalink

the last thing I tried was to extend "EnterBetweenBracesDelegate" and override "formatAtOffset" where I tried to append white spaces "    " and move caret. It did append the white spaces but didn't move the caret. 

editor.getDocument().insertString(editor.getCaretModel().getOffset() - 5, "    ");
LogicalPosition logicalPosition = editor.getCaretModel().getLogicalPosition();
LogicalPosition newLogicalPosition = new LogicalPosition(logicalPosition.line, logicalPosition.column + 4);

editor.getCaretModel().moveToLogicalPosition(newLogicalPosition);

Any way, what I'm trying doesn't sound right. But over the years, many people asked the same question as me, and I didn't see any useful answer. Seems like everyone is trying just about anything, eventually they get it working in probably sub-optimal way. Some documentation on this would be useful.

 

0

Please sign in to leave a comment.