diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/DuplicateActionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/DuplicateActionTest.groovy index 00e1a2a41cf0..fe9ced59cc21 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/DuplicateActionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/DuplicateActionTest.groovy @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.codeInsight; @@ -14,7 +29,7 @@ xxx } public void testEmpty() { - doTest '', "txt", '\n' + doTest '', "txt", '' } private void doTest(String before, @NonNls String ext, String after) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/DuplicateAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/DuplicateAction.java index 72a05fb0fc29..551d8efcc8d9 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/DuplicateAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/DuplicateAction.java @@ -31,6 +31,7 @@ import com.intellij.openapi.editor.actionSystem.EditorAction; import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler; import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.util.Pair; +import org.jetbrains.annotations.Nullable; public class DuplicateAction extends EditorAction { public DuplicateAction() { @@ -68,6 +69,7 @@ public class DuplicateAction extends EditorAction { } } + @Nullable static Pair duplicateLinesRange(Editor editor, Document document, VisualPosition rangeStart, VisualPosition rangeEnd) { Pair lines = EditorUtil.calcSurroundingRange(editor, rangeStart, rangeEnd); int offset = editor.getCaretModel().getOffset(); @@ -76,6 +78,9 @@ public class DuplicateAction extends EditorAction { LogicalPosition nextLineStart = lines.second; int start = editor.logicalPositionToOffset(lineStart); int end = editor.logicalPositionToOffset(nextLineStart); + if (end <= start) { + return null; + } String s = document.getCharsSequence().subSequence(start, end).toString(); final int lineToCheck = nextLineStart.line - 1; diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/DuplicateLinesAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/DuplicateLinesAction.java index fc3c86c50aed..2560098f9902 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/DuplicateLinesAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/DuplicateLinesAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,7 +40,9 @@ public class DuplicateLinesAction extends EditorAction { VisualPosition rangeEnd = editor.offsetToVisualPosition(Math.max(selStart, selEnd)); final Pair copiedRange = DuplicateAction.duplicateLinesRange(editor, editor.getDocument(), rangeStart, rangeEnd); - editor.getSelectionModel().setSelection(copiedRange.first, copiedRange.second); + if (copiedRange != null) { + editor.getSelectionModel().setSelection(copiedRange.first, copiedRange.second); + } } else { VisualPosition caretPos = editor.getCaretModel().getVisualPosition();