Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dmitry Trofimov
2012-07-09 18:54:58 +02:00
3 changed files with 22 additions and 5 deletions
@@ -52,6 +52,7 @@ public class CopyPasteIndentProcessor implements CopyPastePostProcessor<IndentTr
}
}
int minIndent = Integer.MAX_VALUE;
int maxIndent = 0;
int tabSize = CodeStyleFacade.getInstance(file.getProject()).getTabSize(file.getFileType());
for (int line = selStartLine; line <= selEndLine; line++) {
int start = document.getLineStartOffset(line);
@@ -59,11 +60,12 @@ public class CopyPasteIndentProcessor implements CopyPastePostProcessor<IndentTr
int indent = getIndent(document.getCharsSequence(), start, end, tabSize);
if (indent >= 0) {
minIndent = Math.min(minIndent, indent);
maxIndent = Math.max(minIndent, indent);
}
}
int firstNonSpaceChar = CharArrayUtil.shiftForward(document.getCharsSequence(), startOffsets[0], " \t");
int firstLineLeadingSpaces = (firstNonSpaceChar <= document.getLineEndOffset(selStartLine)) ? firstNonSpaceChar - startOffsets[0] : 0;
return new IndentTransferableData(minIndent, firstLineLeadingSpaces);
return new IndentTransferableData(maxIndent - minIndent, maxIndent, firstLineLeadingSpaces);
}
private static boolean acceptFileType(FileType fileType) {
@@ -149,12 +151,17 @@ public class CopyPasteIndentProcessor implements CopyPastePostProcessor<IndentTr
EditorActionUtil.indentLine(project, editor, startLine, -value.getFirstLineLeadingSpaces());
}
final int caretOffset = editor.getCaretModel().getOffset();
int realCaretColumn = caretOffset - document.getLineStartOffset(document.getLineNumber(caretOffset));
final List<String> strings = StringUtil.split(pastedText, "\n");
if (caretColumn > value.getIndent() && !strings.isEmpty() &&
if (realCaretColumn >= value.getIndent() && !strings.isEmpty() &&
StringUtil.isEmptyOrSpaces(strings.get(strings.size()-1))) endLine -=1;
for (int i = startLine+1; i <= endLine; i++) {
EditorActionUtil.indentLine(project, editor, i, value.getIndent());
int indent = value.getFirstLineLeadingSpaces() <= realCaretColumn ||
value.getFirstLineLeadingSpaces() == value.getMaxIndent()? value.getIndent() : -value.getIndent();
EditorActionUtil.indentLine(project, editor, i, indent);
}
indented.set(Boolean.TRUE);
}
@@ -12,10 +12,12 @@ public class IndentTransferableData implements TextBlockTransferableData, Serial
private static @NonNls DataFlavor ourFlavor;
private final int myIndent;
private final int myMaxIndent;
private final int myFirstLineLeadingSpaces;
public IndentTransferableData(int indent, int firstLineLeadingSpaces) {
public IndentTransferableData(int indent, int maxIndent, int firstLineLeadingSpaces) {
myIndent = indent;
myMaxIndent = maxIndent;
myFirstLineLeadingSpaces = firstLineLeadingSpaces;
}
@@ -23,6 +25,10 @@ public class IndentTransferableData implements TextBlockTransferableData, Serial
return myIndent;
}
public int getMaxIndent() {
return myMaxIndent;
}
public int getFirstLineLeadingSpaces() {
return myFirstLineLeadingSpaces;
}
@@ -60,6 +66,6 @@ public class IndentTransferableData implements TextBlockTransferableData, Serial
}
protected IndentTransferableData clone() {
return new IndentTransferableData(myIndent, myFirstLineLeadingSpaces);
return new IndentTransferableData(myIndent, myMaxIndent, myFirstLineLeadingSpaces);
}
}
@@ -160,6 +160,10 @@ public class ExecUtil {
return sudoAndGetOutput(scriptPath, prompt, null);
}
/**
*
* @param scriptPath is already escaped filepath
*/
public static ProcessOutput sudoAndGetOutput(@NotNull final String scriptPath,
@NotNull final String prompt,
@Nullable String workDir) throws IOException, ExecutionException {