1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-08-01 15:59:06 +02:00

Merge branch 'visual_block_delete'

This commit is contained in:
Andrey Vlasovskikh 2014-10-23 16:55:17 +04:00
commit 72b74e075c
3 changed files with 32 additions and 12 deletions
src/com/maddyhome/idea/vim/group
test/org/jetbrains/plugins/ideavim/action

View File

@ -1574,17 +1574,25 @@ public class MotionGroup {
public TextRange getVisualRange(@NotNull Editor editor) {
final TextRange res = new TextRange(editor.getSelectionModel().getBlockSelectionStarts(),
editor.getSelectionModel().getBlockSelectionEnds());
// If the last left/right motion was the $ command, simulate each line being selected to end-of-line
final CommandState.SubMode subMode = CommandState.getInstance(editor).getSubMode();
if (subMode == CommandState.SubMode.VISUAL_BLOCK && EditorData.getLastColumn(editor) >= MotionGroup.LAST_COLUMN) {
final int[] starts = res.getStartOffsets();
if (subMode == CommandState.SubMode.VISUAL_BLOCK) {
final int[] ends = res.getEndOffsets();
for (int i = 0; i < starts.length; i++) {
if (ends[i] > starts[i]) {
ends[i] = EditorHelper.getLineEndForOffset(editor, starts[i]);
// If the last left/right motion was the $ command, simulate each line being selected to end-of-line
if (EditorData.getLastColumn(editor) >= MotionGroup.LAST_COLUMN) {
final int[] starts = res.getStartOffsets();
for (int i = 0; i < starts.length; i++) {
if (ends[i] > starts[i]) {
ends[i] = EditorHelper.getLineEndForOffset(editor, starts[i]);
}
}
}
else {
for (int i = 0; i < ends.length; ++i) {
ends[i] = EditorHelper.normalizeOffset(editor, ends[i] + 1, false);
}
}
return new TextRange(starts, ends);
}
return res;
}

View File

@ -241,9 +241,21 @@ public class ChangeActionTest extends VimTestCase {
"bar\n" +
"baz\n" +
"quux\n",
"<caret>oo\n" +
"ar\n" +
"az\n" +
"<caret>o\n" +
"r\n" +
"z\n" +
"quux\n");
}
public void testDeleteCharVisualBlock() {
doTest(parseKeys("<C-V>", "jjl", "x"),
"<caret>foo\n" +
"bar\n" +
"baz\n" +
"quux\n",
"<caret>o\n" +
"r\n" +
"z\n" +
"quux\n");
}

View File

@ -100,8 +100,8 @@ public class CopyActionTest extends VimTestCase {
//
// The problem is that the selection range should be 1-char wide when entering the visual block mode
myFixture.checkResult("* *one\n" +
"* *two\n");
myFixture.checkResult("* * one\n" +
"* * two\n");
assertSelection(null);
assertOffset(2);
}