mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-86397 Delete line (Ctrl+Y) moves caret to the 1st column position
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -44,9 +44,12 @@ public class EditorModificationUtil {
|
||||
int selectionStart = selectionModel.getSelectionStart();
|
||||
int selectionEnd = selectionModel.getSelectionEnd();
|
||||
|
||||
editor.getCaretModel().moveToOffset(selectionStart);
|
||||
final CaretModel caretModel = editor.getCaretModel();
|
||||
final VisualPosition position = caretModel.getVisualPosition();
|
||||
caretModel.moveToOffset(selectionStart);
|
||||
selectionModel.removeSelection();
|
||||
editor.getDocument().deleteString(selectionStart, selectionEnd);
|
||||
caretModel.moveToVisualPosition(position); // Try to preserve visual caret position
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
}
|
||||
|
||||
|
||||
+15
@@ -980,6 +980,21 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorP
|
||||
assertEquals(text, myEditor.getSelectionModel().getSelectedText());
|
||||
}
|
||||
|
||||
public void testCaretPositionAfterLineRemoval() throws IOException {
|
||||
final String text =
|
||||
"123456\n" +
|
||||
"123456\n" +
|
||||
"line towrapbecauseitislong\n" +
|
||||
"923456";
|
||||
init(8, text);
|
||||
final CaretModel caretModel = myEditor.getCaretModel();
|
||||
caretModel.moveToOffset(text.indexOf("e"));
|
||||
final VisualPosition position = caretModel.getVisualPosition();
|
||||
deleteLine();
|
||||
assertEquals(text.substring(0, text.indexOf("line")) + text.substring(text.indexOf('9')), myEditor.getDocument().getText());
|
||||
assertEquals(position, caretModel.getVisualPosition());
|
||||
}
|
||||
|
||||
private void init(final int visibleWidthInColumns, @NotNull String fileText) throws IOException {
|
||||
int symbolWidthInPixels = 7;
|
||||
init(visibleWidthInColumns * symbolWidthInPixels, fileText, symbolWidthInPixels);
|
||||
|
||||
Reference in New Issue
Block a user