public int insertionIndexForRule(boolean lexer) {
// Add the rule in the next line by default
Point p = window.getTextEditor().getLineTextPositionsAtTextPosition(window.getCaretPosition());
int insertionIndex = p.y;
ElementRule rule = window.editorRules.getEnclosingRuleAtPosition(window.getCaretPosition());
if(rule != null) {
if(rule.lexer) {
if(lexer) {
// Add new rule just after this one
insertionIndex = rule.getEndIndex();
} else {
// Add new rule after the last parser rule
ElementRule last = window.editorRules.getLastParserRule();
if(last != null) insertionIndex = last.getEndIndex();
}
} else {
if(lexer) {
// Add new rule after the last lexer rule
ElementRule last = window.editorRules.getLastLexerRule();
if(last != null) {
insertionIndex = last.getEndIndex();
} else {
// Add new rule after the last rule
last = window.editorRules.getLastRule();
if(last != null) insertionIndex = last.getEndIndex();
}
} else {
// Add new rule just after this one
insertionIndex = rule.getEndIndex();
}