if(editor != null && editor.isEditable()){
try {
// foldingSetter.takeSnapshot();
// Loop over each line, performing the right trim
IRewriteTarget target= (IRewriteTarget)editor.getAdapter(IRewriteTarget.class);
if (target != null)
target.beginCompoundChange();
int currentLine = 0;
while (currentLine < doc.getNumberOfLines()) {
int offset = doc.getLineOffset(currentLine);
int length = doc.getLineLength(currentLine);
oldText = doc.get(offset, length);
trimmer.reset(oldText);
newText = trimmer.replaceAll("");
// Replace the old line if the length is different
if (newText.length() != length) {
doc.replace(offset, length, newText);
// Update the cursor offset for the characters removed
if (offset < cursorOffset) {
cursorOffset -= (length - newText.length());
}
}
currentLine++;
}
TextSelection selection = new TextSelection(doc, cursorOffset, selectionLength);
editor.getSelectionProvider().setSelection(selection);
if (target != null)
target.endCompoundChange();
// foldingSetter.restoreSnapshot();
} catch (Exception blx) {
blx.printStackTrace();
}