Skip to content

Commit

Permalink
Merge pull request #242 from i-e-b/master
Browse files Browse the repository at this point in the history
Partial implementation of virtualedit config
  • Loading branch information
AlexPl292 authored Sep 17, 2020
2 parents 3096c2e + 76587d6 commit 5bf2818
Show file tree
Hide file tree
Showing 22 changed files with 533 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.MotionType
import com.maddyhome.idea.vim.handler.NonShiftedSpecialKeyHandler
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
import com.maddyhome.idea.vim.helper.commandState
import com.maddyhome.idea.vim.helper.isEndAllowed
import java.awt.event.KeyEvent
import javax.swing.KeyStroke

Expand All @@ -39,7 +41,8 @@ class MotionArrowRightAction : NonShiftedSpecialKeyHandler(), ComplicatedKeysAct
)

override fun offset(editor: Editor, caret: Caret, context: DataContext, count: Int, rawCount: Int, argument: Argument?): Int {
return VimPlugin.getMotion().moveCaretHorizontal(editor, caret, count, false)
val allowPastEnd = editor.commandState.mode.isEndAllowed
return VimPlugin.getMotion().moveCaretHorizontal(editor, caret, count, allowPastEnd)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class MotionArrowDownAction : NonShiftedSpecialKeyHandler(), ComplicatedKeysActi
}

override fun preOffsetComputation(editor: Editor, caret: Caret, context: DataContext, cmd: Command): Boolean {
col = EditorHelper.prepareLastColumn(editor, caret)
col = EditorHelper.prepareLastColumn(caret)
return true
}

override fun postMove(editor: Editor, caret: Caret, context: DataContext, cmd: Command) {
EditorHelper.updateLastColumn(editor, caret, col)
EditorHelper.updateLastColumn(caret, col)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class MotionArrowUpAction : NonShiftedSpecialKeyHandler(), ComplicatedKeysAction
}

override fun preOffsetComputation(editor: Editor, caret: Caret, context: DataContext, cmd: Command): Boolean {
col = EditorHelper.prepareLastColumn(editor, caret)
col = EditorHelper.prepareLastColumn(caret)
return true
}

override fun postMove(editor: Editor, caret: Caret, context: DataContext, cmd: Command) {
EditorHelper.updateLastColumn(editor, caret, col)
EditorHelper.updateLastColumn(caret, col)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ sealed class MotionDownBase : MotionActionHandler.ForEachCaret() {
private var col: Int = 0

override fun preOffsetComputation(editor: Editor, caret: Caret, context: DataContext, cmd: Command): Boolean {
col = EditorHelper.prepareLastColumn(editor, caret)
col = EditorHelper.prepareLastColumn(caret)
return true
}

override fun postMove(editor: Editor, caret: Caret, context: DataContext, cmd: Command) {
EditorHelper.updateLastColumn(editor, caret, col)
EditorHelper.updateLastColumn(caret, col)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.group.MotionGroup
import com.maddyhome.idea.vim.handler.ShiftedArrowKeyHandler
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.vimForEachCaret
import com.maddyhome.idea.vim.helper.*

/**
* @author Alex Plate
Expand All @@ -38,10 +37,10 @@ class MotionShiftDownAction : ShiftedArrowKeyHandler() {
override fun motionWithKeyModel(editor: Editor, context: DataContext, cmd: Command) {
editor.vimForEachCaret { caret ->
val vertical = VimPlugin.getMotion().moveCaretVertical(editor, caret, cmd.count)
val col = EditorHelper.prepareLastColumn(editor, caret)
val col = EditorHelper.prepareLastColumn(caret)
MotionGroup.moveCaret(editor, caret, vertical)

EditorHelper.updateLastColumn(editor, caret, col)
EditorHelper.updateLastColumn(caret, col)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.group.MotionGroup
import com.maddyhome.idea.vim.handler.ShiftedArrowKeyHandler
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.vimForEachCaret
import com.maddyhome.idea.vim.helper.*

/**
* @author Alex Plate
Expand All @@ -38,10 +37,10 @@ class MotionShiftUpAction : ShiftedArrowKeyHandler() {
override fun motionWithKeyModel(editor: Editor, context: DataContext, cmd: Command) {
editor.vimForEachCaret { caret ->
val vertical = VimPlugin.getMotion().moveCaretVertical(editor, caret, -cmd.count)
val col = EditorHelper.prepareLastColumn(editor, caret)
val col = EditorHelper.prepareLastColumn(caret)
MotionGroup.moveCaret(editor, caret, vertical)

EditorHelper.updateLastColumn(editor, caret, col)
EditorHelper.updateLastColumn(caret, col)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ sealed class MotionUpBase : MotionActionHandler.ForEachCaret() {
private var col: Int = 0

override fun preOffsetComputation(editor: Editor, caret: Caret, context: DataContext, cmd: Command): Boolean {
col = EditorHelper.prepareLastColumn(editor, caret)
col = EditorHelper.prepareLastColumn(caret)
return true
}

override fun postMove(editor: Editor, caret: Caret, context: DataContext, cmd: Command) {
EditorHelper.updateLastColumn(editor, caret, col)
EditorHelper.updateLastColumn(caret, col)
}
}

Expand Down
7 changes: 2 additions & 5 deletions src/com/maddyhome/idea/vim/command/CommandState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.diagnostic.debug
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.helper.DigraphResult
import com.maddyhome.idea.vim.helper.DigraphSequence
import com.maddyhome.idea.vim.helper.noneOfEnum
import com.maddyhome.idea.vim.helper.vimCommandState
import com.maddyhome.idea.vim.action.motion.updown.*
import com.maddyhome.idea.vim.helper.*
import com.maddyhome.idea.vim.key.CommandPartNode
import com.maddyhome.idea.vim.option.OptionsManager.showmode
import org.jetbrains.annotations.ApiStatus
Expand Down
19 changes: 15 additions & 4 deletions src/com/maddyhome/idea/vim/group/ChangeGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -766,15 +766,26 @@ public void beforeProcessKey(final @NotNull Editor editor,
* @return true if able to delete the text, false if not
*/
public boolean deleteEndOfLine(@NotNull Editor editor, @NotNull Caret caret, int count) {
int initialOffset = caret.getOffset();
int offset = VimPlugin.getMotion().moveCaretToLineEndOffset(editor, caret, count - 1, true);

int startOffset = initialOffset;
if (offset == initialOffset) startOffset--; // handle delete from virtual space

if (offset != -1) {
final TextRange rangeToDelete = new TextRange(caret.getOffset(), offset);
final TextRange rangeToDelete = new TextRange(startOffset, offset);
editor.getCaretModel().getAllCarets().stream().filter(c -> c != caret && rangeToDelete.contains(c.getOffset()))
.forEach(c -> editor.getCaretModel().removeCaret(c));
boolean res = deleteText(editor, rangeToDelete, SelectionType.CHARACTER_WISE);
int pos = VimPlugin.getMotion().moveCaretHorizontal(editor, caret, -1, false);
if (pos != -1) {
MotionGroup.moveCaret(editor, caret, pos);

if (CommandStateHelper.getUsesVirtualSpace()) {
MotionGroup.moveCaret(editor, caret, startOffset);
}
else {
int pos = VimPlugin.getMotion().moveCaretHorizontal(editor, caret, -1, false);
if (pos != -1) {
MotionGroup.moveCaret(editor, caret, pos);
}
}

return res;
Expand Down
Loading

0 comments on commit 5bf2818

Please sign in to comment.