1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-08-17 16:31:45 +02:00

Compare commits

...

53 Commits

Author SHA1 Message Date
Andrey Vlasovskikh
e3f57fd647 Updated changelog 2012-11-14 17:50:01 +04:00
Andrey Vlasovskikh
e074105bde VIM-112 Delete a single previous word with <C-W> in insert mode, not all inserted words 2012-11-14 17:08:32 +04:00
Andrey Vlasovskikh
7a8bdfc4fc VIM-321 Updated test number and help index for 'd' and 'count' 2012-11-14 16:05:04 +04:00
Andrey Vlasovskikh
d765eb74ef VIM-312 Fixed IOOBE in delete empty range 2012-11-13 22:44:54 +04:00
Andrey Vlasovskikh
ac654d70fa VIM-318 Fixed executing editor commands for editors not bound to a project 2012-11-13 22:44:44 +04:00
Andrey Vlasovskikh
ecd0e771a5 Updated changelog 2012-11-12 18:47:24 +04:00
Andrey Vlasovskikh
6eb15ecb96 Fixed command handling when motion expected, but another type of argument found 2012-11-10 03:55:10 +04:00
Andrey Vlasovskikh
fbb23714a7 Extracted argument type as enum 2012-11-10 02:10:21 +04:00
Andrey Vlasovskikh
b6e7533262 Index of supported commands covered with tests 2012-11-09 23:17:50 +04:00
Andrey Vlasovskikh
2dba6f91bc Added tmp/ to .gitignore 2012-11-09 23:14:27 +04:00
Andrey Vlasovskikh
bb0fb6e787 Extracted editor sub-mode and selection mode as enums 2012-11-09 20:30:23 +04:00
Andrey Vlasovskikh
0e91f52cbc Reset key handler before each test 2012-11-09 20:23:35 +04:00
Andrey Vlasovskikh
ef67ecc898 VIM-311 Test for single command sub-mode of insert mode 2012-11-08 19:17:20 +04:00
Andrey Vlasovskikh
c81b668f82 Extracted editor mode as enum 2012-11-07 16:48:05 +04:00
Andrey Vlasovskikh
a8cc087a55 Extracted command type as enum 2012-11-07 16:07:58 +04:00
Andrey Vlasovskikh
02e349802c Cleaner toString() methods for commands and nodes 2012-11-07 14:27:30 +04:00
Andrey Vlasovskikh
2ddaa26b8f EA-33193 Fixed access to context data from different Swing events
In order to set marks and jump locations we don't require a data context. We always can find the marked file via the current editor.
2012-11-02 20:01:33 +04:00
Andrey Vlasovskikh
c695e98787 Paths relative to the Git root in .gitignore 2012-11-02 19:56:21 +04:00
Andrey Vlasovskikh
9e66424164 Unzip only the current IntelliJ archive 2012-11-01 19:38:25 +04:00
Andrey Vlasovskikh
4c5ccbd166 Added JRE jars to the build classpath 2012-11-01 18:07:08 +04:00
Andrey Vlasovskikh
f4ae8017ce Added .idea to .gitignore 2012-11-01 02:28:39 +04:00
Andrey Vlasovskikh
19ec6f3a10 No Unicode chars in tests for build server environment 2012-10-31 20:49:23 +04:00
Andrey Vlasovskikh
6248558217 Define 'javac2' task after creating dirs mentioned in its <classpath> 2012-10-31 20:26:43 +04:00
Andrey Vlasovskikh
6afb83084c Default build number for local builds 2012-10-31 20:13:34 +04:00
Andrey Vlasovskikh
85ebfc10b1 Added .gitignore for ignoring build results 2012-10-31 20:13:16 +04:00
Andrey Vlasovskikh
800139eb85 ant target for running unit tests 2012-10-31 20:12:12 +04:00
Andrey Vlasovskikh
f4f04d5a08 Removed test that depends on search history 2012-10-31 19:05:19 +04:00
Andrey Vlasovskikh
75138e20fd Don't show keymap configuration dialog in unit test mode 2012-10-31 18:52:38 +04:00
Andrey Vlasovskikh
9daf10cf22 Fixed compilation of tests for IntelliJ 11.x 2012-10-31 18:51:32 +04:00
Andrey Vlasovskikh
0d14a46d08 VIM-289 Fixed regexp substitute when the substitution contained newlines 2012-10-29 19:41:54 +04:00
Andrey Vlasovskikh
0a079be25c Vim compatible regexp substitutions for '\n' and '\r' 2012-10-29 18:42:29 +04:00
Andrey Vlasovskikh
b0b89e7248 Nullable annotations 2012-10-25 16:55:34 +04:00
Andrey Vlasovskikh
4b6cd9a11f VIM-185 Fixed NPE in KeyHandler.handleKey() 2012-10-25 15:29:29 +04:00
Andrey Vlasovskikh
46b53d682d Extracted several methods from KeyHandler.handleKey() 2012-10-25 14:51:58 +04:00
Andrey Vlasovskikh
047183e89c Replaced an odd loop for handling digraphs with recursion 2012-10-23 21:48:59 +04:00
Andrey Vlasovskikh
7d8b3acfde Extracted several methods from KeyHandler.handleKey() 2012-10-23 21:39:57 +04:00
Andrey Vlasovskikh
6e8d3abb17 Macro recording test 2012-10-23 20:16:06 +04:00
Andrey Vlasovskikh
c502c4a083 Pull typeTextInFile() up to VimTestCase 2012-10-17 16:54:57 +04:00
Andrey Vlasovskikh
87026bda3c Reuse StringHelper.stringToKeys() 2012-10-17 16:49:21 +04:00
Andrey Vlasovskikh
03bbc2e1f2 Immutable isRecording inside handleKey() 2012-10-17 15:49:35 +04:00
Andrey Vlasovskikh
0872a0c3b5 More motion tests 2012-10-15 20:21:46 +04:00
Andrey Vlasovskikh
7f4dea6846 Enum key handler state instead of integer constants 2012-10-15 17:07:53 +04:00
Andrey Vlasovskikh
dc1b393679 Cleanup and annotations 2012-10-12 19:58:17 +04:00
Andrey Vlasovskikh
b26d68984f VIM-226 Added tests for the bug fixed together with VIM-146 2012-10-12 19:37:02 +04:00
Andrey Vlasovskikh
a58203f0b2 VIM-146 Fixed handling of '$' in search and substitute commands
'$' matches an empty range at the end of a line, so in multiple matches mode the search continued forever.
2012-10-12 19:03:55 +04:00
Andrey Vlasovskikh
694bb9eefa Register action for 'iW' selection 2012-10-10 17:14:16 +04:00
Andrey Vlasovskikh
5429774744 Cleanup and nullable annotations 2012-10-10 17:08:15 +04:00
Andrey Vlasovskikh
d4b202a7f4 VIM-198 Fixed indexing bug in offset normalization
Normalization was fixed for files that contain a newline at the end and when the normalized offset is allowed to be at the end of a line.
2012-10-10 16:53:00 +04:00
Andrey Vlasovskikh
3a5b8dbf0f Moved toKeyStrokes() to VimTestCase 2012-10-10 16:46:09 +04:00
Andrey Vlasovskikh
228f0a3f31 Nullable annotations 2012-10-09 21:41:36 +04:00
Andrey Vlasovskikh
3d18c08fd4 VIM-276 T and F motions are exclusive, not inclusive 2012-10-09 21:22:00 +04:00
Andrey Vlasovskikh
df4ac6d642 Base class for action tests 2012-10-09 21:15:51 +04:00
Andrey Vlasovskikh
e3abbf68dc Moved SearchHelperTest into a separate test directory 2012-10-09 21:13:48 +04:00
152 changed files with 2535 additions and 1502 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
/.idea/
/idea/
/out/
/tmp/

View File

@@ -1,6 +1,52 @@
History of changes for IdeaVim for IntellIJ platform version @PLATFORM_VERSION@
The Changelog
=============
@VERSION@ from 0.8.4
History of changes in IdeaVim for the IntelliJ platform.
0.23.115, 2012-11-14
--------------------
A bugfix release.
* VIM-318 Fixed executing editor commands for editors not bound to a project
* VIM-321 Fixed IOOBE in delete empty range
* VIM-112 Delete a single previous word with <C-W> in insert mode, not all inserted words
0.23.111, 2012-11-12
--------------------
A bugfix release.
* Register action for 'iW' selection
* Vim compatible regexp substitutions for '\n' and '\r'
* Index of supported commands covered with tests
* VIM-276 T and F motions are exclusive, not inclusive
* VIM-289 Fixed regexp substitute when the substitution contained newlines
* VIM-185 Fixed NPE in KeyHandler.handleKey()
* VIM-226 Added tests for the bug fixed together with VIM-146
* VIM-146 Fixed handling of '$' in search and substitute commands
* VIM-198 Fixed indexing bug in offset normalization
* VIM-311 Test for single command sub-mode of insert mode
* EA-33193 Fixed access to context data from different Swing events
* Fixed command handling when motion expected, but another type of argument
found
0.23.93, 2012-03-21
-------------------
A bugfix release. Vim.xml was fixed to use Command+C, Command+V on Mac OS.
Unfortunately you need to update Vim.xml manually this time.
...
Previous Releases
-----------------
... from 0.8.4
Bug Fixes
- The Escape key is passed up to IDEA if not used by VIM first. This fix solves
minor issues such as not being able to clear highlighted text using the

View File

@@ -1,3 +1,4 @@
version-id:0.23
platform-version:110.0
idea.download.url=http://download.jetbrains.com/idea/ideaIU-11.zip
build.number=x

View File

@@ -22,17 +22,20 @@
<property name="idea" value="${basedir}/idea"/>
<property name="src" value="${basedir}/src"/>
<property name="resources" value="${basedir}/resources"/>
<property name="test" value="${basedir}/test"/>
<property name="keymap" value="${basedir}/keymap"/>
<property name="idea.home" value="${idea}/unzip"/>
<property environment="env"/>
<property name="tools.jar" value="${env.JAVA_HOME}/lib/tools.jar"/>
<property name="version" value="${version-id}.${build.number}"/>
<property name="filename" value="ideavim-${version}"/>
<!--Output-->
<property name="out" value="${basedir}"/>
<property name="out" value="${basedir}/out"/>
<property name="classes" value="${out}/classes"/>
<property name="build" value="${out}/build"/>
<property name="dist" value="${out}/dist"/>
<property name="test-reports" value="${out}/test-reports"/>
<!-- Define task -->
<path id="ant-contrib">
@@ -44,27 +47,31 @@
<fileset dir="${idea.home}/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="${java.home}/lib">
<include name="*.jar"/>
</fileset>
<pathelement path="${classes}"/>
</path>
<path id="test.classpath">
<path refid="build.classpath"/>
<pathelement path="${tools.jar}"/>
</path>
<!-- Clean all the generated stuff -->
<target name="clean" description="Removes all generated files">
<delete dir="${build}"/>
<delete dir="${classes}"/>
<delete dir="${dist}"/>
<delete dir="${out}"/>
</target>
<!-- Compile all the sources to the ${classes} folder -->
<target name="compile">
<mkdir dir="${classes}"/>
<!-- The task requires the following libraries from IntelliJ IDEA distribution: -->
<!-- javac2.jar; jdom.jar; asm.jar; asm-commons.jar -->
<taskdef name="javac2" classname="com.intellij.ant.Javac2">
<classpath refid="build.classpath"/>
</taskdef>
<javac2 destdir="${classes}"
debug="on"
fork="true">
<!-- The task requires the following libraries from IntelliJ IDEA distribution: -->
<!-- javac2.jar; jdom.jar; asm.jar; asm-commons.jar -->
<javac2 destdir="${classes}" debug="on" fork="true" includeantruntime="false">
<classpath refid="build.classpath"/>
<src path="${src}"/>
<include name="com/maddyhome/idea/**"/>
@@ -162,19 +169,19 @@
<target name="build" depends="unzip, clean, compile, jar, help" description="Compiles all source code and created plugin jar file"/>
<!-- Donwload IntelliJ IDEA distribution -->
<target name="download" description="Downloads IntellIJ IDEA artifacts">
<delete dir="${idea}"/>
<!-- Download IntelliJ IDEA distribution -->
<target name="download" description="Downloads IntelliJ IDEA artifacts">
<mkdir dir="${idea}"/>
<get src="${idea.download.url}" dest="${idea}"/>
<get src="${idea.download.url}" dest="${idea}" skipexisting="true"/>
</target>
<!-- Unpack idea-*.zip file for ideavim compilation -->
<target name="unzip" depends="download" description="Unzip downloaded artifacts and set up idea.home">
<delete dir="${idea}/unzip"/>
<mkdir dir="${idea}/unzip"/>
<basename property="idea.filename" file="${idea.download.url}"/>
<unzip dest="${idea}/unzip">
<fileset dir="${idea}" includes="idea*.zip"/>
<fileset dir="${idea}" includes="${idea.filename}"/>
</unzip>
</target>
@@ -214,4 +221,54 @@
<mkdir dir="${dist}"/>
<tar basedir="." destfile="${dist}/${filename}-src.tar.gz" excludes=".git/**,.idea/**,idea/**,*.iws,*.iml" compression="gzip"/>
</target>
<target name="compile-tests" depends="compile">
<mkdir dir="${classes}"/>
<taskdef name="javac2" classname="com.intellij.ant.Javac2">
<classpath refid="build.classpath"/>
</taskdef>
<javac2 destdir="${classes}" debug="on" fork="true" includeantruntime="false">
<classpath refid="build.classpath"/>
<src path="${test}"/>
<include name="org/jetbrains/plugins/ideavim/**"/>
</javac2>
</target>
<target name="prepare-tests" depends="compile-tests">
<mkdir dir="${classes}/META-INF"/>
<copy file="resources/META-INF/plugin.xml" todir="${classes}/META-INF">
<filterset>
<filter token="VERSION" value="${version}"/>
<filter token="SINCE-VERSION" value="${platform-version}"/>
</filterset>
</copy>
<copy todir="${classes}">
<fileset dir="${resources}"/>
</copy>
<mkdir dir="${out}/IdeaVim"/>
<copy todir="${out}/IdeaVim">
<fileset dir="${keymap}" includes="**"/>
</copy>
</target>
<target name="test" depends="unzip, clean, prepare-tests">
<mkdir dir="${test-reports}"/>
<junit fork="true" logfailedtests="false" printsummary="true">
<classpath refid="test.classpath"/>
<jvmarg value="-Xmx256M"/>
<jvmarg value="-ea"/>
<jvmarg value="-Djava.awt.headless=true"/>
<jvmarg value="-Didea.plugins.path=${out}"/>
<jvmarg value="-Didea.load.plugins.id=IdeaVIM"/>
<formatter type="plain"/>
<batchtest todir="${test-reports}">
<fileset dir="${test}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
</target>
</project>

