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();
}
if (indentStrategy == null) {
indentStrategy = new PyAutoIndentStrategy();
}
if (!isStringPartition) {
if (indentStrategy.getIndentPrefs().getSmartLineMove()) {
String prevExpectedIndent = calculateNewIndentationString(document, skippedPs, indentStrategy);
if (prevExpectedIndent != null) {
moving = StringUtils.removeWhitespaceColumnsToLeftAndApplyIndent(moving,
prevExpectedIndent, false);
}
}
}
if (getMoveUp()) {
insertion = moving + delim + skipped;
} else {
insertion = skipped + delim + moving;
}
// modify the document
document.replace(offset, length, insertion);
if (getMoveUp()) {
selectionAfter = new LineRange(selectionBefore.getStartLine() - 1,
selectionBefore.getNumberOfLines());
} else {
selectionAfter = new LineRange(selectionBefore.getStartLine() + 1,
selectionBefore.getNumberOfLines());
}
} finally {
if (target != null) {
target.endCompoundChange();
if (!getMoveUp()) {
target.setRedraw(true);
}
}
}
// move the selection along