Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial implementation of virtualedit config #242

Merged
merged 7 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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