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

'J' shouldn't add whitespace if there is trailing whitespace

This commit is contained in:
Tuomas Tynkkynen 2014-11-16 23:08:47 +02:00
parent e8de9f915c
commit 3bdfaa02e1
3 changed files with 64 additions and 1 deletions
src/com/maddyhome/idea/vim/group
test/org/jetbrains/plugins/ideavim/action

View File

@ -788,6 +788,9 @@ public class ChangeGroup {
MotionGroup.moveCaret(editor, VimPlugin.getMotion().moveCaretToLineEnd(editor, startLine, true));
for (int i = 1; i < count; i++) {
int start = VimPlugin.getMotion().moveCaretToLineEnd(editor);
int trailingWhitespaceStart = VimPlugin.getMotion().moveCaretToLineEndSkipLeading(editor);
boolean hasTrailingWhitespace = start != trailingWhitespaceStart + 1;
MotionGroup.moveCaret(editor, start);
int offset;
if (spaces) {
@ -797,7 +800,7 @@ public class ChangeGroup {
offset = VimPlugin.getMotion().moveCaretToLineStartOffset(editor);
}
deleteText(editor, new TextRange(editor.getCaretModel().getOffset(), offset), null);
if (spaces) {
if (spaces && !hasTrailingWhitespace) {
insertText(editor, start, " ");
MotionGroup.moveCaret(editor, VimPlugin.getMotion().moveCaretHorizontal(editor, -1, false));
}

View File

@ -1036,6 +1036,11 @@ public class MotionGroup {
return EditorHelper.getLeadingCharacterOffset(editor, line);
}
public int moveCaretToLineEndSkipLeading(@NotNull Editor editor) {
int logicalLine = editor.getCaretModel().getLogicalPosition().line;
return moveCaretToLineEndSkipLeading(editor, logicalLine);
}
public int moveCaretToLineEndSkipLeading(@NotNull Editor editor, int line) {
int start = EditorHelper.getLineStartOffset(editor, line);
int end = EditorHelper.getLineEndOffset(editor, line, true);

View File

@ -273,6 +273,61 @@ public class ChangeActionTest extends VimTestCase {
"quux\n");
}
public void testDeleteJoinLinesSpaces() {
doTest(parseKeys("3J"),
" a<caret> 1\n" +
" b 2\n" +
" c 3\n" +
"quux\n",
" a 1 b 2 c 3\n" +
"quux\n");
}
public void testDeleteJoinLines() {
doTest(parseKeys("3gJ"),
" a<caret> 1\n" +
" b 2\n" +
" c 3\n" +
"quux\n",
" a 1 b 2 c 3\n" +
"quux\n");
}
public void testDeleteJoinLinesWithTrailingSpaceThenEmptyLine() {
doTest(parseKeys("3J"),
"foo \n" +
"\n" +
"bar",
"foo bar");
}
public void testDeleteJoinLinesWithTwoTrailingSpaces() {
doTest(parseKeys("J"),
"foo \n" +
"bar",
"foo bar");
}
public void testDeleteJoinVisualLinesSpaces() {
doTest(parseKeys("v2jJ"),
" a<caret> 1\n" +
" b 2\n" +
" c 3\n" +
"quux\n",
" a 1 b 2 c 3\n" +
"quux\n");
}
public void testDeleteJoinVisualLines() {
doTest(parseKeys("v2jgJ"),
" a<caret> 1\n" +
" b 2\n" +
" c 3\n" +
"quux\n",
" a 1 b 2 c 3\n" +
"quux\n");
}
// VIM-511 |.|
public void testRepeatWithBackspaces() {
doTest(parseKeys("ce", "foo", "<BS><BS><BS>", "foo", "<Esc>", "j0", "."),