mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-85100 Deleting wrapped lines with Ctrl+Y doen't work properly with "soft wrapped" lines
Correct processing for the empty document
This commit is contained in:
@@ -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<caret>
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
doTest '<caret>', "txt", '\n<caret>'
|
||||
doTest '<caret>', "txt", '<caret>'
|
||||
}
|
||||
|
||||
private void doTest(String before, @NonNls String ext, String after) {
|
||||
|
||||
@@ -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<Integer, Integer> duplicateLinesRange(Editor editor, Document document, VisualPosition rangeStart, VisualPosition rangeEnd) {
|
||||
Pair<LogicalPosition, LogicalPosition> 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;
|
||||
|
||||
|
||||
+4
-2
@@ -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<Integer,Integer> 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();
|
||||
|
||||
Reference in New Issue
Block a user