// if either the skipped line or the moving lines are outside the widget's
// visible area, bail out
if (!containedByVisibleRegion(movingArea, viewer) || !containedByVisibleRegion(skippedLine, viewer))
return;
PySelection skippedPs = new PySelection(document, skippedLine);
// get the content to be moved around: the moving (selected) area and the skipped line
String moving = movingArea.getText();
String skipped = skippedLine.getText();
if (moving == null || skipped == null || document.getLength() == 0)
return;
String delim;
String insertion;
int offset;
int length;
ILineRange selectionBefore = getLineRange(document, movingArea);
IRewriteTarget target = null;
if (pyEdit != null) {
target = (IRewriteTarget) pyEdit.getAdapter(IRewriteTarget.class);
if (target != null) {
target.beginCompoundChange();
if (!getMoveUp()) {
//When going up we'll just do a single document change, so, there's
//no need to set the redraw.
target.setRedraw(false);
}
}
}
ILineRange selectionAfter;
boolean isStringPartition;
try {
if (getMoveUp()) {
//check partition in the start of the skipped line
isStringPartition = ParsingUtils.isStringPartition(document, skippedLine.getOffset());
delim = document.getLineDelimiter(skippedLine.getEndLine());
Assert.isNotNull(delim);
offset = skippedLine.getOffset();
length = moving.length() + delim.length() + skipped.length();
} else {
//check partition in the start of the line after the skipped line
int offsetToCheckPartition;
if (skippedLine.getEndLine() == document.getNumberOfLines() - 1) {
offsetToCheckPartition = document.getLength() - 1; //check the last document char
} else {
offsetToCheckPartition = skippedLine.getOffset() + skippedLine.getLength(); //that's always the '\n' of the line
}
isStringPartition = ParsingUtils.isStringPartition(document, offsetToCheckPartition);
delim = document.getLineDelimiter(movingArea.getEndLine());
Assert.isNotNull(delim);
offset = movingArea.getOffset();
//When going down, we need to remove the movingArea to compute the new indentation
//properly (otherwise we'd use that text being moved on the compute algorithm)
document.replace(movingArea.getOffset(), movingArea.getLength() + delim.length(), "");
length = skipped.length();
int pos = skippedPs.getAbsoluteCursorOffset() - (movingArea.getLength() + delim.length());
skippedPs.setSelection(pos, pos);
}
PyAutoIndentStrategy indentStrategy = null;
if (pyEdit != null) {
indentStrategy = pyEdit.getAutoEditStrategy();