1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-03-07 12:32:52 +01:00

VIM-1633 - fix block selection

This commit is contained in:
romain.gautier@nimamoh.net 2019-04-13 03:35:08 +02:00
parent 2d4eed726f
commit c0d72d25f8
2 changed files with 122 additions and 5 deletions
src/com/maddyhome/idea/vim/helper
test/org/jetbrains/plugins/ideavim/action

View File

@ -113,15 +113,25 @@ public class SearchHelper {
boolean isOuter) {
CharSequence chars = editor.getDocument().getCharsSequence();
int pos = caret.getOffset();
int start = caret.getSelectionStart();
int end = caret.getSelectionEnd();
if (start != end) {
pos = Math.min(start, end);
}
int start = Math.min(caret.getSelectionStart(), caret.getSelectionEnd());
int end = Math.max(caret.getSelectionStart(), caret.getSelectionEnd());
int loc = blockChars.indexOf(type);
char close = blockChars.charAt(loc + 1);
if (!isOuter
&& (start - 1) >= 0 && type == chars.charAt(start - 1)
&& end < chars.length() && close == chars.charAt(end)) {
start = start - 1;
pos = start;
}
boolean rangeSelection = end - start > 1;
if (rangeSelection && start == 0)
return null;
if (rangeSelection)
pos = Math.max(0, start - 1);
boolean initialPosIsInString = checkInString(chars, pos, true);
int bstart = -1;

View File

@ -777,6 +777,113 @@ public class MotionActionTest extends VimTestCase {
myFixture.checkResult("abcde</tag>fg<tag>hi");
}
// VIM-1633 |v_a)|
public void testNestedBlockSelection() {
configureByText("(<caret>a)");
typeText(parseKeys("va)"));
assertSelection("(a)");
configureByText("((<caret>a))");
typeText(parseKeys("va)"));
assertSelection("(a)");
configureByText("(outer\n" +
" <caret>(inner))");
typeText(parseKeys("va)"));
assertSelection("(inner)");
configureByText("(outer\n" +
" (inner<caret>))");
typeText(parseKeys("va)"));
assertSelection("(inner)");
configureByText("(outer\n" +
" <caret> (inner))");
typeText(parseKeys("va)"));
assertSelection("(outer\n" +
" (inner))");
configureByText("(outer\n" +
" <caret>(inner))");
typeText(parseKeys("va)a)"));
assertSelection("(outer\n" +
" (inner))");
configureByText("(outer\n" +
" <caret>(inner))");
typeText(parseKeys("v2a)"));
assertSelection("(outer\n" +
" (inner))");
configureByText("(outer\n" +
" <caret>(inner))");
typeText(parseKeys("vlla)"));
assertSelection("(outer\n" +
" (inner))");
configureByText("(outer\n" +
" (inner<caret>))");
typeText(parseKeys("vlla)"));
assertSelection("(inner)");
}
// VIM-1633 |v_i)|
public void testNestedInBlockSelection() {
configureByText("(<caret>a)");
typeText(parseKeys("vi)"));
assertSelection("a");
configureByText("((<caret>a))");
typeText(parseKeys("vi)"));
assertSelection("(a)");
configureByText("(outer\n" +
" <caret>(inner))");
typeText(parseKeys("vi)"));
assertSelection("inner");
configureByText("(outer\n" +
" (inner<caret>))");
typeText(parseKeys("vi)"));
assertSelection("inner");
configureByText("(outer\n" +
" <caret> (inner))");
typeText(parseKeys("vi)"));
assertSelection("outer\n" +
" (inner)");
configureByText("(outer\n" +
" <caret>(inner))");
typeText(parseKeys("vi)i)"));
assertSelection("outer\n" +
" (inner)");
configureByText("(outer\n" +
" <caret>(inner))");
typeText(parseKeys("v2i)"));
assertSelection("outer\n" +
" (inner)");
configureByText("(outer\n" +
" <caret>(inner))");
typeText(parseKeys("vlli)"));
assertSelection("outer\n" +
" (inner)");
configureByText("(outer\n" +
" (inner<caret>))");
typeText(parseKeys("vlli)"));
assertSelection("inner");
configureByText("(outer\n" +
" (<caret>inner))");
typeText(parseKeys("vllli)"));
assertSelection("inner");
}
// |v_it|
public void testFileStartsWithSlash() {
configureByText("/*hello\n" +