fixed PY-7524 Dragged/pasted code in wrong location

fixed PY-7470 Smart copy-paste unindents next line (in place insert)
This commit is contained in:
Ekaterina Tuzova
2012-09-11 20:30:27 +04:00
parent a34e75a3f9
commit d68883c9e3
@@ -108,11 +108,7 @@ public class CopyPasteIndentProcessor implements CopyPastePostProcessor<IndentTr
final int offset = getLineStartSafeOffset(initialDocument, lineNumber);
final int caretColumn = caretOffset - offset;
if (bounds.getStartOffset() != offset) { //selection
startLine += 1;
toIndent = Math.abs(bounds.getStartOffset() - offset);
}
else {
if (bounds.getStartOffset() == offset) {
String toString = initialDocument.getText(TextRange.create(offset, initialDocument.getLineEndOffset(lineNumber)));
toIndent = StringUtil.findFirst(toString, new CharFilter() {
@Override
@@ -124,6 +120,12 @@ public class CopyPasteIndentProcessor implements CopyPastePostProcessor<IndentTr
toIndent = caretColumn;
}
}
else if (isNotApplicable(initialDocument, offset))
return;
else { // selection
startLine += 1;
toIndent = Math.abs(bounds.getStartOffset() - offset);
}
}
// actual difference in indentation level
@@ -141,6 +143,11 @@ public class CopyPasteIndentProcessor implements CopyPastePostProcessor<IndentTr
}
indented.set(Boolean.TRUE);
}
private boolean isNotApplicable(DocumentImpl initialDocument, int offset) {
return caretOffset < initialDocument.getTextLength() && !StringUtil
.isEmptyOrSpaces(initialDocument.getText(TextRange.create(offset, caretOffset)));
}
});
//System.out.println("--- after indent ---\n" + document.getText());
}