114
index.txt Normal file
View File

@@ -0,0 +1,114 @@
*index.txt*
IDEAVIM REFERENCE MANUAL based on Vim Reference Manual
*index*
This file contains a list of all commands for each mode, with a tag and a
short description. The lists are sorted on ASCII value.
Tip: When looking for certain functionality, use a search command. E.g.,
to look for deleting something, use: "/delete".
1. Insert mode |insert-index|
2. Normal mode |normal-index|
2.1. Text objects |objects|
3. Visual mode |visual-index|
5. EX commands |ex-cmd-index|
==============================================================================
1. Insert mode *insert-index*
tag char action in Insert mode ~
-----------------------------------------------------------------------
|i_CTRL-K| CTRL-K {char1} {char2}
enter digraph
|i_CTRL-O| CTRL-O execute a single command and return to insert
mode
|i_CTRL-W| CTRL-W delete word before the cursor
==============================================================================
2. Normal mode *normal-index*
CHAR any non-blank character
WORD a sequence of non-blank characters
N a number entered before the command
{motion} a cursor movement command
Nmove the text that is moved over with a {motion}
SECTION a section that possibly starts with '}' instead of '{'
note: 1 = cursor movement command; 2 = can be undone/redone
tag char note action in Normal mode ~
------------------------------------------------------------------------------
|quote| "{a-zA-Z0-9.%#:-"} use register {a-zA-Z0-9.%#:-"} for next
delete, yank or put (uppercase to append)
({.%#:} only work with put)
|/| /{pattern}<CR> 1 search forward for the Nth occurrence of
{pattern}
|count| 0 1 cursor to the first char of the line
|count| 1 prepend to command to give a count
|count| 2 "
|count| 3 "
|count| 4 "
|count| 5 "
|count| 6 "
|count| 7 "
|count| 8 "
|count| 9 "
|F| F{char} 1 cursor to the Nth occurrence of {char} to
the left
|P| ["x]P 2 put the text [from buffer x] before the
cursor N times
|T| T{char} 1 cursor till after Nth occurrence of {char}
to the left
|Y| ["x]Y yank N lines [into buffer x]; synonym for
"yy"
|c| ["x]c{motion} 2 delete Nmove text [into buffer x] and start
insert
|d| ["x]d{motion} 2 delete Nmove text [into buffer x]
|f| f{char} 1 cursor to Nth occurrence of {char} to the
right
|i| i 2 insert text before the cursor N times
|p| ["x]p 2 put the text [from register x] after the
cursor N times
|q| q{0-9a-zA-Z"} record typed characters into named register
{0-9a-zA-Z"} (uppercase to append)
|q| q (while recording) stops recording
|t| t{char} 1 cursor till before Nth occurrence of {char}
to the right
|y| ["x]y{motion} yank Nmove text [into buffer x]
|yy| ["x]yy yank N lines [into buffer x]
==============================================================================
2.1 Text objects *objects*
These can be used after an operator or in Visual mode to select an object.
tag command action in op-pending and Visual mode ~
------------------------------------------------------------------------------
|v_iW| iW "inner WORD"
|v_iw| iw "inner word"
==============================================================================
3. Visual mode *visual-index*
Most commands in Visual mode are the same as in Normal mode. The ones listed
here are those that are different.
tag command note action in Visual mode ~
------------------------------------------------------------------------------
|v_y| y yank the highlighted area
==============================================================================
5. EX commands *ex-cmd-index*
This is a brief but complete listing of all the ":" commands, without
mentioning any arguments. The optional part of the command name is inside [].
The commands are sorted on the non-optional part of their name.
tag command action ~
------------------------------------------------------------------------------
|:display| :di[splay] display registers
|:registers| :reg[isters] display the contents of registers
|:substitute| :s[ubstitute] find and replace text

View File

@@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.TypedActionHandler;
@@ -39,6 +40,8 @@ import com.maddyhome.idea.vim.helper.EditorHelper;
import com.maddyhome.idea.vim.helper.RunnableHelper;
import com.maddyhome.idea.vim.key.*;
import com.maddyhome.idea.vim.option.Options;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.event.KeyEvent;
@@ -56,11 +59,11 @@ public class KeyHandler {
*
* @return A reference to the singleton
*/
@NotNull
public static KeyHandler getInstance() {
if (instance == null) {
instance = new KeyHandler();
}
return instance;
}
@@ -83,7 +86,7 @@ public class KeyHandler {
/**
* Gets the original key handler
*
* @return The orginal key handler
* @return The original key handler
*/
public TypedActionHandler getOriginalHandler() {
return origHandler;
@@ -97,23 +100,121 @@ public class KeyHandler {
* @param key The keystroke typed by the user
* @param context The data context
*/
public void handleKey(Editor editor, KeyStroke key, DataContext context) {
public void handleKey(@NotNull Editor editor, @NotNull KeyStroke key, @NotNull DataContext context) {
VimPlugin.clearError();
// All the editor actions should be performed with top level editor!!!
// Be careful: all the EditorActionHandler implementation should correctly process InjectedEditors
editor = InjectedLanguageUtil.getTopLevelEditor(editor);
logger.debug("handleKey " + key);
CommandState editorState = CommandState.getInstance(editor);
boolean isRecording = editorState.isRecording();
final CommandState editorState = CommandState.getInstance(editor);
final boolean isRecording = editorState.isRecording();
boolean shouldRecord = true;
for (int loop = 0; loop < 2; loop++) {
// If this is a "regular" character keystroke, get the character
char chKey = key.getKeyChar() == KeyEvent.CHAR_UNDEFINED ? 0 : key.getKeyChar();
if ((editorState.getMode() == CommandState.MODE_COMMAND || mode == STATE_COMMAND) &&
(key.getKeyCode() == KeyEvent.VK_ESCAPE ||
(key.getKeyCode() == KeyEvent.VK_C && (key.getModifiers() & KeyEvent.CTRL_MASK) != 0) ||
(key.getKeyCode() == '[' && (key.getModifiers() & KeyEvent.CTRL_MASK) != 0))) {
if (mode != STATE_COMMAND && count == 0 && currentArg == Argument.NONE && currentCmd.size() == 0 &&
if (isEditorReset(key, editorState)) {
handleEditorReset(editor, key, context);
}
// At this point the user must be typing in a command. Most commands can be preceded by a number. Let's
// check if a number can be entered at this point, and if so, did the user send us a digit.
else if (isCommandCount(editorState, chKey)) {
// Update the count
count = count * 10 + (chKey - '0');
logger.debug("count now " + count);
}
// Pressing delete while entering a count "removes" the last digit entered
else if (isDeleteCommandCount(key, editorState)) {
// "Remove" the last digit sent to us
count /= 10;
logger.debug("count now " + count);
}
// If we got this far the user is entering a command or supplying an argument to an entered command.
// First let's check to see if we are at the point of expecting a single character argument to a command.
else if (currentArg == Argument.Type.CHARACTER) {
handleCharArgument(key, chKey);
}
// If we are this far, then the user must be entering a command or a non-single-character argument
// to an entered command. Let's figure out which it is
else {
// For debugging purposes we track the keys entered for this command
keys.add(key);
if (logger.isDebugEnabled()) {
logger.debug("keys now " + keys);
}
// Ask the key/action tree if this is an appropriate key at this point in the command and if so,
// return the node matching this keystroke
final Node node = editorState.getCurrentNode().getChild(key);
if (handleDigraph(editor, key, context, node)) {
return;
}
// If this is a branch node we have entered only part of a multi-key command
if (node instanceof BranchNode) {
handleBranchNode(editor, context, editorState, chKey, (BranchNode)node);
}
// If this is a command node the user has entered a valid key sequence of a known command
else if (node instanceof CommandNode) {
handleCommandNode(editor, context, (CommandNode)node);
}
// If this is an argument node then the last keystroke was not part of the current command but should
// be the first keystroke of the argument of the current command
else if (node instanceof ArgumentNode) {
shouldRecord = handleArgumentNode(editor, key, context, editorState, shouldRecord, (ArgumentNode)node);
}
else {
logger.debug("checking for digraph");
logger.debug("lastWasBS=" + lastWasBS);
logger.debug("lastChar=" + lastChar);
if (lastWasBS && lastChar != 0 && Options.getInstance().isSet("digraph")) {
char dig = CommandGroups.getInstance().getDigraph().getDigraph(lastChar, key.getKeyChar());
logger.debug("dig=" + dig);
key = KeyStroke.getKeyStroke(dig);
}
// If we are in insert/replace mode send this key in for processing
if (editorState.getMode() == CommandState.Mode.INSERT ||
editorState.getMode() == CommandState.Mode.REPLACE) {
if (!CommandGroups.getInstance().getChange().processKey(editor, context, key)) {
shouldRecord = false;
}
}
else if (editorState.getMappingMode() == KeyParser.MAPPING_CMD_LINE) {
if (!CommandGroups.getInstance().getProcess().processExKey(editor, key, true)) {
shouldRecord = false;
}
}
// If we get here then the user has entered an unrecognized series of keystrokes
else {
state = State.BAD_COMMAND;
}
lastChar = key.getKeyChar();
partialReset(editor);
}
}
// Do we have a fully entered command at this point? If so, lets execute it
if (state == State.READY) {
executeCommand(editor, key, context, editorState);
}
else if (state == State.BAD_COMMAND) {
VimPlugin.indicateError();
reset(editor);
}
// We had some sort of error so reset the handler and let the user know (beep)
else if (state == State.ERROR) {
VimPlugin.indicateError();
fullReset(editor);
}
else if (isRecording && shouldRecord) {
CommandGroups.getInstance().getRegister().addKeyStroke(key);
}
}
private void handleEditorReset(@NotNull Editor editor, @NotNull KeyStroke key, @NotNull DataContext context) {
if (state != State.COMMAND && count == 0 && currentArg == Argument.Type.NONE && currentCmd.size() == 0 &&
CommandGroups.getInstance().getRegister().getCurrentRegister() == RegisterGroup.REGISTER_DEFAULT) {
if (key.getKeyCode() == KeyEvent.VK_ESCAPE) {
KeyHandler.executeAction("VimEditorEscape", context);
@@ -124,29 +225,32 @@ public class KeyHandler {
reset(editor);
}
// At this point the user must be typing in a command. Most commands can be preceeded by a number. Let's
// check if a number can be entered at this point, and if so, did the user send us a digit.
else if ((editorState.getMode() == CommandState.MODE_COMMAND ||
editorState.getMode() == CommandState.MODE_VISUAL) &&
mode == STATE_NEW_COMMAND && currentArg != Argument.CHARACTER && currentArg != Argument.DIGRAPH &&
private boolean isDeleteCommandCount(@NotNull KeyStroke key, @NotNull CommandState editorState) {
return (editorState.getMode() == CommandState.Mode.COMMAND ||
editorState.getMode() == CommandState.Mode.VISUAL) &&
state == State.NEW_COMMAND && currentArg != Argument.Type.CHARACTER && currentArg !=
Argument.Type.DIGRAPH &&
key.getKeyCode() == KeyEvent.VK_DELETE && count != 0;
}
private boolean isCommandCount(@NotNull CommandState editorState, char chKey) {
return (editorState.getMode() == CommandState.Mode.COMMAND ||
editorState.getMode() == CommandState.Mode.VISUAL) &&
state == State.NEW_COMMAND && currentArg != Argument.Type.CHARACTER && currentArg !=
Argument.Type.DIGRAPH &&
Character.isDigit(chKey) &&
(count != 0 || chKey != '0')) {
// Update the count
count = count * 10 + (chKey - '0');
logger.debug("count now " + count);
(count != 0 || chKey != '0');
}
// Pressing delete while entering a count "removes" the last digit entered
else if ((editorState.getMode() == CommandState.MODE_COMMAND ||
editorState.getMode() == CommandState.MODE_VISUAL) &&
mode == STATE_NEW_COMMAND && currentArg != Argument.CHARACTER && currentArg != Argument.DIGRAPH &&
key.getKeyCode() == KeyEvent.VK_DELETE && count != 0) {
// "Remove" the last digit sent to us
count /= 10;
logger.debug("count now " + count);
private boolean isEditorReset(@NotNull KeyStroke key, @NotNull CommandState editorState) {
return (editorState.getMode() == CommandState.Mode.COMMAND || state == State.COMMAND) &&
(key.getKeyCode() == KeyEvent.VK_ESCAPE ||
(key.getKeyCode() == KeyEvent.VK_C && (key.getModifiers() & KeyEvent.CTRL_MASK) != 0) ||
(key.getKeyCode() == '[' && (key.getModifiers() & KeyEvent.CTRL_MASK) != 0));
}
// If we got this far the user is entering a command or supplying an argument to an entered command.
// First let's check to see if we are at the point of expecting a single character argument to a command.
else if (currentArg == Argument.CHARACTER) {
private void handleCharArgument(@NotNull KeyStroke key, char chKey) {
logger.debug("currentArg is Character");
// We are expecting a character argument - is this a regular character the user typed?
// Some special keys can be handled as character arguments - let's check for them here.
@@ -167,26 +271,15 @@ public class KeyHandler {
Argument arg = new Argument(chKey);
Command cmd = currentCmd.peek();
cmd.setArgument(arg);
mode = STATE_READY;
state = State.READY;
}
else {
// Oops - this isn't a valid character argument
mode = STATE_BAD_COMMAND;
state = State.BAD_COMMAND;
}
}
// If we are this far - sheesh, then the user must be entering a command or a non-single-character argument
// to an entered command. Let's figure out which it is
else {
// For debugging purposes we track the keys entered for this command
keys.add(key);
if (logger.isDebugEnabled()) {
logger.debug("keys now " + keys);
}
// Ask the key/action tree if this is an appropriate key at this point in the command and if so,
// return the node matching this keystroke
Node node = editorState.getCurrentNode().getChild(key);
private boolean handleDigraph(@NotNull Editor editor, @NotNull KeyStroke key, @NotNull DataContext context, @Nullable Node node) {
if (digraph == null && !(node instanceof CommandNode) && DigraphSequence.isDigraphStart(key)) {
digraph = new DigraphSequence();
}
@@ -194,183 +287,26 @@ public class KeyHandler {
DigraphSequence.DigraphResult res = digraph.processKey(key, editor, context);
switch (res.getResult()) {
case DigraphSequence.DigraphResult.RES_OK:
return;
return true;
case DigraphSequence.DigraphResult.RES_BAD:
digraph = null;
return;
return true;
case DigraphSequence.DigraphResult.RES_DONE:
if (currentArg == Argument.DIGRAPH) {
currentArg = Argument.CHARACTER;
if (currentArg == Argument.Type.DIGRAPH) {
currentArg = Argument.Type.CHARACTER;
}
key = res.getStroke();
digraph = null;
continue;
handleKey(editor, res.getStroke(), context);
return true;
}
logger.debug("digraph done");
}
// If this is a branch node we have entered only part of a multikey command
if (node instanceof BranchNode) {
logger.debug("branch node");
BranchNode bnode = (BranchNode)node;
// Flag that we aren't allowing any more count digits (unless it's OK)
if ((bnode.getFlags() & Command.FLAG_ALLOW_MID_COUNT) == 0) {
mode = STATE_COMMAND;
}
editorState.setCurrentNode(bnode);
ArgumentNode arg = (ArgumentNode)((BranchNode)editorState.getCurrentNode()).getArgumentNode();
if (arg != null) {
if (editorState.isRecording() && (arg.getFlags() & Command.FLAG_NO_ARG_RECORDING) != 0) {
handleKey(editor, KeyStroke.getKeyStroke(' '), context);
return false;
}
if (arg.getArgType() == Argument.EX_STRING) {
CommandGroups.getInstance().getProcess().startSearchCommand(editor, context, count, chKey);
mode = STATE_NEW_COMMAND;
currentArg = Argument.EX_STRING;
editorState.pushState(CommandState.MODE_EX_ENTRY, 0, KeyParser.MAPPING_CMD_LINE);
}
}
}
// If this is a command node the user has entered a valid key sequence of a known command
else if (node instanceof CommandNode) {
logger.debug("command node");
// If all does well we are ready to process this command
mode = STATE_READY;
CommandNode cmdNode = (CommandNode)node;
// Did we just get the completed sequence for a motion command argument?
if (currentArg == Argument.MOTION) {
// We have been expecting a motion argument - is this one?
if (cmdNode.getCmdType() == Command.MOTION) {
// Create the motion command and add it to the stack
Command cmd = new Command(count, cmdNode.getActionId(), cmdNode.getAction(),
cmdNode.getCmdType(), cmdNode.getFlags());
cmd.setKeys(keys);
currentCmd.push(cmd);
}
else if (cmdNode.getCmdType() == Command.RESET) {
currentCmd.clear();
Command cmd = new Command(1, cmdNode.getActionId(), cmdNode.getAction(),
cmdNode.getCmdType(), cmdNode.getFlags());
cmd.setKeys(keys);
currentCmd.push(cmd);
}
else {
// Oops - this wasn't a motion command. The user goofed and typed something else
mode = STATE_BAD_COMMAND;
}
}
else if (currentArg == Argument.EX_STRING && (cmdNode.getFlags() & Command.FLAG_COMPLETE_EX) != 0) {
String text = CommandGroups.getInstance().getProcess().endSearchCommand(editor, context);
Argument arg = new Argument(text);
Command cmd = currentCmd.peek();
cmd.setArgument(arg);
CommandState.getInstance(editor).popState();
}
// The user entered a valid command that doesn't take any arguments
else {
// Create the command and add it to the stack
Command cmd = new Command(count, cmdNode.getActionId(), cmdNode.getAction(),
cmdNode.getCmdType(), cmdNode.getFlags());
cmd.setKeys(keys);
currentCmd.push(cmd);
// This is a sanity check that the command has a valid action. This should only fail if the
// programmer made a typo or forgot to add the action to the plugin.xml file
if (cmd.getAction() == null) {
logger.error("NULL action for keys '" + keys + "'");
mode = STATE_ERROR;
}
}
}
// If this is an argument node then the last keystroke was not part of the current command but should
// be the first keystroke of the current command's argument
else if (node instanceof ArgumentNode) {
logger.debug("argument node");
// Create a new command based on what the user has typed so far, excluding this keystroke.
ArgumentNode arg = (ArgumentNode)node;
Command cmd = new Command(count, arg.getActionId(), arg.getAction(), arg.getCmdType(), arg.getFlags());
cmd.setKeys(keys);
currentCmd.push(cmd);
// What type of argument does this command expect?
switch (arg.getArgType()) {
case Argument.DIGRAPH:
//digraphState = 0;
digraph = new DigraphSequence();
// No break - fall through
case Argument.CHARACTER:
case Argument.MOTION:
mode = STATE_NEW_COMMAND;
currentArg = arg.getArgType();
// Is the current command an operator? If so set the state to only accept "operator pending"
// commands
if ((arg.getFlags() & Command.FLAG_OP_PEND) != 0) {
//CommandState.getInstance().setMappingMode(KeyParser.MAPPING_OP_PEND);
editorState.pushState(editorState.getMode(), editorState.getSubMode(),
KeyParser.MAPPING_OP_PEND);
}
break;
case Argument.EX_STRING:
/*
mode = STATE_NEW_COMMAND;
currentArg = arg.getArgType();
editorState.pushState(CommandState.MODE_EX_ENTRY, 0, KeyParser.MAPPING_CMD_LINE);
*/
break;
default:
// Oops - we aren't expecting any other type of argument
mode = STATE_ERROR;
}
// If the current keystroke is really the first character of an argument the user needs to enter,
// recursively go back and handle this keystroke again with all the state properly updated to
// handle the argument
if (currentArg != Argument.NONE) {
partialReset(editor);
boolean saveRecording = isRecording;
handleKey(editor, key, context);
isRecording = saveRecording;
shouldRecord = false; // Prevent this from getting recorded twice
}
}
else {
logger.debug("checking for digraph");
logger.debug("lastWasBS=" + lastWasBS);
logger.debug("lastChar=" + lastChar);
if (lastWasBS && lastChar != 0 && Options.getInstance().isSet("digraph")) {
char dig = CommandGroups.getInstance().getDigraph().getDigraph(lastChar, key.getKeyChar());
logger.debug("dig=" + dig);
key = KeyStroke.getKeyStroke(dig);
}
// If we are in insert/replace mode send this key in for processing
if (editorState.getMode() == CommandState.MODE_INSERT ||
editorState.getMode() == CommandState.MODE_REPLACE) {
if (!CommandGroups.getInstance().getChange().processKey(editor, context, key)) {
shouldRecord = false;
}
}
else if (editorState.getMappingMode() == KeyParser.MAPPING_CMD_LINE) {
if (!CommandGroups.getInstance().getProcess().processExKey(editor, context, key, true)) {
shouldRecord = false;
}
}
// If we get here then the user has entered an unrecognized series of keystrokes
else {
mode = STATE_BAD_COMMAND;
}
lastChar = key.getKeyChar();
partialReset(editor);
}
}
break;
}
// Do we have a fully entered command at this point? If so, lets execute it
if (mode == STATE_READY) {
private void executeCommand(@NotNull Editor editor, @NotNull KeyStroke key, @NotNull DataContext context,
@NotNull CommandState editorState) {
DelegateCommandListener.getInstance().setRunnable(null);
// Let's go through the command stack and merge it all into one command. At this time there should never
// be more than two commands on the stack - one is the actual command and the other would be a motion
@@ -386,13 +322,13 @@ public class KeyHandler {
logger.debug("cmd=" + cmd);
}
// If we have a command and a motion command argument, both could possibly have their own counts. We
// need to adjust the counts so the motion gets the product of both counts and the command's count gets
// reset. Example 3c2w (change 2 words, three times) becomes c6w (change 6 words)
// need to adjust the counts so the motion gets the product of both counts and the count associated with
// the command gets reset. Example 3c2w (change 2 words, three times) becomes c6w (change 6 words)
Argument arg = cmd.getArgument();
if (logger.isDebugEnabled()) {
logger.debug("arg=" + arg);
}
if (arg != null && arg.getType() == Argument.MOTION) {
if (arg != null && arg.getType() == Argument.Type.MOTION) {
Command mot = arg.getMotion();
// If no count was entered for either command then nothing changes. If either had a count then
// the motion gets the product of both.
@@ -414,32 +350,147 @@ public class KeyHandler {
logger.debug("lastWasBS=" + lastWasBS);
Project project = editor.getProject();
if (cmd.isReadType() || EditorHelper.canEdit(project, editor)) {
if (cmd.getType().isRead() || project == null || EditorHelper.canEdit(project, editor)) {
if (ApplicationManager.getApplication().isDispatchThread()) {
Runnable action = new ActionRunner(editor, context, cmd, key);
if (cmd.isWriteType()) {
if (cmd.getType().isWrite()) {
RunnableHelper.runWriteCommand(project, action, cmd.getActionId(), null);
}
else {
RunnableHelper.runReadCommand(project, action, cmd.getActionId(), null);
}
}
}
else {
logger.info("write command on read-only file");
VimPlugin.indicateError();
reset(editor);
}
}
else if (mode == STATE_BAD_COMMAND) {
VimPlugin.indicateError();
reset(editor);
private boolean handleArgumentNode(@NotNull Editor editor,
@NotNull KeyStroke key,
@NotNull DataContext context,
@NotNull CommandState editorState,
boolean shouldRecord,
@NotNull ArgumentNode node) {
logger.debug("argument node");
// Create a new command based on what the user has typed so far, excluding this keystroke.
Command cmd = new Command(count, node.getActionId(), node.getAction(), node.getCmdType(), node.getFlags());
cmd.setKeys(keys);
currentCmd.push(cmd);
// What type of argument does this command expect?
switch (node.getArgType()) {
case DIGRAPH:
//digraphState = 0;
digraph = new DigraphSequence();
// No break - fall through
case CHARACTER:
case MOTION:
state = State.NEW_COMMAND;
currentArg = node.getArgType();
// Is the current command an operator? If so set the state to only accept "operator pending"
// commands
if ((node.getFlags() & Command.FLAG_OP_PEND) != 0) {
//CommandState.getInstance().setMappingMode(KeyParser.MAPPING_OP_PEND);
editorState.pushState(editorState.getMode(), editorState.getSubMode(),
KeyParser.MAPPING_OP_PEND);
}
// We had some sort of error so reset the handler and let the user know (beep)
else if (mode == STATE_ERROR) {
VimPlugin.indicateError();
fullReset(editor);
break;
case EX_STRING:
break;
default:
// Oops - we aren't expecting any other type of argument
state = State.ERROR;
}
// If the current keystroke is really the first character of an argument the user needs to enter,
// recursively go back and handle this keystroke again with all the state properly updated to
// handle the argument
if (currentArg != Argument.Type.NONE) {
partialReset(editor);
handleKey(editor, key, context);
shouldRecord = false; // Prevent this from getting recorded twice
}
return shouldRecord;
}
private void handleCommandNode(@NotNull Editor editor, @NotNull DataContext context, @NotNull CommandNode node) {
logger.debug("command node");
// If all does well we are ready to process this command
state = State.READY;
// Did we just get the completed sequence for a motion command argument?
if (currentArg == Argument.Type.MOTION) {
// We have been expecting a motion argument - is this one?
if (node.getCmdType() == Command.Type.MOTION) {
// Create the motion command and add it to the stack
Command cmd = new Command(count, node.getActionId(), node.getAction(),
node.getCmdType(), node.getFlags());
cmd.setKeys(keys);
currentCmd.push(cmd);
}
else if (node.getCmdType() == Command.Type.RESET) {
currentCmd.clear();
Command cmd = new Command(1, node.getActionId(), node.getAction(),
node.getCmdType(), node.getFlags());
cmd.setKeys(keys);
currentCmd.push(cmd);
}
else {
// Oops - this wasn't a motion command. The user goofed and typed something else
state = State.BAD_COMMAND;
}
}
else if (currentArg == Argument.Type.EX_STRING && (node.getFlags() & Command.FLAG_COMPLETE_EX) != 0) {
String text = CommandGroups.getInstance().getProcess().endSearchCommand(editor, context);
Argument arg = new Argument(text);
Command cmd = currentCmd.peek();
cmd.setArgument(arg);
CommandState.getInstance(editor).popState();
}
// The user entered a valid command that doesn't take any arguments
else {
// Create the command and add it to the stack
Command cmd = new Command(count, node.getActionId(), node.getAction(),
node.getCmdType(), node.getFlags());
cmd.setKeys(keys);
currentCmd.push(cmd);
// This is a sanity check that the command has a valid action. This should only fail if the
// programmer made a typo or forgot to add the action to the plugin.xml file
if (cmd.getAction() == null) {
logger.error("NULL action for keys '" + keys + "'");
state = State.ERROR;
}
}
}
private void handleBranchNode(@NotNull Editor editor, @NotNull DataContext context, @NotNull CommandState editorState, char key,
@NotNull BranchNode node) {
logger.debug("branch node");
// Flag that we aren't allowing any more count digits (unless it's OK)
if ((node.getFlags() & Command.FLAG_ALLOW_MID_COUNT) == 0) {
state = State.COMMAND;
}
editorState.setCurrentNode(node);
ArgumentNode arg = (ArgumentNode)((BranchNode)editorState.getCurrentNode()).getArgumentNode();
if (arg != null) {
if (currentArg == Argument.Type.MOTION && arg.getCmdType() != Command.Type.MOTION) {
editorState.popState();
state = State.BAD_COMMAND;
return;
}
if (editorState.isRecording() && (arg.getFlags() & Command.FLAG_NO_ARG_RECORDING) != 0) {
handleKey(editor, KeyStroke.getKeyStroke(' '), context);
}
if (arg.getArgType() == Argument.Type.EX_STRING) {
CommandGroups.getInstance().getProcess().startSearchCommand(editor, context, count, key);
state = State.NEW_COMMAND;
currentArg = Argument.Type.EX_STRING;
editorState.pushState(CommandState.Mode.EX_ENTRY, CommandState.SubMode.NONE, KeyParser.MAPPING_CMD_LINE);
}
else if (isRecording && shouldRecord) {
CommandGroups.getInstance().getRegister().addKeyStroke(key);
}
}
@@ -492,7 +543,7 @@ public class KeyHandler {
*
* @param editor The editor to reset.
*/
private void partialReset(Editor editor) {
private void partialReset(@Nullable Editor editor) {
count = 0;
keys = new ArrayList<KeyStroke>();
CommandState editorState = CommandState.getInstance(editor);
@@ -505,11 +556,11 @@ public class KeyHandler {
*
* @param editor The editor to reset.
*/
public void reset(Editor editor) {
public void reset(@Nullable Editor editor) {
partialReset(editor);
mode = STATE_NEW_COMMAND;
state = State.NEW_COMMAND;
currentCmd.clear();
currentArg = Argument.NONE;
currentArg = Argument.Type.NONE;
digraph = null;
logger.debug("reset");
}
@@ -520,7 +571,8 @@ public class KeyHandler {
*
* @param editor The editor to reset.
*/
public void fullReset(Editor editor) {
public void fullReset(@Nullable Editor editor) {
VimPlugin.clearError();
CommandState.getInstance(editor).reset();
reset(editor);
lastChar = 0;
@@ -545,8 +597,8 @@ public class KeyHandler {
boolean wasRecording = editorState.isRecording();
executeAction(cmd.getAction(), context);
if (editorState.getMode() == CommandState.MODE_INSERT ||
editorState.getMode() == CommandState.MODE_REPLACE) {
if (editorState.getMode() == CommandState.Mode.INSERT ||
editorState.getMode() == CommandState.Mode.REPLACE) {
CommandGroups.getInstance().getChange().processCommand(editor, context, cmd);
}
@@ -554,7 +606,7 @@ public class KeyHandler {
// By default the "empty" register is used by all commands so we want to reset whatever the last register
// selected by the user was to the empty register - unless we just executed the "select register" command.
if (cmd.getType() != Command.SELECT_REGISTER) {
if (cmd.getType() != Command.Type.SELECT_REGISTER) {
CommandGroups.getInstance().getRegister().resetRegister();
}
@@ -562,7 +614,7 @@ public class KeyHandler {
// mode we were in. This handles commands in those modes that temporarily allow us to execute normal
// mode commands. An exception is if this command should leave us in the temporary mode such as
// "select register"
if (editorState.getSubMode() == CommandState.SUBMODE_SINGLE_COMMAND &&
if (editorState.getSubMode() == CommandState.SubMode.SINGLE_COMMAND &&
(cmd.getFlags() & Command.FLAG_EXPECT_MORE) == 0) {
editorState.popState();
}
@@ -580,23 +632,24 @@ public class KeyHandler {
private KeyStroke key;
}
private static enum State {
NEW_COMMAND,
COMMAND,
READY,
ERROR,
BAD_COMMAND
}
private int count;
private List<KeyStroke> keys;
private int mode;
private State state;
private Stack<Command> currentCmd = new Stack<Command>();
private int currentArg;
@NotNull private Argument.Type currentArg;
private TypedActionHandler origHandler;
private DigraphSequence digraph = null;
private char lastChar;
private boolean lastWasBS;
private static KeyHandler instance;
private static final int STATE_NEW_COMMAND = 1;
private static final int STATE_COMMAND = 2;
private static final int STATE_READY = 3;
private static final int STATE_ERROR = 4;
private static final int STATE_BAD_COMMAND = 5;
private static Logger logger = Logger.getInstance(KeyHandler.class.getName());
}

View File

@@ -3,6 +3,7 @@ package com.maddyhome.idea.vim;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.ex.ApplicationEx;
@@ -97,7 +98,9 @@ public class VimKeyMapUtil {
}
// Prompt user to select the parent for the Vim keyboard
if (!ApplicationManager.getApplication().isUnitTestMode()) {
configureVimParentKeymap(path, document, false);
}
final KeymapImpl vimKeyMap = new KeymapImpl();
final Keymap[] allKeymaps = manager.getAllKeymaps();

View File

@@ -90,6 +90,7 @@ public class VimPlugin implements ApplicationComponent, PersistentStateComponent
private boolean isBlockCursor = false;
private boolean isAnimatedScrolling = false;
private boolean isRefrainFromScrolling = false;
private boolean error = false;
private String previousKeyMap = "";
@@ -199,7 +200,7 @@ public class VimPlugin implements ApplicationComponent, PersistentStateComponent
DocumentManager.getInstance().init();
EditorFactory.getInstance().addEditorFactoryListener(new EditorFactoryAdapter() {
public void editorCreated(EditorFactoryEvent event) {
public void editorCreated(@NotNull EditorFactoryEvent event) {
final Editor editor = event.getEditor();
isBlockCursor = editor.getSettings().isBlockCursor();
isAnimatedScrolling = editor.getSettings().isAnimatedScrolling();
@@ -218,7 +219,7 @@ public class VimPlugin implements ApplicationComponent, PersistentStateComponent
}
}
public void editorReleased(EditorFactoryEvent event) {
public void editorReleased(@NotNull EditorFactoryEvent event) {
EditorData.uninitializeEditor(event.getEditor());
event.getEditor().getSettings().setAnimatedScrolling(isAnimatedScrolling);
event.getEditor().getSettings().setRefrainFromScrolling(isRefrainFromScrolling);
@@ -310,7 +311,10 @@ public class VimPlugin implements ApplicationComponent, PersistentStateComponent
* Inidicate to the user that an error has occurred. Just beep.
*/
public static void indicateError() {
if (!Options.getInstance().isSet("visualbell")) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
getInstance().error = true;
}
else if (!Options.getInstance().isSet("visualbell")) {
Toolkit.getDefaultToolkit().beep();
}
}
@@ -324,6 +328,7 @@ public class VimPlugin implements ApplicationComponent, PersistentStateComponent
Project[] projs = pm.getOpenProjects();
for (Project proj : projs) {
StatusBar bar = WindowManager.getInstance().getStatusBar(proj);
if (bar != null) {
if (msg == null || msg.length() == 0) {
bar.setInfo("");
}
@@ -332,6 +337,7 @@ public class VimPlugin implements ApplicationComponent, PersistentStateComponent
}
}
}
}
public void turnOnPlugin() {
KeyHandler.getInstance().fullReset(null);
@@ -384,4 +390,14 @@ public class VimPlugin implements ApplicationComponent, PersistentStateComponent
return actions;
}
public boolean isError() {
return error;
}
public static void clearError() {
if (ApplicationManager.getApplication().isUnitTestMode()) {
getInstance().error = false;
}
}
}

View File

@@ -26,6 +26,8 @@ import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import com.maddyhome.idea.vim.KeyHandler;
import com.maddyhome.idea.vim.VimPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -42,7 +44,7 @@ public class PassThruDelegateEditorAction extends AbstractDelegateEditorAction {
this.origHandler = handler;
}
public void execute(Editor editor, DataContext dataContext) {
public void execute(@Nullable Editor editor, @NotNull DataContext dataContext) {
if (logger.isDebugEnabled()) {
logger.debug("actionPerformed key=" + stroke);
}

View File

@@ -54,7 +54,7 @@ public class RepeatChangeAction extends EditorAction {
}
Command save = state.getCommand();
state.setCommand(cmd);
state.pushState(CommandState.MODE_REPEAT, 0, KeyParser.MAPPING_NORMAL);
state.pushState(CommandState.Mode.REPEAT, CommandState.SubMode.NONE, KeyParser.MAPPING_NORMAL);
char reg = CommandGroups.getInstance().getRegister().getCurrentRegister();
CommandGroups.getInstance().getRegister().selectRegister(state.getLastChangeRegister());
try {

View File

@@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.command.SelectionType;
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.group.CommandGroups;
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler;
@@ -36,8 +37,8 @@ public class ChangeVisualAction extends EditorAction {
private static class Handler extends VisualOperatorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd, TextRange range) {
int mode = range.isMultiple() ? Command.FLAG_MOT_BLOCKWISE : Command.FLAG_MOT_INCLUSIVE;
return CommandGroups.getInstance().getChange().changeRange(editor, context, range, mode);
final SelectionType type = range.isMultiple() ? SelectionType.BLOCK_WISE : SelectionType.CHARACTER_WISE;
return CommandGroups.getInstance().getChange().changeRange(editor, context, range, type);
}
}
}

View File

@@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.command.SelectionType;
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.group.CommandGroups;
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler;
@@ -40,7 +41,7 @@ public class ChangeVisualLinesAction extends EditorAction {
range = new TextRange(EditorHelper.getLineStartForOffset(editor, range.getStartOffset()),
EditorHelper.getLineEndForOffset(editor, range.getEndOffset()) + 1);
return CommandGroups.getInstance().getChange().changeRange(editor, context, range, Command.FLAG_MOT_LINEWISE);
return CommandGroups.getInstance().getChange().changeRange(editor, context, range, SelectionType.LINE_WISE);
}
}
}

View File

@@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.command.SelectionType;
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.group.CommandGroups;
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler;
@@ -47,14 +48,13 @@ public class ChangeVisualLinesEndAction extends EditorAction {
}
range = new TextRange(starts, ends);
return CommandGroups.getInstance().getChange().changeRange(editor, context, range,
Command.FLAG_MOT_BLOCKWISE);
return CommandGroups.getInstance().getChange().changeRange(editor, context, range, SelectionType.BLOCK_WISE);
}
else {
range = new TextRange(EditorHelper.getLineStartForOffset(editor, range.getStartOffset()),
EditorHelper.getLineEndForOffset(editor, range.getEndOffset()) + 1);
return CommandGroups.getInstance().getChange().changeRange(editor, context, range, Command.FLAG_MOT_LINEWISE);
return CommandGroups.getInstance().getChange().changeRange(editor, context, range, SelectionType.LINE_WISE);
}
}
}

View File

@@ -48,7 +48,7 @@ public class FilterMotionAction extends EditorAction {
LogicalPosition start = editor.offsetToLogicalPosition(range.getStartOffset());
LogicalPosition end = editor.offsetToLogicalPosition(range.getEndOffset());
if (current.line != start.line) {
MotionGroup.moveCaret(editor, context, range.getStartOffset());
MotionGroup.moveCaret(editor, range.getStartOffset());
}
int count;
@@ -59,7 +59,7 @@ public class FilterMotionAction extends EditorAction {
count = 1;
}
Command command = new Command(count, null, null, 0, 0);
Command command = new Command(count, null, null, Command.Type.UNDEFINED, 0);
CommandGroups.getInstance().getProcess().startFilterCommand(editor, context, command);
return true;

View File

@@ -24,6 +24,7 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.command.SelectionType;
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.group.CommandGroups;
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler;
@@ -38,13 +39,14 @@ public class DeleteVisualAction extends EditorAction {
private static class Handler extends VisualOperatorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd, TextRange range) {
int mode = CommandState.getInstance(editor).getSubMode();
if (mode == Command.FLAG_MOT_LINEWISE) {
CommandState.SubMode mode = CommandState.getInstance(editor).getSubMode();
if (mode == CommandState.SubMode.VISUAL_LINE) {
range = new TextRange(EditorHelper.getLineStartForOffset(editor, range.getStartOffset()),
EditorHelper.getLineEndForOffset(editor, range.getEndOffset()) + 1);
}
return CommandGroups.getInstance().getChange().deleteRange(editor, context, range, mode, false);
return CommandGroups.getInstance().getChange().deleteRange(editor, context, range,
SelectionType.fromSubMode(mode), false);
}
}
}

View File

@@ -24,6 +24,7 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.command.SelectionType;
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.group.CommandGroups;
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler;
@@ -38,16 +39,16 @@ public class DeleteVisualLinesAction extends EditorAction {
private static class Handler extends VisualOperatorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd, TextRange range) {
int mode = CommandState.getInstance(editor).getSubMode();
if (mode == Command.FLAG_MOT_BLOCKWISE) {
return CommandGroups.getInstance().getChange().deleteRange(editor, context, range, mode, false);
CommandState.SubMode mode = CommandState.getInstance(editor).getSubMode();
if (mode == CommandState.SubMode.VISUAL_BLOCK) {
return CommandGroups.getInstance().getChange().deleteRange(editor, context, range,
SelectionType.fromSubMode(mode), false);
}
else {
range = new TextRange(EditorHelper.getLineStartForOffset(editor, range.getStartOffset()),
EditorHelper.getLineEndForOffset(editor, range.getEndOffset()) + 1);
return CommandGroups.getInstance().getChange().deleteRange(editor, context, range,
Command.FLAG_MOT_LINEWISE, false);
return CommandGroups.getInstance().getChange().deleteRange(editor, context, range, SelectionType.LINE_WISE, false);
}
}
}

View File

@@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.command.SelectionType;
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.group.CommandGroups;
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler;
@@ -48,14 +49,14 @@ public class DeleteVisualLinesEndAction extends EditorAction {
range = new TextRange(starts, ends);
return CommandGroups.getInstance().getChange().deleteRange(editor, context, range,
Command.FLAG_MOT_BLOCKWISE, false);
SelectionType.BLOCK_WISE, false);
}
else {
range = new TextRange(EditorHelper.getLineStartForOffset(editor, range.getStartOffset()),
EditorHelper.getLineEndForOffset(editor, range.getEndOffset()) + 1);
return CommandGroups.getInstance().getChange().deleteRange(editor, context, range,
Command.FLAG_MOT_LINEWISE, false);
SelectionType.LINE_WISE, false);
}
}
}

View File

@@ -24,6 +24,7 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.command.SelectionType;
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.group.CommandGroups;
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler;
@@ -37,8 +38,9 @@ public class YankVisualAction extends EditorAction {
private static class Handler extends VisualOperatorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd, TextRange range) {
final CommandState.SubMode subMode = CommandState.getInstance(editor).getSubMode();
return CommandGroups.getInstance().getCopy().yankRange(editor, context, range,
CommandState.getInstance(editor).getSubMode(), true);
SelectionType.fromSubMode(subMode), true);
}
}
}

View File

@@ -24,6 +24,7 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.command.SelectionType;
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.group.CommandGroups;
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler;
@@ -38,16 +39,16 @@ public class YankVisualLinesAction extends EditorAction {
private static class Handler extends VisualOperatorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd, TextRange range) {
int mode = CommandState.getInstance(editor).getSubMode();
if (mode == Command.FLAG_MOT_BLOCKWISE) {
return CommandGroups.getInstance().getCopy().yankRange(editor, context, range, mode, true);
CommandState.SubMode mode = CommandState.getInstance(editor).getSubMode();
if (mode == CommandState.SubMode.VISUAL_BLOCK) {
return CommandGroups.getInstance().getCopy().yankRange(editor, context, range, SelectionType.fromSubMode(mode),
true);
}
else {
range = new TextRange(EditorHelper.getLineStartForOffset(editor, range.getStartOffset()),
EditorHelper.getLineEndForOffset(editor, range.getEndOffset()) + 1);
return CommandGroups.getInstance().getCopy().yankRange(editor, context, range, Command.FLAG_MOT_LINEWISE,
true);
return CommandGroups.getInstance().getCopy().yankRange(editor, context, range, SelectionType.LINE_WISE, true);
}
}
}

View File

@@ -37,7 +37,7 @@ public class BackspaceAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getProcess().processExKey(editor, context,
return CommandGroups.getInstance().getProcess().processExKey(editor,
(KeyStroke)cmd.getKeys().get(0), false);
}
}

View File

@@ -37,7 +37,7 @@ public class ProcessExKeyAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getProcess().processExKey(editor, context,
return CommandGroups.getInstance().getProcess().processExKey(editor,
(KeyStroke)cmd.getKeys().get(0), false);
}
}

View File

@@ -45,7 +45,7 @@ public class MotionLastColumnAction extends MotionEditorAction {
if (CommandState.inInsertMode(editor)) {
allow = true;
}
else if (CommandState.getInstance(editor).getMode() == CommandState.MODE_VISUAL) {
else if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) {
BoundStringOption opt = (BoundStringOption)Options.getInstance().getOption("selection");
if (!opt.getValue().equals("old")) {
allow = true;

View File

@@ -45,7 +45,7 @@ public class MotionLastScreenColumnAction extends MotionEditorAction {
if (CommandState.inInsertMode(editor)) {
allow = true;
}
else if (CommandState.getInstance(editor).getMode() == CommandState.MODE_VISUAL) {
else if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) {
BoundStringOption opt = (BoundStringOption)Options.getInstance().getOption("selection");
if (!opt.getValue().equals("old")) {
allow = true;

View File

@@ -42,7 +42,7 @@ public class MotionRightAction extends MotionEditorAction {
if (CommandState.inInsertMode(editor)) {
allow = true;
}
else if (CommandState.getInstance(editor).getMode() == CommandState.MODE_VISUAL) {
else if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) {
BoundStringOption opt = (BoundStringOption)Options.getInstance().getOption("selection");
if (!opt.getValue().equals("old")) {
allow = true;

View File

@@ -35,7 +35,7 @@ public class MotionGotoMarkAction extends MotionEditorAction {
private static class Handler extends MotionEditorActionHandler {
public int getOffset(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().moveCaretToMark(editor, context, argument.getCharacter());
return CommandGroups.getInstance().getMotion().moveCaretToMark(editor, argument.getCharacter());
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionGotoMarkLineAction extends MotionEditorAction {
private static class Handler extends MotionEditorActionHandler {
public int getOffset(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().moveCaretToMarkLine(editor, context, argument.getCharacter());
return CommandGroups.getInstance().getMotion().moveCaretToMarkLine(editor, argument.getCharacter());
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionMarkAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMark().setMark(editor, context, cmd.getArgument().getCharacter());
return CommandGroups.getInstance().getMark().setMark(editor, cmd.getArgument().getCharacter());
}
}
}

View File

@@ -36,7 +36,7 @@ public class MotionInnerBigWordAction extends TextObjectAction {
private static class Handler extends TextObjectActionHandler {
public TextRange getRange(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().getWordRange(editor, context, count, false, true);
return CommandGroups.getInstance().getMotion().getWordRange(editor, count, false, true);
}
}
}

View File

@@ -36,7 +36,7 @@ public class MotionInnerBlockAngleAction extends TextObjectAction {
private static class Handler extends TextObjectActionHandler {
public TextRange getRange(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().getBlockRange(editor, context, count, false, '<');
return CommandGroups.getInstance().getMotion().getBlockRange(editor, count, false, '<');
}
}
}

View File

@@ -36,7 +36,7 @@ public class MotionInnerBlockBraceAction extends TextObjectAction {
private static class Handler extends TextObjectActionHandler {
public TextRange getRange(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().getBlockRange(editor, context, count, false, '{');
return CommandGroups.getInstance().getMotion().getBlockRange(editor, count, false, '{');
}
}
}

View File

@@ -36,7 +36,7 @@ public class MotionInnerBlockBracketAction extends TextObjectAction {
private static class Handler extends TextObjectActionHandler {
public TextRange getRange(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().getBlockRange(editor, context, count, false, '[');
return CommandGroups.getInstance().getMotion().getBlockRange(editor, count, false, '[');
}
}
}

View File

@@ -36,7 +36,7 @@ public class MotionInnerBlockParenAction extends TextObjectAction {
private static class Handler extends TextObjectActionHandler {
public TextRange getRange(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().getBlockRange(editor, context, count, false, '(');
return CommandGroups.getInstance().getMotion().getBlockRange(editor, count, false, '(');
}
}
}

View File

@@ -36,7 +36,7 @@ public class MotionInnerParagraphAction extends TextObjectAction {
private static class Handler extends TextObjectActionHandler {
public TextRange getRange(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().getParagraphRange(editor, context, count, false);
return CommandGroups.getInstance().getMotion().getParagraphRange(editor, count, false);
}
}
}

View File

@@ -36,7 +36,7 @@ public class MotionInnerSentenceAction extends TextObjectAction {
private static class Handler extends TextObjectActionHandler {
public TextRange getRange(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().getSentenceRange(editor, context, count, false);
return CommandGroups.getInstance().getMotion().getSentenceRange(editor, count, false);
}
}
}

View File

@@ -36,7 +36,7 @@ public class MotionInnerWordAction extends TextObjectAction {
private static class Handler extends TextObjectActionHandler {
public TextRange getRange(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().getWordRange(editor, context, count, false, false);
return CommandGroups.getInstance().getMotion().getWordRange(editor, count, false, false);
}
}
}

View File

@@ -36,7 +36,7 @@ public class MotionOuterBigWordAction extends TextObjectAction {
private static class Handler extends TextObjectActionHandler {
public TextRange getRange(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().getWordRange(editor, context, count, true, true);
return CommandGroups.getInstance().getMotion().getWordRange(editor, count, true, true);
}
}
}

View File

@@ -36,7 +36,7 @@ public class MotionOuterBlockAngleAction extends TextObjectAction {
private static class Handler extends TextObjectActionHandler {
public TextRange getRange(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().getBlockRange(editor, context, count, true, '<');
return CommandGroups.getInstance().getMotion().getBlockRange(editor, count, true, '<');
}
}
}

View File

@@ -36,7 +36,7 @@ public class MotionOuterBlockBraceAction extends TextObjectAction {
private static class Handler extends TextObjectActionHandler {
public TextRange getRange(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().getBlockRange(editor, context, count, true, '{');
return CommandGroups.getInstance().getMotion().getBlockRange(editor, count, true, '{');
}
}
}

View File

@@ -36,7 +36,7 @@ public class MotionOuterBlockBracketAction extends TextObjectAction {
private static class Handler extends TextObjectActionHandler {
public TextRange getRange(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().getBlockRange(editor, context, count, true, '[');
return CommandGroups.getInstance().getMotion().getBlockRange(editor, count, true, '[');
}
}
}

View File

@@ -36,7 +36,7 @@ public class MotionOuterBlockParenAction extends TextObjectAction {
private static class Handler extends TextObjectActionHandler {
public TextRange getRange(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().getBlockRange(editor, context, count, true, '(');
return CommandGroups.getInstance().getMotion().getBlockRange(editor, count, true, '(');
}
}
}

View File

@@ -36,7 +36,7 @@ public class MotionOuterParagraphAction extends TextObjectAction {
private static class Handler extends TextObjectActionHandler {
public TextRange getRange(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().getParagraphRange(editor, context, count, true);
return CommandGroups.getInstance().getMotion().getParagraphRange(editor, count, true);
}
}
}

View File

@@ -36,7 +36,7 @@ public class MotionOuterSentenceAction extends TextObjectAction {
private static class Handler extends TextObjectActionHandler {
public TextRange getRange(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().getSentenceRange(editor, context, count, true);
return CommandGroups.getInstance().getMotion().getSentenceRange(editor, count, true);
}
}
}

View File

@@ -36,7 +36,7 @@ public class MotionOuterWordAction extends TextObjectAction {
private static class Handler extends TextObjectActionHandler {
public TextRange getRange(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().getWordRange(editor, context, count, true, false);
return CommandGroups.getInstance().getMotion().getWordRange(editor, count, true, false);
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionFirstScreenLineAction extends MotionEditorAction {
private static class Handler extends MotionEditorActionHandler {
public int getOffset(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().moveCaretToFirstScreenLine(editor, context, count);
return CommandGroups.getInstance().getMotion().moveCaretToFirstScreenLine(editor, count);
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionLastScreenLineAction extends MotionEditorAction {
private static class Handler extends MotionEditorActionHandler {
public int getOffset(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().moveCaretToLastScreenLine(editor, context, count);
return CommandGroups.getInstance().getMotion().moveCaretToLastScreenLine(editor, count);
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionLastScreenLineEndAction extends MotionEditorAction {
private static class Handler extends MotionEditorActionHandler {
public int getOffset(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().moveCaretToLastScreenLineEnd(editor, context, count);
return CommandGroups.getInstance().getMotion().moveCaretToLastScreenLineEnd(editor, count);
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionMiddleScreenLineAction extends MotionEditorAction {
private static class Handler extends MotionEditorActionHandler {
public int getOffset(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().moveCaretToMiddleScreenLine(editor, context);
return CommandGroups.getInstance().getMotion().moveCaretToMiddleScreenLine(editor);
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionScrollColumnLeftAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().scrollColumn(editor, context, cmd.getCount());
return CommandGroups.getInstance().getMotion().scrollColumn(editor, cmd.getCount());
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionScrollColumnRightAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().scrollColumn(editor, context, -cmd.getCount());
return CommandGroups.getInstance().getMotion().scrollColumn(editor, -cmd.getCount());
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionScrollFirstScreenColumnAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().scrollColumnToFirstScreenColumn(editor, context);
return CommandGroups.getInstance().getMotion().scrollColumnToFirstScreenColumn(editor);
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionScrollFirstScreenLineAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().scrollLineToFirstScreenLine(editor, context, cmd.getRawCount(), cmd.getCount(), false);
return CommandGroups.getInstance().getMotion().scrollLineToFirstScreenLine(editor, cmd.getRawCount(), cmd.getCount(), false);
}
}
}

View File

@@ -41,10 +41,10 @@ public class MotionScrollFirstScreenLinePageStartAction extends EditorAction {
if (raw == 0) {
int lines = EditorHelper.getScreenHeight(editor);
return CommandGroups.getInstance().getMotion().scrollLine(editor, context, lines);
return CommandGroups.getInstance().getMotion().scrollLine(editor, lines);
}
else {
return CommandGroups.getInstance().getMotion().scrollLineToFirstScreenLine(editor, context, raw, cnt, true);
return CommandGroups.getInstance().getMotion().scrollLineToFirstScreenLine(editor, raw, cnt, true);
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionScrollFirstScreenLineStartAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().scrollLineToFirstScreenLine(editor, context, cmd.getRawCount(),
return CommandGroups.getInstance().getMotion().scrollLineToFirstScreenLine(editor, cmd.getRawCount(),
cmd.getCount(), true);
}
}

View File

@@ -35,7 +35,7 @@ public class MotionScrollHalfPageDownAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().scrollHalfPage(editor, context, 1, cmd.getRawCount());
return CommandGroups.getInstance().getMotion().scrollHalfPage(editor, 1, cmd.getRawCount());
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionScrollHalfPageUpAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().scrollHalfPage(editor, context, -1, cmd.getRawCount());
return CommandGroups.getInstance().getMotion().scrollHalfPage(editor, -1, cmd.getRawCount());
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionScrollLastScreenColumnAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().scrollColumnToLastScreenColumn(editor, context);
return CommandGroups.getInstance().getMotion().scrollColumnToLastScreenColumn(editor);
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionScrollLastScreenLineAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().scrollLineToLastScreenLine(editor, context, cmd.getRawCount(), cmd.getCount(), false);
return CommandGroups.getInstance().getMotion().scrollLineToLastScreenLine(editor, cmd.getRawCount(), cmd.getCount(), false);
}
}
}

View File

@@ -41,10 +41,10 @@ public class MotionScrollLastScreenLinePageStartAction extends EditorAction {
if (raw == 0) {
int lines = EditorHelper.getScreenHeight(editor);
return CommandGroups.getInstance().getMotion().scrollLine(editor, context, -lines);
return CommandGroups.getInstance().getMotion().scrollLine(editor, -lines);
}
else {
return CommandGroups.getInstance().getMotion().scrollLineToLastScreenLine(editor, context, raw, cnt, true);
return CommandGroups.getInstance().getMotion().scrollLineToLastScreenLine(editor, raw, cnt, true);
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionScrollLastScreenLineStartAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().scrollLineToLastScreenLine(editor, context, cmd.getRawCount(),
return CommandGroups.getInstance().getMotion().scrollLineToLastScreenLine(editor, cmd.getRawCount(),
cmd.getCount(), true);
}
}

View File

@@ -35,7 +35,7 @@ public class MotionScrollLineDownAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().scrollLine(editor, context, cmd.getCount());
return CommandGroups.getInstance().getMotion().scrollLine(editor, cmd.getCount());
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionScrollLineUpAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().scrollLine(editor, context, -cmd.getCount());
return CommandGroups.getInstance().getMotion().scrollLine(editor, -cmd.getCount());
}
}
}

View File

@@ -36,7 +36,7 @@ public class MotionScrollMiddleScreenLineAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion()
.scrollLineToMiddleScreenLine(editor, context, cmd.getRawCount(), cmd.getCount(), false);
.scrollLineToMiddleScreenLine(editor, cmd.getRawCount(), cmd.getCount(), false);
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionScrollMiddleScreenLineStartAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().scrollLineToMiddleScreenLine(editor, context, cmd.getRawCount(),
return CommandGroups.getInstance().getMotion().scrollLineToMiddleScreenLine(editor, cmd.getRawCount(),
cmd.getCount(), true);
}
}

View File

@@ -35,7 +35,7 @@ public class MotionScrollPageDownAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().scrollFullPage(editor, context, cmd.getCount());
return CommandGroups.getInstance().getMotion().scrollFullPage(editor, cmd.getCount());
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionScrollPageUpAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().scrollFullPage(editor, context, -cmd.getCount());
return CommandGroups.getInstance().getMotion().scrollFullPage(editor, -cmd.getCount());
}
}
}

View File

@@ -37,7 +37,7 @@ public class GotoDeclarationAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
CommandGroups.getInstance().getMark().saveJumpLocation(editor, context);
CommandGroups.getInstance().getMark().saveJumpLocation(editor);
KeyHandler.executeAction("GotoDeclaration", context);
return true;

View File

@@ -36,7 +36,7 @@ public class SearchAgainNextAction extends MotionEditorAction {
private static class Handler extends MotionEditorActionHandler {
public int getOffset(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getSearch().searchNext(editor, context, count);
return CommandGroups.getInstance().getSearch().searchNext(editor, count);
}
}
}

View File

@@ -36,7 +36,7 @@ public class SearchAgainPreviousAction extends MotionEditorAction {
private static class Handler extends MotionEditorActionHandler {
public int getOffset(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getSearch().searchPrevious(editor, context, count);
return CommandGroups.getInstance().getSearch().searchPrevious(editor, count);
}
}
}

View File

@@ -37,7 +37,7 @@ public class SearchEntryFwdAction extends MotionEditorAction {
private static class Handler extends MotionEditorActionHandler {
public int getOffset(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getSearch().search(editor, context, argument.getString(),
return CommandGroups.getInstance().getSearch().search(editor, argument.getString(),
count, Command.FLAG_SEARCH_FWD, false);
}
}

View File

@@ -37,7 +37,7 @@ public class SearchEntryRevAction extends MotionEditorAction {
private static class Handler extends MotionEditorActionHandler {
public int getOffset(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getSearch().search(editor, context, argument.getString(),
return CommandGroups.getInstance().getSearch().search(editor, argument.getString(),
count, Command.FLAG_SEARCH_REV, false);
}
}

View File

@@ -36,7 +36,7 @@ public class SearchWholeWordBackwardAction extends MotionEditorAction {
private static class Handler extends MotionEditorActionHandler {
public int getOffset(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getSearch().searchWord(editor, context, count, true, -1);
return CommandGroups.getInstance().getSearch().searchWord(editor, count, true, -1);
}
}
}

View File

@@ -36,7 +36,7 @@ public class SearchWholeWordForwardAction extends MotionEditorAction {
private static class Handler extends MotionEditorActionHandler {
public int getOffset(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getSearch().searchWord(editor, context, count, true, 1);
return CommandGroups.getInstance().getSearch().searchWord(editor, count, true, 1);
}
}
}

View File

@@ -36,7 +36,7 @@ public class SearchWordBackwardAction extends MotionEditorAction {
private static class Handler extends MotionEditorActionHandler {
public int getOffset(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getSearch().searchWord(editor, context, count, false, -1);
return CommandGroups.getInstance().getSearch().searchWord(editor, count, false, -1);
}
}
}

View File

@@ -36,7 +36,7 @@ public class SearchWordForwardAction extends MotionEditorAction {
private static class Handler extends MotionEditorActionHandler {
public int getOffset(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getSearch().searchWord(editor, context, count, false, 1);
return CommandGroups.getInstance().getSearch().searchWord(editor, count, false, 1);
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionGotoLineFirstAction extends MotionEditorAction {
private static class Handler extends MotionEditorActionHandler {
public int getOffset(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().moveCaretGotoLineFirst(editor, context, count - 1);
return CommandGroups.getInstance().getMotion().moveCaretGotoLineFirst(editor, count - 1);
}
}
}

View File

@@ -35,7 +35,7 @@ public class MotionGotoLineLastAction extends MotionEditorAction {
private static class Handler extends MotionEditorActionHandler {
public int getOffset(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
return CommandGroups.getInstance().getMotion().moveCaretGotoLineLast(editor, context, rawCount, count - 1);
return CommandGroups.getInstance().getMotion().moveCaretGotoLineLast(editor, rawCount, count - 1);
}
}
}

View File

@@ -42,14 +42,14 @@ public class MotionGotoLineLastEndAction extends MotionEditorAction {
if (CommandState.inInsertMode(editor)) {
allow = true;
}
else if (CommandState.getInstance(editor).getMode() == CommandState.MODE_VISUAL) {
else if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) {
BoundStringOption opt = (BoundStringOption)Options.getInstance().getOption("selection");
if (!opt.getValue().equals("old")) {
allow = true;
}
}
return CommandGroups.getInstance().getMotion().moveCaretGotoLineLastEnd(editor, context, rawCount, count - 1, allow);
return CommandGroups.getInstance().getMotion().moveCaretGotoLineLastEnd(editor, rawCount, count - 1, allow);
}
}
}

View File

@@ -37,10 +37,10 @@ public class MotionPercentOrMatchAction extends MotionEditorAction {
private static class Handler extends MotionEditorActionHandler {
public int getOffset(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
if (rawCount == 0) {
return CommandGroups.getInstance().getMotion().moveCaretToMatchingPair(editor, context);
return CommandGroups.getInstance().getMotion().moveCaretToMatchingPair(editor);
}
else {
return CommandGroups.getInstance().getMotion().moveCaretToLinePercent(editor, context, count);
return CommandGroups.getInstance().getMotion().moveCaretToLinePercent(editor, count);
}
}

View File

@@ -36,7 +36,7 @@ public class VisualExitModeAction extends EditorAction {
private static class Handler extends EditorActionHandler {
public void execute(Editor editor, DataContext context) {
CommandGroups.getInstance().getMotion().processEscape(InjectedLanguageUtil.getTopLevelEditor(editor), context);
CommandGroups.getInstance().getMotion().processEscape(InjectedLanguageUtil.getTopLevelEditor(editor));
}
}
}

View File

@@ -36,7 +36,7 @@ public class VisualSelectPreviousAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().selectPreviousVisualMode(editor, context);
return CommandGroups.getInstance().getMotion().selectPreviousVisualMode(editor);
}
}
}

View File

@@ -36,7 +36,7 @@ public class VisualSwapEndsAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().swapVisualEnds(editor, context);
return CommandGroups.getInstance().getMotion().swapVisualEnds(editor);
}
}
}

View File

@@ -36,7 +36,7 @@ public class VisualSwapEndsBlockAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().swapVisualEndsBlock(editor, context);
return CommandGroups.getInstance().getMotion().swapVisualEndsBlock(editor);
}
}
}

View File

@@ -36,7 +36,7 @@ public class VisualSwapSelectionsAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion().swapVisualSelections(editor, context);
return CommandGroups.getInstance().getMotion().swapVisualSelections(editor);
}
}
}

View File

@@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.group.CommandGroups;
import com.maddyhome.idea.vim.handler.AbstractEditorActionHandler;
@@ -37,7 +38,7 @@ public class VisualToggleBlockModeAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion()
.toggleVisual(editor, context, cmd.getCount(), cmd.getRawCount(), Command.FLAG_MOT_BLOCKWISE);
.toggleVisual(editor, cmd.getCount(), cmd.getRawCount(), CommandState.SubMode.VISUAL_BLOCK);
}
}
}

View File

@@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.group.CommandGroups;
import com.maddyhome.idea.vim.handler.AbstractEditorActionHandler;
@@ -37,7 +38,7 @@ public class VisualToggleCharacterModeAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion()
.toggleVisual(editor, context, cmd.getCount(), cmd.getRawCount(), Command.FLAG_MOT_CHARACTERWISE);
.toggleVisual(editor, cmd.getCount(), cmd.getRawCount(), CommandState.SubMode.VISUAL_CHARACTER);
}
}
}

View File

@@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.group.CommandGroups;
import com.maddyhome.idea.vim.handler.AbstractEditorActionHandler;
@@ -37,7 +38,7 @@ public class VisualToggleLineModeAction extends EditorAction {
private static class Handler extends AbstractEditorActionHandler {
protected boolean execute(Editor editor, DataContext context, Command cmd) {
return CommandGroups.getInstance().getMotion()
.toggleVisual(editor, context, cmd.getCount(), cmd.getRawCount(), Command.FLAG_MOT_LINEWISE);
.toggleVisual(editor, cmd.getCount(), cmd.getRawCount(), CommandState.SubMode.VISUAL_LINE);
}
}
}

View File

@@ -19,34 +19,21 @@ package com.maddyhome.idea.vim.command;
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
import org.jetbrains.annotations.NotNull;
/**
* This represents a command argument.
*/
public class Argument {
/**
* This represents no argument
*/
public static final int NONE = 0;
/**
* This is for arguments of type motion command
*/
public static final int MOTION = 1;
/**
* This is for arguments of type character
*/
public static final int CHARACTER = 2;
/**
* This is for arguments of type string
*/
public static final int STRING = 3;
/**
* This is for arguments consisting of a digraph or a regular character
*/
public static final int DIGRAPH = 4;
/**
* This is for argumaents consisting of an ex string
*/
public static final int EX_STRING = 5;
public static enum Type {
NONE,
MOTION,
CHARACTER,
STRING,
DIGRAPH,
EX_STRING;
}
/**
* Creates a character argument
@@ -55,7 +42,7 @@ public class Argument {
*/
public Argument(char charArg) {
this.charArg = charArg;
type = CHARACTER;
type = Type.CHARACTER;
}
/**
@@ -65,7 +52,7 @@ public class Argument {
*/
public Argument(Command motionArg) {
this.motionArg = motionArg;
type = MOTION;
type = Type.MOTION;
}
/**
@@ -75,7 +62,7 @@ public class Argument {
*/
public Argument(String strArg) {
this.strArg = strArg;
type = STRING;
type = Type.STRING;
}
/**
@@ -83,7 +70,8 @@ public class Argument {
*
* @return The argument type
*/
public int getType() {
@NotNull
public Type getType() {
return type;
}
@@ -135,12 +123,12 @@ public class Argument {
public String toString() {
StringBuffer res = new StringBuffer();
res.append("Argument {");
res.append("Argument [");
res.append("charArg=").append(charArg);
res.append(",motionArg=").append(motionArg);
res.append(",strArg=").append(strArg);
res.append(",type=").append(type);
res.append("}");
res.append(", motionArg=").append(motionArg);
res.append(", strArg=").append(strArg);
res.append(", type=").append(type);
res.append("]");
return res.toString();
}
@@ -148,5 +136,5 @@ public class Argument {
private char charArg = 0;
private Command motionArg = null;
private String strArg = null;
private int type;
@NotNull private Type type;
}

View File

@@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.maddyhome.idea.vim.handler.AbstractEditorActionHandler;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.List;
@@ -107,61 +108,58 @@ public class Command {
public static final int FLAG_COMPLETE_EX = 1 << 29;
public static final int FLAG_TEXT_BLOCK = 1 << 30;
public static enum Type {
/**
* Represents commands that actually move the cursor and can be arguments to operators
* Represents undefined commands.
*/
public static final int MOTION = 1;
UNDEFINED,
/**
* Represents commands that insert new text into the editor
* Represents commands that actually move the cursor and can be arguments to operators.
*/
public static final int INSERT = 2;
MOTION,
/**
* Represents commands that remove text from the editor
* Represents commands that insert new text into the editor.
*/
public static final int DELETE = 3;
INSERT,
/**
* Represents commands that change text in the editor
* Represents commands that remove text from the editor.
*/
public static final int CHANGE = 4;
DELETE,
/**
* Represents commands that copy text in the editor
* Represents commands that change text in the editor.
*/
public static final int COPY = 5;
CHANGE,
/**
* Represents commands that paste text into the editor
* Represents commands that copy text in the editor.
*/
public static final int PASTE = 6;
public static final int RESET = 7;
COPY,
PASTE,
RESET,
/**
* Represents commands that select the register
* Represents commands that select the register.
*/
public static final int SELECT_REGISTER = 8;
/**
* Represents other types of commands
*/
public static final int OTHER_READONLY = 9;
public static final int OTHER_WRITABLE = 10;
public static final int OTHER_READ_WRITE = 11;
public static final int COMPLETION = 12;
SELECT_REGISTER,
OTHER_READONLY,
OTHER_WRITABLE,
OTHER_READ_WRITE,
COMPLETION;
public boolean isReadType() {
boolean res = false;
switch (type) {
public boolean isRead() {
switch (this) {
case MOTION:
case COPY:
case SELECT_REGISTER:
case OTHER_READONLY:
case OTHER_READ_WRITE:
case COMPLETION:
res = true;
return true;
default:
return false;
}
}
return res;
}
public boolean isWriteType() {
boolean res = false;
switch (type) {
public boolean isWrite() {
switch (this) {
case INSERT:
case DELETE:
case CHANGE:
@@ -169,10 +167,11 @@ public class Command {
case RESET:
case OTHER_WRITABLE:
case OTHER_READ_WRITE:
res = true;
return true;
default:
return false;
}
}
return res;
}
/**
@@ -183,7 +182,7 @@ public class Command {
* @param type The type of the command
* @param flags Any custom flags specific to this command
*/
public Command(int count, String actionId, AnAction action, int type, int flags) {
public Command(int count, String actionId, AnAction action, @NotNull Type type, int flags) {
this(count, actionId, action, type, flags, null);
}
@@ -196,7 +195,7 @@ public class Command {
* @param flags Any custom flags specific to this command
* @param arg The argument to this command
*/
public Command(int count, String actionId, AnAction action, int type, int flags, Argument arg) {
public Command(int count, String actionId, AnAction action, @NotNull Type type, int flags, Argument arg) {
this.count = count;
this.actionId = actionId;
this.action = action;
@@ -246,7 +245,8 @@ public class Command {
*
* @return The command type
*/
public int getType() {
@NotNull
public Type getType() {
return type;
}
@@ -322,15 +322,15 @@ public class Command {
public String toString() {
StringBuffer res = new StringBuffer();
res.append("Command {");
res.append("Command[");
res.append("count=").append(count);
res.append(",actionId=").append(actionId);
res.append(",action=").append(action);
res.append(",type=").append(type);
res.append(",flags=").append(flags);
res.append(",argument=").append(argument);
res.append(",keys=").append(keys);
res.append("}");
res.append(", actionId=").append(actionId);
res.append(", action=").append(action);
res.append(", type=").append(type);
res.append(", flags=").append(flags);
res.append(", argument=").append(argument);
res.append(", keys=").append(keys);
res.append("]");
return res.toString();
}
@@ -338,7 +338,7 @@ public class Command {
private int count;
private String actionId;
private AnAction action;
private int type;
@NotNull private Type type;
private int flags;
private Argument argument;
private List<KeyStroke> keys;

View File

@@ -28,6 +28,8 @@ import com.maddyhome.idea.vim.helper.EditorData;
import com.maddyhome.idea.vim.key.KeyParser;
import com.maddyhome.idea.vim.key.ParentNode;
import com.maddyhome.idea.vim.option.Options;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Stack;
@@ -35,32 +37,23 @@ import java.util.Stack;
* This singleton maintains various state information about commands being run
*/
public class CommandState {
/**
* Indicates a runtime state of being in command mode
*/
public static final int MODE_COMMAND = 1;
/**
* Indicates a runtime state of being in insert mode
*/
public static final int MODE_INSERT = 2;
/**
* Indicates a runtime state of being in replace mode
*/
public static final int MODE_REPLACE = 3;
/**
* Indicates a runtime state of being in repeat mode
*/
public static final int MODE_REPEAT = 4;
/**
* Indicates a runtime state of being in visual mode
*/
public static final int MODE_VISUAL = 5;
/**
* Indicates a runtime state of entering an Ex command
*/
public static final int MODE_EX_ENTRY = 6;
public static final int SUBMODE_SINGLE_COMMAND = 1;
public static enum Mode {
COMMAND,
INSERT,
REPLACE,
REPEAT,
VISUAL,
EX_ENTRY;
}
public static enum SubMode {
NONE,
SINGLE_COMMAND,
VISUAL_CHARACTER,
VISUAL_LINE,
VISUAL_BLOCK;
}
/**
* Gets the command state singleton
@@ -68,7 +61,8 @@ public class CommandState {
* @param editor
* @return The singleton instance
*/
public static CommandState getInstance(Editor editor) {
@NotNull
public static CommandState getInstance(@Nullable Editor editor) {
if (editor == null) {
return new CommandState();
}
@@ -83,8 +77,8 @@ public class CommandState {
}
public static boolean inInsertMode(Editor editor) {
final int mode = getInstance(editor).getMode();
return mode == MODE_INSERT || mode == MODE_REPLACE;
final Mode mode = getInstance(editor).getMode();
return mode == Mode.INSERT || mode == Mode.REPLACE;
}
/**
@@ -114,7 +108,7 @@ public class CommandState {
return flags;
}
public void pushState(int mode, int submode, int mapping) {
public void pushState(@NotNull Mode mode, @NotNull SubMode submode, int mapping) {
logger.debug("pushState");
modes.push(new State(mode, submode, mapping));
updateStatus();
@@ -137,19 +131,21 @@ public class CommandState {
*
* @return The current runtime mode
*/
public int getMode() {
final int mode = currentState().getMode();
@NotNull
public Mode getMode() {
final Mode mode = currentState().getMode();
if (logger.isDebugEnabled()) {
logger.debug("getMode=" + mode);
}
return mode;
}
public int getSubMode() {
@NotNull
public SubMode getSubMode() {
return currentState().getSubmode();
}
public void setSubMode(int submode) {
public void setSubMode(@NotNull SubMode submode) {
currentState().setSubmode(submode);
updateStatus();
}
@@ -184,30 +180,30 @@ public class CommandState {
StringBuffer msg = new StringBuffer();
switch (state.getMode()) {
case MODE_COMMAND:
if (state.getSubmode() == SUBMODE_SINGLE_COMMAND) {
case COMMAND:
if (state.getSubmode() == SubMode.SINGLE_COMMAND) {
msg.append('(').append(getStatusString(pos - 1).toLowerCase()).append(')');
}
break;
case MODE_INSERT:
case INSERT:
msg.append("INSERT");
break;
case MODE_REPLACE:
case REPLACE:
msg.append("REPLACE");
break;
case MODE_VISUAL:
case VISUAL:
if (pos > 0) {
State tmp = modes.get(pos - 1);
if (tmp.getMode() == MODE_COMMAND && tmp.getSubmode() == SUBMODE_SINGLE_COMMAND) {
if (tmp.getMode() == Mode.COMMAND && tmp.getSubmode() == SubMode.SINGLE_COMMAND) {
msg.append(getStatusString(pos - 1));
msg.append(" - ");
}
}
switch (state.getSubmode()) {
case Command.FLAG_MOT_LINEWISE:
case VISUAL_LINE:
msg.append("VISUAL LINE");
break;
case Command.FLAG_MOT_BLOCKWISE:
case VISUAL_BLOCK:
msg.append("VISUAL BLOCK");
break;
default:
@@ -224,13 +220,13 @@ public class CommandState {
* mode.
*/
public void toggleInsertOverwrite() {
int oldmode = getMode();
int newmode = oldmode;
if (oldmode == MODE_INSERT) {
newmode = MODE_REPLACE;
Mode oldmode = getMode();
Mode newmode = oldmode;
if (oldmode == Mode.INSERT) {
newmode = Mode.REPLACE;
}
else if (oldmode == MODE_REPLACE) {
newmode = MODE_INSERT;
else if (oldmode == Mode.REPLACE) {
newmode = Mode.INSERT;
}
if (oldmode != newmode) {
@@ -332,25 +328,27 @@ public class CommandState {
* Signleton, no public object creation
*/
private CommandState() {
modes.push(new State(MODE_COMMAND, 0, KeyParser.MAPPING_NORMAL));
modes.push(new State(Mode.COMMAND, SubMode.NONE, KeyParser.MAPPING_NORMAL));
}
private class State {
public State(int mode, int submode, int mapping) {
public State(@NotNull Mode mode, @NotNull SubMode submode, int mapping) {
this.mode = mode;
this.submode = submode;
this.mapping = mapping;
}
public int getMode() {
@NotNull
public Mode getMode() {
return mode;
}
public int getSubmode() {
@NotNull
public SubMode getSubmode() {
return submode;
}
public void setSubmode(int submode) {
public void setSubmode(@NotNull SubMode submode) {
this.submode = submode;
}
@@ -371,13 +369,13 @@ public class CommandState {
return res.toString();
}
private int mode;
private int submode;
@NotNull private Mode mode;
@NotNull private SubMode submode;
private int mapping;
}
private Stack<State> modes = new Stack<State>();
private State defaultState = new State(MODE_COMMAND, 0, KeyParser.MAPPING_NORMAL);
private State defaultState = new State(Mode.COMMAND, SubMode.NONE, KeyParser.MAPPING_NORMAL);
private Command command;
private int flags;
private boolean isRecording = false;

View File

@@ -0,0 +1,61 @@
package com.maddyhome.idea.vim.command;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author vlan
*/
public enum SelectionType {
// Integer values for registers serialization in RegisterGroup.readData()
LINE_WISE(1 << 1),
CHARACTER_WISE(1 << 2),
BLOCK_WISE(1 << 3);
SelectionType(int value) {
this.value = value;
}
private final int value;
public int getValue() {
return value;
}
@Nullable
public static SelectionType fromValue(int value) {
for (SelectionType type : SelectionType.values()) {
if (type.getValue() == value) {
return type;
}
}
return null;
}
@Nullable
public static SelectionType fromSubMode(@NotNull CommandState.SubMode subMode) {
switch (subMode) {
case VISUAL_LINE:
return LINE_WISE;
case VISUAL_CHARACTER:
return CHARACTER_WISE;
case VISUAL_BLOCK:
return BLOCK_WISE;
default:
return null;
}
}
@NotNull
public static SelectionType fromCommandFlags(int flags) {
if ((flags & Command.FLAG_MOT_LINEWISE) != 0) {
return SelectionType.LINE_WISE;
}
else if ((flags & Command.FLAG_MOT_BLOCKWISE) != 0) {
return SelectionType.BLOCK_WISE;
}
else {
return SelectionType.CHARACTER_WISE;
}
}
}

View File

@@ -19,8 +19,10 @@ package com.maddyhome.idea.vim.command;
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
import org.jetbrains.annotations.NotNull;
public class VisualChange {
public VisualChange(int lines, int columns, int type) {
public VisualChange(int lines, int columns, @NotNull SelectionType type) {
this.lines = lines;
this.columns = columns;
this.type = type;
@@ -34,7 +36,8 @@ public class VisualChange {
return columns;
}
public int getType() {
@NotNull
public SelectionType getType() {
return type;
}
@@ -51,5 +54,5 @@ public class VisualChange {
int lines;
int columns;
int type;
@NotNull SelectionType type;
}

View File

@@ -19,8 +19,10 @@ package com.maddyhome.idea.vim.command;
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
import org.jetbrains.annotations.NotNull;
public class VisualRange {
public VisualRange(int start, int end, int type, int offset) {
public VisualRange(int start, int end, @NotNull CommandState.SubMode type, int offset) {
this.start = start;
this.end = end;
this.type = type;
@@ -35,7 +37,8 @@ public class VisualRange {
return end;
}
public int getType() {
@NotNull
public CommandState.SubMode getType() {
return type;
}
@@ -57,6 +60,6 @@ public class VisualRange {
int start;
int end;
int type;
@NotNull CommandState.SubMode type;
int offset;
}

View File

@@ -19,7 +19,9 @@ package com.maddyhome.idea.vim.common;
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
import com.maddyhome.idea.vim.command.SelectionType;
import com.maddyhome.idea.vim.helper.StringHelper;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.Comparator;
@@ -33,17 +35,17 @@ public class Register {
* Create a register of the specified type for the given text
*
* @param name The character
* @param type The register type (linewise or characterwise)
* @param type The register type
* @param text The text to store
*/
public Register(char name, int type, String text) {
public Register(char name, @NotNull SelectionType type, String text) {
this.name = name;
this.type = type;
this.text = text;
this.keys = null;
}
public Register(char name, int type, List<KeyStroke> keys) {
public Register(char name, @NotNull SelectionType type, List<KeyStroke> keys) {
this.name = name;
this.type = type;
this.text = null;
@@ -68,7 +70,8 @@ public class Register {
*
* @return The register type
*/
public int getType() {
@NotNull
public SelectionType getType() {
return type;
}
@@ -151,7 +154,7 @@ public class Register {
}
private char name;
private int type;
@NotNull private SelectionType type;
private String text;
private List<KeyStroke> keys;
}

View File

@@ -19,7 +19,7 @@ import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.command.SelectionType;
import com.maddyhome.idea.vim.common.Register;
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.ex.handler.*;
@@ -192,8 +192,8 @@ public class CommandParser {
// Run the command
boolean ok = handler.process(editor, context, new ExCommand(res.getRanges(), command, res.getArgument()), count);
if (ok && (handler.getArgFlags() & CommandHandler.DONT_SAVE_LAST) == 0) {
CommandGroups.getInstance().getRegister().storeTextInternal(editor, context, new TextRange(-1, -1), cmd,
Command.FLAG_MOT_CHARACTERWISE, ':', false, false);
CommandGroups.getInstance().getRegister().storeTextInternal(editor, new TextRange(-1, -1), cmd,
SelectionType.CHARACTER_WISE, ':', false, false);
}
if (ok && (handler.getArgFlags() & CommandHandler.KEEP_FOCUS) != 0) {

View File

@@ -204,8 +204,8 @@ public class Ranges {
startLine = endLine;
endLine = range.getLine(editor, context, lastZero);
if (range.isMove()) {
MotionGroup.moveCaret(editor, context,
CommandGroups.getInstance().getMotion().moveCaretToLine(editor, context, endLine));
MotionGroup.moveCaret(editor,
CommandGroups.getInstance().getMotion().moveCaretToLine(editor, endLine));
}
// Did that last range represent the start of the file?
lastZero = (endLine < 0);

View File

@@ -69,7 +69,7 @@ public class CmdFilterHandler extends CommandHandler {
}
try {
return CommandGroups.getInstance().getProcess().executeFilter(editor, context, range, command);
return CommandGroups.getInstance().getProcess().executeFilter(editor, range, command);
}
catch (IOException e) {
throw new ExException(e.getMessage());

View File

@@ -21,7 +21,8 @@ package com.maddyhome.idea.vim.ex.handler;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.command.SelectionType;
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.ex.*;
import com.maddyhome.idea.vim.group.CommandGroups;
@@ -46,8 +47,8 @@ public class CopyTextHandler extends CommandHandler {
int offset = CommandGroups.getInstance().getMotion().moveCaretToLineStart(editor, line + 1);
String text = EditorHelper.getText(editor, range.getStartOffset(), range.getEndOffset());
CommandGroups.getInstance().getCopy().putText(editor, context, offset, text, Command.FLAG_MOT_LINEWISE, 1, true,
false, 0);
CommandGroups.getInstance().getCopy().putText(editor, context, offset, text, SelectionType.LINE_WISE, 1, true,
false, CommandState.SubMode.NONE);
return true;
}

View File

@@ -21,7 +21,7 @@ package com.maddyhome.idea.vim.ex.handler;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.command.SelectionType;
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.ex.CommandHandler;
import com.maddyhome.idea.vim.ex.ExCommand;
@@ -50,6 +50,6 @@ public class DeleteLinesHandler extends CommandHandler {
TextRange range = cmd.getTextRange(editor, context, true);
return CommandGroups.getInstance().getChange().deleteRange(editor, context, range, Command.FLAG_MOT_LINEWISE, false);
return CommandGroups.getInstance().getChange().deleteRange(editor, context, range, SelectionType.LINE_WISE, false);
}
}

View File

@@ -43,7 +43,7 @@ public class EditFileHandler extends CommandHandler {
String arg = cmd.getArgument();
if (arg != null) {
if (arg.equals("#")) {
CommandGroups.getInstance().getMark().saveJumpLocation(editor, context);
CommandGroups.getInstance().getMark().saveJumpLocation(editor);
CommandGroups.getInstance().getFile().selectPreviousTab(context);
return true;
@@ -51,7 +51,7 @@ public class EditFileHandler extends CommandHandler {
else if (arg.length() > 0) {
boolean res = CommandGroups.getInstance().getFile().openFile(arg, context);
if (res) {
CommandGroups.getInstance().getMark().saveJumpLocation(editor, context);
CommandGroups.getInstance().getMark().saveJumpLocation(editor);
}
return res;

View File

@@ -42,7 +42,7 @@ public class FindClassHandler extends CommandHandler {
if (arg != null && arg.length() > 0) {
boolean res = CommandGroups.getInstance().getFile().openFile(arg + ".java", context);
if (res) {
CommandGroups.getInstance().getMark().saveJumpLocation(editor, context);
CommandGroups.getInstance().getMark().saveJumpLocation(editor);
}
return res;

Some files were not shown because too many files have changed in this diff Show More