1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-03-01 13:46:02 +01:00

VIM-262 Support for paste from register in command mode

This commit is contained in:
Andrey Vlasovskikh 2012-12-25 22:30:52 +04:00
parent 7b6163c968
commit ed5358a6d6
6 changed files with 72 additions and 17 deletions
index.txt
src/com/maddyhome/idea/vim
test/org/jetbrains/plugins/ideavim/action

View File

@ -26,6 +26,8 @@ tag char action in Insert mode ~
enter digraph
|i_CTRL-O| CTRL-O execute a single command and return to insert
mode
|i_CTRL-R| CTRL-R {0-9a-z"%#*:=}
insert the contents of a register
|i_CTRL-W| CTRL-W delete word before the cursor
==============================================================================
@ -159,6 +161,20 @@ tag command note action in Visual mode ~
------------------------------------------------------------------------------
|v_y| y yank the highlighted area
==============================================================================
4. Command-line editing *ex-edit-index*
Get to the command-line with the ':', '!', '/' or '?' commands.
Normal characters are inserted at the current cursor position.
"Completion" below refers to context-sensitive completion. It will complete
file names, tags, commands etc. as appropriate.
tag command action in Command-line editing mode ~
------------------------------------------------------------------------------
|c_CTRL-R| CTRL-R {0-9a-z"%#*:= CTRL-F CTRL-P CTRL-W CTRL-A}
insert the contents of a register or object
under the cursor as if typed
==============================================================================
5. EX commands *ex-cmd-index*

View File

@ -276,14 +276,8 @@ public class RegisterGroup extends AbstractActionGroup {
}
}
public void addKeys(char register, @NotNull List<KeyStroke> keys) {
final Register r = getRegister(register);
if (r != null) {
r.addKeys(keys);
}
else {
registers.put(register, new Register(register, SelectionType.CHARACTER_WISE, keys));
}
public void setKeys(char register, @NotNull List<KeyStroke> keys) {
registers.put(register, new Register(register, SelectionType.CHARACTER_WISE, keys));
}
public void finishRecording(Editor editor) {

View File

@ -21,6 +21,7 @@ package com.maddyhome.idea.vim.ui;
import com.intellij.openapi.diagnostic.Logger;
import com.maddyhome.idea.vim.KeyHandler;
import com.maddyhome.idea.vim.common.Register;
import com.maddyhome.idea.vim.group.CommandGroups;
import com.maddyhome.idea.vim.helper.DigraphSequence;
import com.maddyhome.idea.vim.helper.SearchHelper;
@ -131,6 +132,7 @@ public class ExEditorKit extends DefaultEditorKit {
new ExEditorKit.HistoryDownFilterAction(),
new ExEditorKit.ToggleInsertReplaceAction(),
new ExEditorKit.StartDigraphAction(),
new InsertRegisterAction(),
};
public static class DefaultExKeyHandler extends DefaultKeyTypedAction {
@ -203,18 +205,46 @@ public class ExEditorKit extends DefaultEditorKit {
}
}
// TODO - how do I get the argument (register name)?
public static class InsertRegisterAction extends TextAction {
private static enum State {
SKIP_CTRL_R,
WAIT_REGISTER,
}
private State state = State.SKIP_CTRL_R;
public InsertRegisterAction() {
super(InsertRegister);
}
/**
* Invoked when an action occurs.
*/
public void actionPerformed(ActionEvent e) {
ExTextField target = (ExTextField)getTextComponent(e);
target.saveLastEntry();
final ExTextField target = (ExTextField)getTextComponent(e);
final KeyStroke key = convert(e);
if (key != null) {
switch (state) {
case SKIP_CTRL_R:
state = State.WAIT_REGISTER;
target.setCurrentAction(this);
break;
case WAIT_REGISTER:
state = State.SKIP_CTRL_R;
target.setCurrentAction(null);
final char c = key.getKeyChar();
if (c != KeyEvent.CHAR_UNDEFINED) {
final Register register = CommandGroups.getInstance().getRegister().getRegister(c);
if (register != null) {
final String oldText = target.getText();
final String text = register.getText();
if (oldText != null && text != null) {
target.setText(oldText + text);
}
}
}
else {
target.handleKey(key);
}
}
}
}
}
@ -409,7 +439,7 @@ public class ExEditorKit extends DefaultEditorKit {
DigraphSequence.DigraphResult res = digraphSequence.processKey(key, target.getEditor(), target.getContext());
switch (res.getResult()) {
case DigraphSequence.DigraphResult.RES_BAD:
target.escape();
target.setCurrentAction(null);
target.handleKey(key);
break;
case DigraphSequence.DigraphResult.RES_DONE:

View File

@ -35,7 +35,6 @@ public class ExKeyBindings {
}
// TODO - add the following keys:
// Ctrl-R {register}
// Ctrl-\ Ctrl-N - abort
static final KeyBinding[] bindings = new KeyBinding[]{
new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), ExEditorKit.EscapeChar),
@ -86,5 +85,7 @@ public class ExKeyBindings {
new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.META_MASK), ExEditorKit.pasteAction),
new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, KeyEvent.SHIFT_MASK), ExEditorKit.pasteAction),
new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_R, KeyEvent.CTRL_MASK), ExEditorKit.InsertRegister),
};
}

View File

@ -210,7 +210,7 @@ public class ChangeActionTest extends VimTestCase {
// VIM-262 |i_CTRL-R|
public void testInsertFromRegister() {
CommandGroups.getInstance().getRegister().addKeys('a', stringToKeys("World"));
CommandGroups.getInstance().getRegister().setKeys('a', stringToKeys("World"));
final List<KeyStroke> keys = stringToKeys("A, ");
keys.add(KeyStroke.getKeyStroke("control R"));
keys.addAll(stringToKeys("a!"));

View File

@ -2,6 +2,7 @@ package org.jetbrains.plugins.ideavim.action;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.VisualPosition;
import com.maddyhome.idea.vim.group.CommandGroups;
import org.jetbrains.plugins.ideavim.VimTestCase;
import javax.swing.*;
@ -549,4 +550,17 @@ public class MotionActionTest extends VimTestCase {
"four five\n");
assertOffset(14);
}
// VIM-262 |c_CTRL-R|
public void testSearchFromRegister() {
CommandGroups.getInstance().getRegister().setKeys('a', stringToKeys("two"));
final List<KeyStroke> keys = stringToKeys("/");
keys.add(KeyStroke.getKeyStroke("control R"));
keys.addAll(stringToKeys("a"));
keys.add(KeyStroke.getKeyStroke("ENTER"));
typeTextInFile(keys, "<caret>one\n" +
"two\n" +
"three\n");
assertOffset(4);
}
}