1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Sort Lines command.

This commit is contained in:
Sergey Prigogin 2010-05-03 05:48:29 +00:00
parent d6c48415c3
commit 404e31b20a

View file

@ -78,8 +78,6 @@ public final class SortLinesAction extends TextEditorAction {
CodeFormatterUtil.getTabWidth(cProject));
if (elements.length <= 1)
return;
if (!validateEditorInputState())
return;
Arrays.sort(elements);
StringBuilder buf = new StringBuilder();
@ -89,7 +87,13 @@ public final class SortLinesAction extends TextEditorAction {
buf.append(TextUtilities.getDefaultLineDelimiter(document));
}
}
ReplaceEdit edit = new ReplaceEdit(block.getOffset(), block.getLength(), buf.toString());
String replacement = buf.toString();
if (replacement.equals(document.get(block.getOffset(), block.getLength())))
return;
if (!validateEditorInputState())
return;
ReplaceEdit edit = new ReplaceEdit(block.getOffset(), block.getLength(), replacement);
IDocumentUndoManager manager= DocumentUndoManagerRegistry.getDocumentUndoManager(document);
manager.beginCompoundChange();
edit.apply(document);