public class InsertFormattedLineBreakAction {
public static boolean execute() {
if (!isEnabled()) return false;
EclipseEmmetEditor editor = ActionRunner.getSingleton().getEditor();
if (editor != null && shouldHandle(editor)) {
try {
Boolean result = Emmet.getSingleton().runAction(editor, "insert_formatted_line_break_only");
if (!result) {
String curPadding = editor.getCurrentLinePadding();
String content = editor.getContent();
int caretPos = editor.getCaretPos();
int c_len = content.length();
String nl = editor.getNewline();
String nextNl = editor.getDocument().getLineDelimiter( editor.getDocument().getLineOfOffset(caretPos) );
if (nextNl != null)
nl = nextNl;
// check out next line padding
SelectionData lineRange = editor.getCurrentLineRange();
StringBuilder nextPadding = new StringBuilder();
for (int i = lineRange.getEnd() + nl.length(); i < c_len; i++) {
char ch = content.charAt(i);
if (ch == ' ' || ch == '\t')
nextPadding.append(ch);
else
break;
}
if (nextPadding.length() > curPadding.length()) {
editor.replaceContent(nl + nextPadding.toString(), caretPos, caretPos, true);
result = true;
}
}
return result;