PY-18522 PY-19053 Paste raw text if there are non whitespace symbols before caret on line

This previously existed check was lost after the recent fixes for
PY-18522. It also caused failures of PyCopyPasteTest.testEmpty(), so
I reverted previous fix for the test.
This commit is contained in:
Mikhail Golubev
2016-04-04 21:52:11 +03:00
parent 546bb0d275
commit 77425f305d
5 changed files with 18 additions and 7 deletions
@@ -82,6 +82,9 @@ public class PythonCopyPasteProcessor implements CopyPastePreProcessor {
final int lineStartOffset = getLineStartSafeOffset(document, lineNumber);
final int lineEndOffset = document.getLineEndOffset(lineNumber);
final String linePrefix = document.getText(TextRange.create(lineStartOffset, caretOffset));
if (!StringUtil.isEmptyOrSpaces(linePrefix)) return text;
final PsiElement element = file.findElementAt(caretOffset);
if (PsiTreeUtil.getParentOfType(element, PyStringLiteralExpression.class) != null) return text;
@@ -186,15 +189,13 @@ public class PythonCopyPasteProcessor implements CopyPastePreProcessor {
}
private static boolean isApplicable(@NotNull final PsiFile file, @NotNull String text, int caretOffset) {
final boolean useTabs = CodeStyleSettingsManager.getSettings(file.getProject()).useTabCharacter(PythonFileType.INSTANCE);
final boolean useTabs =
CodeStyleSettingsManager.getSettings(file.getProject()).useTabCharacter(PythonFileType.INSTANCE);
final PsiElement nonWS = PyUtil.findNextAtOffset(file, caretOffset, PsiWhiteSpace.class);
if (nonWS == null) {
return !StringUtil.isEmptyOrSpaces(text);
}
if (text.endsWith("\n") ||
(inStatementList(file, caretOffset) && (text.startsWith(useTabs ? "\t" : " ") || StringUtil.split(text, "\n").size() > 1))) {
if (nonWS == null || text.endsWith("\n"))
return true;
if (inStatementList(file, caretOffset) && (text.startsWith(useTabs ? "\t" : " ") || StringUtil.split(text, "\n").size() > 1))
return true;
}
return false;
}
@@ -0,0 +1,2 @@
def foo():
x = 10 * 20
@@ -0,0 +1,2 @@
def foo():
x = 10 * <caret>
@@ -0,0 +1 @@
<selection>20</selection>
@@ -391,4 +391,9 @@ public class PyCopyPasteTest extends PyTestCase {
public void testEmptyFunctionCaretAtBodyIndent() {
doTest();
}
// PY-19053
public void testSimpleExpressionPartCaretAtLineEnd() {
doTest();
}
}