use of org.erlide.engine.services.text.IndentResult in project erlide_eclipse by erlang.
the class AutoIndentStrategy method indentAfterNewLine.
protected void indentAfterNewLine(final IDocument d, final DocumentCommand c) throws BadLocationException {
if (editor == null) {
return;
}
final int offset = c.offset;
String txt = null;
editor.reconcileNow();
final IErlElement element = editor.getElementAt(offset, false);
final IErlMember member = (IErlMember) element;
if (member != null) {
final int start = member.getSourceRange().getOffset();
if (offset >= start) {
txt = d.get(start, offset - start);
}
}
if (txt == null) {
txt = "";
}
final int lineN = d.getLineOfOffset(offset);
final int lineOffset = d.getLineOffset(lineN);
final int lineLength = d.getLineLength(lineN);
final String oldLine = d.get(offset, lineLength + lineOffset - offset);
try {
final int indentw = AutoIndentStrategy.getIndentWidthFromPreferences();
final int tabw = EditorsUI.getPreferenceStore().getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH);
final Map<String, String> prefs = new TreeMap<>();
IndentationPreferencePage.addKeysAndPrefs(prefs);
SmartTypingPreferencePage.addAutoNLKeysAndPrefs(prefs);
final boolean useTabs = AutoIndentStrategy.getUseTabsFromPreferences();
final IndentResult res = ErlangEngine.getInstance().getIndentService().indentLine(oldLine, txt, c.text, indentw, tabw, useTabs, prefs);
if (res.isAddNewLine()) {
c.text += "\n";
}
c.text += res.getText();
c.length += res.getRemoveNext();
} catch (final Exception e) {
ErlLogger.warn(e);
}
}
Aggregations