mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-17 16:31:45 +02:00
Compare commits
102 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0da8625f30 | ||
![]() |
4cc784eb95 | ||
![]() |
ee3bec9eed | ||
![]() |
24788ac86f | ||
![]() |
9af3c732b5 | ||
![]() |
e5873fe5f9 | ||
![]() |
39f088cdcd | ||
![]() |
e805852721 | ||
![]() |
e136ecc1f8 | ||
![]() |
efa4001440 | ||
![]() |
68c20ed48d | ||
![]() |
c5760ceaab | ||
![]() |
8c7c9a67a6 | ||
![]() |
85231b314f | ||
![]() |
210b2efd47 | ||
![]() |
ae5b1385ea | ||
![]() |
011ce28251 | ||
![]() |
efb58b45df | ||
![]() |
7d033787eb | ||
![]() |
3a47583cf9 | ||
![]() |
565b4b3f2f | ||
![]() |
574f32a6dd | ||
![]() |
0e67c8ff69 | ||
![]() |
b886073c11 | ||
![]() |
57c35b9a74 | ||
![]() |
f5100694d6 | ||
![]() |
3ff9bfcc13 | ||
![]() |
6c8d2bfd9e | ||
![]() |
637f7f48ad | ||
![]() |
8eae80d30f | ||
![]() |
9a103276e3 | ||
![]() |
6386f011f7 | ||
![]() |
742d6e63d9 | ||
![]() |
f6141603ef | ||
![]() |
7a5b4e565a | ||
![]() |
373e1527c1 | ||
![]() |
9cb05b6a7d | ||
![]() |
74bf5ff044 | ||
![]() |
0f7e9d11b6 | ||
![]() |
5fadc2fb9f | ||
![]() |
96bbcf623f | ||
![]() |
89e853158c | ||
![]() |
5c31fcc03e | ||
![]() |
3fee4a803b | ||
![]() |
8b61f559d7 | ||
![]() |
4bd058f5dc | ||
![]() |
999ccf87fc | ||
![]() |
4e45e885b9 | ||
![]() |
6aee9ccaf1 | ||
![]() |
af3c6ff012 | ||
![]() |
0c9bdf5168 | ||
![]() |
82a9587b4f | ||
![]() |
850f4d7ec5 | ||
![]() |
8d1dcc4568 | ||
![]() |
3650ab85df | ||
![]() |
e1e1cc2666 | ||
![]() |
79fd32088b | ||
![]() |
458e0fc76d | ||
![]() |
5090c81632 | ||
![]() |
dcd035353b | ||
![]() |
8606ce21bd | ||
![]() |
72537c6ffb | ||
![]() |
30f9888f51 | ||
![]() |
d5a2b92121 | ||
![]() |
fd3eee6870 | ||
![]() |
2d6d1003b7 | ||
![]() |
499c590f5a | ||
![]() |
787b78ef36 | ||
![]() |
88a0b0fa23 | ||
![]() |
1519f04930 | ||
![]() |
e0a1291de0 | ||
![]() |
8a2d881002 | ||
![]() |
4802b6f460 | ||
![]() |
8c0e116a1c | ||
![]() |
8862878011 | ||
![]() |
bdf3361243 | ||
![]() |
6b5216077b | ||
![]() |
7e119f7963 | ||
![]() |
933cbc7e51 | ||
![]() |
65f30d4480 | ||
![]() |
1f8d3f119e | ||
![]() |
45fe858503 | ||
![]() |
0cc06ad186 | ||
![]() |
18cd7547ad | ||
![]() |
7746a26062 | ||
![]() |
a47fc9d3be | ||
![]() |
8fdf75330c | ||
![]() |
d6ebaa26b0 | ||
![]() |
27bd7ec836 | ||
![]() |
6752058922 | ||
![]() |
b965108dad | ||
![]() |
6bf0f36567 | ||
![]() |
69f1a70968 | ||
![]() |
47edfcac5e | ||
![]() |
c34599b954 | ||
![]() |
48b371c985 | ||
![]() |
47165e7b9d | ||
![]() |
f2a0408801 | ||
![]() |
7ccb6c8411 | ||
![]() |
1518831f37 | ||
![]() |
3bdfaa02e1 | ||
![]() |
e8de9f915c |
12
.idea/codeStyleSettings.xml
generated
12
.idea/codeStyleSettings.xml
generated
@@ -141,11 +141,8 @@
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="Groovy">
|
||||
<option name="LINE_COMMENT_AT_FIRST_COLUMN" value="false" />
|
||||
<option name="BLOCK_COMMENT_AT_FIRST_COLUMN" value="false" />
|
||||
<option name="KEEP_LINE_BREAKS" value="false" />
|
||||
<option name="ELSE_ON_NEW_LINE" value="true" />
|
||||
<option name="WHILE_ON_NEW_LINE" value="true" />
|
||||
<option name="CATCH_ON_NEW_LINE" value="true" />
|
||||
<option name="FINALLY_ON_NEW_LINE" value="true" />
|
||||
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
|
||||
@@ -154,7 +151,6 @@
|
||||
<option name="ALIGN_MULTILINE_TERNARY_OPERATION" value="true" />
|
||||
<option name="ALIGN_MULTILINE_THROWS_LIST" value="true" />
|
||||
<option name="ALIGN_MULTILINE_EXTENDS_LIST" value="true" />
|
||||
<option name="ALIGN_MULTILINE_PARENTHESIZED_EXPRESSION" value="true" />
|
||||
<option name="SPACE_AFTER_TYPE_CAST" value="false" />
|
||||
<option name="CALL_PARAMETERS_WRAP" value="1" />
|
||||
<option name="METHOD_PARAMETERS_WRAP" value="5" />
|
||||
@@ -165,12 +161,9 @@
|
||||
<option name="METHOD_CALL_CHAIN_WRAP" value="1" />
|
||||
<option name="BINARY_OPERATION_WRAP" value="5" />
|
||||
<option name="TERNARY_OPERATION_WRAP" value="5" />
|
||||
<option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
|
||||
<option name="FOR_STATEMENT_WRAP" value="5" />
|
||||
<option name="ARRAY_INITIALIZER_WRAP" value="1" />
|
||||
<option name="ASSIGNMENT_WRAP" value="1" />
|
||||
<option name="IF_BRACE_FORCE" value="1" />
|
||||
<option name="DOWHILE_BRACE_FORCE" value="1" />
|
||||
<option name="WHILE_BRACE_FORCE" value="1" />
|
||||
<option name="FOR_BRACE_FORCE" value="1" />
|
||||
<option name="FIELD_ANNOTATION_WRAP" value="0" />
|
||||
@@ -227,6 +220,10 @@
|
||||
<option name="TAB_SIZE" value="8" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="JSON">
|
||||
<option name="KEEP_LINE_BREAKS" value="false" />
|
||||
<option name="PARENT_SETTINGS_INSTALLED" value="true" />
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="JSP">
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="2" />
|
||||
@@ -277,4 +274,3 @@
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
|
@@ -33,6 +33,7 @@ Contributors:
|
||||
* [Thomas B Homburg](mailto:thomas@homburg.dk)
|
||||
* [smartbomb](mailto:smartbomb@server.fake)
|
||||
* [Tuomas Tynkkynen](mailto:tuomas.tynkkynen@iki.fi)
|
||||
* [Jackson Popkin](mailto:jackson@donorschoose.org)
|
||||
|
||||
If you are a contributor and your name is not listed here, feel free to
|
||||
contact the maintainer.
|
||||
|
76
CHANGES.md
76
CHANGES.md
@@ -3,6 +3,82 @@ The Changelog
|
||||
|
||||
History of changes in IdeaVim for the IntelliJ platform.
|
||||
|
||||
0.44, 2015-11-02
|
||||
----------------
|
||||
|
||||
A bugfix release.
|
||||
|
||||
|
||||
* VIM-1040 Fixed typing keys in completion menus and typing with the
|
||||
plugin disabled
|
||||
|
||||
|
||||
0.43, 2015-11-02
|
||||
----------------
|
||||
|
||||
A bugfix release.
|
||||
|
||||
* VIM-1039 Fixed running the plugin with Java 6
|
||||
|
||||
|
||||
0.42, 2015-11-01
|
||||
----------------
|
||||
|
||||
This release is compatible with IntelliJ 15+ and other IDEs based on the
|
||||
IntelliJ platform branch 143+.
|
||||
|
||||
* VIM-970 Fixed move commands in read-only files
|
||||
|
||||
|
||||
0.41, 2015-06-10
|
||||
----------------
|
||||
|
||||
A bugfix release.
|
||||
|
||||
* VIM-957 Fixed plugin version 0.40 is not compatible with IDEs other than
|
||||
IntelliJ
|
||||
|
||||
|
||||
0.40, 2015-06-09
|
||||
----------------
|
||||
|
||||
Added support for `mapleader`. Support comments in `%` brace matching. Various
|
||||
bug fixes.
|
||||
|
||||
Features:
|
||||
|
||||
* VIM-650 Added support for `mapleader`
|
||||
* VIM-932 Support comments in `%` brace matching
|
||||
|
||||
Bug fixes:
|
||||
|
||||
* VIM-586 Invoke Vim shortcuts handler later to restore the sequence of input
|
||||
events
|
||||
* VIM-838 `J` shouldn't add whitespace if there is a trailing space
|
||||
* VIM-855 Fixed regexp character class problem
|
||||
* VIM-210 Fix focus issues with the Ex panel and splits
|
||||
* VIM-575 Don't change cursor position of other splits in visual mode
|
||||
* VIM-864 Fixed visual marks getting changed during visual substitute
|
||||
* VIM-856 Fixed regex look-behind problem
|
||||
* VIM-868 Allow count on `gt` and `gT`
|
||||
* VIM-700 Remapping `0` should still allow it to be entered in command count
|
||||
* VIM-781 Fixed expanding visual block selection past empty lines
|
||||
* VIM-845 Fixed `c` and `x` functionality for visual block selections
|
||||
* VIM-930 Fixed editor focus issues after closing Ex entry box on Oracle Java 6
|
||||
|
||||
|
||||
0.39, 2014-12-03
|
||||
----------------
|
||||
|
||||
A bugfix release.
|
||||
|
||||
Bug fixes:
|
||||
|
||||
* VIM-848 Show line numbers if they are enabled in the settings and there is
|
||||
no `set number`
|
||||
* VIM-702 Fix infinite loop on `s/$/\r/g`
|
||||
* EA-63022 Don't update line numbers in the caret movement event listener
|
||||
|
||||
|
||||
0.38, 2014-12-01
|
||||
----------------
|
||||
|
24
README.md
24
README.md
@@ -2,15 +2,15 @@ IdeaVim
|
||||
=======
|
||||
|
||||
<div>
|
||||
<a href="http://teamcity.jetbrains.com/viewType.html?buildTypeId=bt299&guest=1">
|
||||
<img src="http://teamcity.jetbrains.com/app/rest/builds/buildType:(id:bt299)/statusIcon"/>
|
||||
<a href="http://teamcity.jetbrains.com/viewType.html?buildTypeId=IdeaVim_Build&guest=1">
|
||||
<img src="http://teamcity.jetbrains.com/app/rest/builds/buildType:(id:IdeaVim_Build)/statusIcon"/>
|
||||
</a>
|
||||
<span>Build<span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<a href="http://teamcity.jetbrains.com/viewType.html?buildTypeId=bt453&guest=1">
|
||||
<img src="http://teamcity.jetbrains.com/app/rest/builds/buildType:(id:bt453)/statusIcon"/>
|
||||
<a href="http://teamcity.jetbrains.com/viewType.html?buildTypeId=IdeaVim_TestsForIntelliJ15&guest=1">
|
||||
<img src="http://teamcity.jetbrains.com/app/rest/builds/buildType:(id:IdeaVim_TestsForIntelliJ15)/statusIcon"/>
|
||||
</a>
|
||||
<span>Tests</span>
|
||||
</div>
|
||||
@@ -91,6 +91,11 @@ Note, that IdeaVim currently parses ~/.ideavimrc file via simple pattern matchin
|
||||
see [VIM-669](http://youtrack.jetbrains.com/issue/VIM-669) for proper parsing
|
||||
of VimL files.
|
||||
|
||||
Also note that if you have overridden the `user.home` JVM option, this will
|
||||
will affect where IdeaVim looks for your .ideavimrc file. For example, if you
|
||||
have `-Duser.home=/my/alternate/home` then IdeaVim will source
|
||||
`/my/alternate/home/.ideavimrc` instead of `~/.ideavimrc`.
|
||||
|
||||
|
||||
Changes to the IDE
|
||||
------------------
|
||||
@@ -122,6 +127,10 @@ Ex commands or via `:map` command mappings:
|
||||
* `:action {name}`
|
||||
* Execute an action named `NAME`
|
||||
|
||||
For example, here `\r` is mapped to the Reformat Code action:
|
||||
|
||||
:map \r :action ReformatCode<CR>
|
||||
|
||||
|
||||
Contributing
|
||||
------------
|
||||
@@ -162,7 +171,12 @@ in the issue tracker.
|
||||
previous step.
|
||||
|
||||
6. Build IdeaVim and run IntelliJ with IdeaVim enabled using the "IdeaVim" run
|
||||
configuration (use "Run | Run... | IdeaVim").
|
||||
configuration (use "Run | Run... | IdeaVim"). This will launch a spare
|
||||
instance of IntelliJ running the compiled plugin in a sandboxed enviroment.
|
||||
To actually deploy the plugin the recommended way is executing `ant dist`
|
||||
from command line, which will update versions in plugin.xml among other
|
||||
tasks. Install the generated "ideavim.jar" file from
|
||||
"Settings | Plugins | Install plugin from disk".
|
||||
|
||||
7. In order to be able to run tests in your IntelliJ edition uncomment the
|
||||
appropriate lines in the constructor of the `VimTestCase` class.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
version-id:0.38
|
||||
platform-version:135.0
|
||||
idea.download.url=http://download.jetbrains.com/idea/ideaIU-14.0.1.zip
|
||||
version-id:0.44
|
||||
platform-version:143.0
|
||||
idea.download.url=http://download.jetbrains.com/idea/ideaIC-143.380.20.tar.gz
|
||||
build.number=dev
|
||||
|
@@ -105,9 +105,9 @@
|
||||
<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.filename}"/>
|
||||
</unzip>
|
||||
<untar src="${idea}/${idea.filename}" dest="${idea}/unzip" compression="gzip">
|
||||
<cutdirsmapper dirs="1"/>
|
||||
</untar>
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="dist-src, dist-bin" description="Creates the src and bin distribution files"/>
|
||||
@@ -159,7 +159,7 @@
|
||||
|
||||
<target name="test" depends="unzip, clean, prepare-tests">
|
||||
<mkdir dir="${test-reports}"/>
|
||||
<junit fork="true" logfailedtests="false" printsummary="true">
|
||||
<junit fork="true" forkmode="once" logfailedtests="false" printsummary="true">
|
||||
<classpath refid="test.classpath"/>
|
||||
|
||||
<jvmarg value="-Xmx256M"/>
|
||||
@@ -169,6 +169,7 @@
|
||||
<jvmarg value="-Didea.load.plugins.id=IdeaVIM"/>
|
||||
|
||||
<formatter type="plain"/>
|
||||
<formatter type="xml" usefile="true" />
|
||||
|
||||
<batchtest todir="${test-reports}">
|
||||
<fileset dir="${test}">
|
||||
|
@@ -7,9 +7,9 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/idea" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
@@ -1,8 +1,33 @@
|
||||
<idea-plugin url="http://plugins.jetbrains.com/plugin/164">
|
||||
<name>IdeaVim</name>
|
||||
<id>IdeaVIM</id>
|
||||
<change-notes>
|
||||
<![CDATA[
|
||||
<change-notes><![CDATA[
|
||||
<p>0.44:</p>
|
||||
<ul>
|
||||
<li>Fixed typing keys in completion menus and typing with the plugin disabled</li>
|
||||
</ul>
|
||||
<p>0.43:</p>
|
||||
<ul>
|
||||
<li>Fixed running the plugin with Java 6</li>
|
||||
</ul>
|
||||
<p>0.42:</p>
|
||||
<ul>
|
||||
<li>Fixed move commands in read-only files</li>
|
||||
</ul>
|
||||
<p>0.41:</p>
|
||||
<ul>
|
||||
<li>Various bug fixes</li>
|
||||
</ul>
|
||||
<p>0.40:</p>
|
||||
<ul>
|
||||
<li>Support for <code>mapleader</code></li>
|
||||
<li>Support comments in <code>%</code> brace matching</li>
|
||||
<li>Various bug fixes</li>
|
||||
</ul>
|
||||
<p>0.39:</p>
|
||||
<ul>
|
||||
<li>Various bug fixes</li>
|
||||
</ul>
|
||||
<p>0.38:</p>
|
||||
<ul>
|
||||
<li>Support for <code>:action</code> and <code>:actionlist</code> for executing arbitrary IDE actions</li>
|
||||
@@ -21,42 +46,18 @@
|
||||
<li>Fixed visual block selection mode</li>
|
||||
<li>Various bug fixes</li>
|
||||
</ul>
|
||||
<p>0.35:</p>
|
||||
<ul>
|
||||
<li><code>~/.vimrc</code> is no longer read by default, use <code>~/.ideavimrc</code> instead</li>
|
||||
<li>Various bug fixes</li>
|
||||
</ul>
|
||||
<p>0.34:</p>
|
||||
<ul>
|
||||
<li>Various bug fixes</li>
|
||||
</ul>
|
||||
<p>0.33:</p>
|
||||
<ul>
|
||||
<li>Support for <code>:map</code> key mapping commands</li>
|
||||
<li>New keyboard shortcuts handler that doesn't require a separate keymap for Vim emulation</li>
|
||||
<li>Support for <code>:source</code> command</li>
|
||||
<li>Support for <code>:sort</code> command</li>
|
||||
<li>Various bug fixes</li>
|
||||
</ul>
|
||||
<p>0.32:</p>
|
||||
<ul>
|
||||
<li>Fixed API compatibility with IntelliJ platform builds 132.1052+</li>
|
||||
</ul>
|
||||
<p>See also the complete <a href="https://github.com/JetBrains/ideavim/blob/master/CHANGES.md">changelog</a>.</p>
|
||||
]]>
|
||||
</change-notes>
|
||||
<description>
|
||||
<![CDATA[
|
||||
]]></change-notes>
|
||||
<description><![CDATA[
|
||||
<p>Build @VERSION@-@BUILD-NUMBER@</p>
|
||||
<p>Vim emulation plug-in for IDEs based on the IntelliJ platform.</p>
|
||||
<p>IdeaVim supports many Vim features including normal/insert/visual modes, motion keys, deletion/changing, marks, registers, some Ex commands, Vim regexps, configuration via ~/.ideavimrc, macros, window commands, etc.</p>
|
||||
<p>See also:</p>
|
||||
<ul>
|
||||
<li><a href="https://github.com/JetBrains/ideavim">GitHub repository</a> for documentation and contributing</li>
|
||||
<li><a href="http://youtrack.jetbrains.com/issues/VIM">Issue tracker</a> for feature requests and bug reports</li>
|
||||
<li><a href="https://github.com/JetBrains/ideavim">GitHub repository</a>: documentation and contributing</li>
|
||||
<li><a href="http://youtrack.jetbrains.com/issues/VIM">Issue tracker</a>: feature requests and bug reports</li>
|
||||
</ul>
|
||||
]]>
|
||||
</description>
|
||||
]]></description>
|
||||
<version>@VERSION@</version>
|
||||
<vendor>JetBrains</vendor>
|
||||
|
||||
|
@@ -42,13 +42,13 @@ public class EventFacade {
|
||||
|
||||
public void setupTypedActionHandler(@NotNull TypedActionHandler handler) {
|
||||
final TypedAction typedAction = getTypedAction();
|
||||
myOriginalTypedActionHandler = typedAction.getHandler();
|
||||
typedAction.setupHandler(handler);
|
||||
myOriginalTypedActionHandler = typedAction.getRawHandler();
|
||||
typedAction.setupRawHandler(handler);
|
||||
}
|
||||
|
||||
public void restoreTypedActionHandler() {
|
||||
if (myOriginalTypedActionHandler != null) {
|
||||
getTypedAction().setupHandler(myOriginalTypedActionHandler);
|
||||
getTypedAction().setupRawHandler(myOriginalTypedActionHandler);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -111,29 +111,29 @@ public class KeyHandler {
|
||||
editor = InjectedLanguageUtil.getTopLevelEditor(editor);
|
||||
final CommandState editorState = CommandState.getInstance(editor);
|
||||
|
||||
if (allowKeyMappings && handleKeyMapping(editor, key, context)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean isRecording = editorState.isRecording();
|
||||
boolean shouldRecord = true;
|
||||
// If this is a "regular" character keystroke, get the character
|
||||
char chKey = key.getKeyChar() == KeyEvent.CHAR_UNDEFINED ? 0 : key.getKeyChar();
|
||||
|
||||
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)) {
|
||||
final boolean isRecording = editorState.isRecording();
|
||||
boolean shouldRecord = true;
|
||||
|
||||
// Check for command count before key mappings - otherwise e.g. ':map 0 ^' breaks command counts that contain a zero
|
||||
if (isCommandCount(editorState, chKey)) {
|
||||
// Update the count
|
||||
count = count * 10 + (chKey - '0');
|
||||
}
|
||||
else if (allowKeyMappings && handleKeyMapping(editor, key, context)) {
|
||||
return;
|
||||
}
|
||||
// Pressing delete while entering a count "removes" the last digit entered
|
||||
// Unlike the digits, this must be checked *after* checking for key mappings
|
||||
else if (isDeleteCommandCount(key, editorState)) {
|
||||
// "Remove" the last digit sent to us
|
||||
count /= 10;
|
||||
}
|
||||
else if (isEditorReset(key, editorState)) {
|
||||
handleEditorReset(editor, key, context);
|
||||
}
|
||||
// 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) {
|
||||
|
@@ -41,7 +41,7 @@ import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.wm.StatusBar;
|
||||
import com.intellij.openapi.wm.WindowManager;
|
||||
import com.maddyhome.idea.vim.ex.CommandParser;
|
||||
import com.maddyhome.idea.vim.ex.VimScriptParser;
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptParser;
|
||||
import com.maddyhome.idea.vim.group.*;
|
||||
import com.maddyhome.idea.vim.helper.DocumentManager;
|
||||
import com.maddyhome.idea.vim.helper.MacKeyRepeat;
|
||||
@@ -141,7 +141,7 @@ public class VimPlugin implements ApplicationComponent, PersistentStateComponent
|
||||
});
|
||||
|
||||
final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
|
||||
EventFacade.getInstance().setupTypedActionHandler(new VimTypedActionHandler(typedAction.getHandler()));
|
||||
EventFacade.getInstance().setupTypedActionHandler(new VimTypedActionHandler(typedAction.getRawHandler()));
|
||||
|
||||
// Register vim actions in command mode
|
||||
RegisterActions.registerActions();
|
||||
|
@@ -24,6 +24,7 @@ import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actionSystem.TypedActionHandler;
|
||||
import com.maddyhome.idea.vim.helper.EditorDataContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -53,7 +54,7 @@ public class VimTypedActionHandler implements TypedActionHandler {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
handler.handleKey(editor, KeyStroke.getKeyStroke(charTyped), context);
|
||||
handler.handleKey(editor, KeyStroke.getKeyStroke(charTyped), new EditorDataContext(editor));
|
||||
}
|
||||
catch (Throwable e) {
|
||||
logger.error(e);
|
||||
|
@@ -24,6 +24,7 @@ import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationListener;
|
||||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.keymap.KeymapUtil;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
@@ -34,6 +35,7 @@ import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.action.change.insert.InsertExitModeAction;
|
||||
import com.maddyhome.idea.vim.command.CommandState;
|
||||
import com.maddyhome.idea.vim.helper.EditorData;
|
||||
import com.maddyhome.idea.vim.helper.EditorDataContext;
|
||||
import com.maddyhome.idea.vim.key.ShortcutOwner;
|
||||
import com.maddyhome.idea.vim.ui.VimEmulationConfigurable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -83,6 +85,8 @@ public class VimShortcutKeyAction extends AnAction implements DumbAware {
|
||||
.addAll(getKeyStrokes(VK_DOWN, 0))
|
||||
.build();
|
||||
|
||||
private static final Logger ourLogger = Logger.getInstance(VimShortcutKeyAction.class.getName());
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
final Editor editor = getEditor(e);
|
||||
@@ -93,7 +97,18 @@ public class VimShortcutKeyAction extends AnAction implements DumbAware {
|
||||
notifyAboutShortcutConflict(keyStroke);
|
||||
}
|
||||
// Should we use InjectedLanguageUtil.getTopLevelEditor(editor) here, as we did in former EditorKeyHandler?
|
||||
KeyHandler.getInstance().handleKey(editor, keyStroke, e.getDataContext());
|
||||
// Run key handler later to restore input events sequence due to VimTypedActionHandler
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
KeyHandler.getInstance().handleKey(editor, keyStroke, new EditorDataContext(editor));
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
ourLogger.error(throwable);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -36,7 +36,7 @@ public class MotionNextTabAction extends MotionEditorAction {
|
||||
|
||||
private static class Handler extends MotionEditorActionHandler {
|
||||
public int getOffset(@NotNull final Editor editor, @NotNull final DataContext context, final int count, final int rawCount, final Argument argument) {
|
||||
return VimPlugin.getMotion().moveCaretGotoNextTab(editor, context);
|
||||
return VimPlugin.getMotion().moveCaretGotoNextTab(editor, context, rawCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ public class MotionPreviousTabAction extends MotionEditorAction {
|
||||
|
||||
private static class Handler extends MotionEditorActionHandler {
|
||||
public int getOffset(@NotNull final Editor editor, @NotNull final DataContext context, final int count, final int rawCount, final Argument argument) {
|
||||
return VimPlugin.getMotion().moveCaretGotoPreviousTab(editor, context);
|
||||
return VimPlugin.getMotion().moveCaretGotoPreviousTab(editor, context, rawCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -85,6 +85,11 @@ public class CommandState {
|
||||
return state.getMode() == Mode.VISUAL && state.getSubMode() == SubMode.VISUAL_CHARACTER;
|
||||
}
|
||||
|
||||
public static boolean inVisualBlockMode(@Nullable Editor editor) {
|
||||
final CommandState state = getInstance(editor);
|
||||
return state.getMode() == Mode.VISUAL && state.getSubMode() == SubMode.VISUAL_BLOCK;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Command getCommand() {
|
||||
return myCommand;
|
||||
@@ -311,7 +316,7 @@ public class CommandState {
|
||||
VimPlugin.showMode(msg.toString());
|
||||
}
|
||||
|
||||
public static enum Mode {
|
||||
public enum Mode {
|
||||
COMMAND,
|
||||
INSERT,
|
||||
REPLACE,
|
||||
@@ -320,7 +325,7 @@ public class CommandState {
|
||||
EX_ENTRY
|
||||
}
|
||||
|
||||
public static enum SubMode {
|
||||
public enum SubMode {
|
||||
NONE,
|
||||
SINGLE_COMMAND,
|
||||
VISUAL_CHARACTER,
|
||||
|
@@ -79,6 +79,7 @@ public class CommandParser {
|
||||
new DumpLineHandler();
|
||||
new EditFileHandler();
|
||||
new ActionHandler();
|
||||
new EchoHandler();
|
||||
new ExitHandler();
|
||||
new FindClassHandler();
|
||||
new FindFileHandler();
|
||||
@@ -89,6 +90,7 @@ public class CommandParser {
|
||||
new HistoryHandler();
|
||||
new JoinLinesHandler();
|
||||
new JumpsHandler();
|
||||
new LetHandler();
|
||||
new MapHandler();
|
||||
new MarkHandler();
|
||||
new MarksHandler();
|
||||
@@ -301,7 +303,7 @@ public class CommandParser {
|
||||
state = STATE_RANGE_MARK;
|
||||
}
|
||||
else if (ch == '+' || ch == '-') {
|
||||
location.append('0');
|
||||
location.append('.');
|
||||
state = STATE_RANGE_OFFSET;
|
||||
}
|
||||
else if (ch == '\\') {
|
||||
|
@@ -56,7 +56,7 @@ public class ExOutputModel {
|
||||
public void clear() {
|
||||
myText = null;
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
ExOutputPanel.getInstance(myEditor).deactivate();
|
||||
ExOutputPanel.getInstance(myEditor).deactivate(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
54
src/com/maddyhome/idea/vim/ex/handler/EchoHandler.java
Normal file
54
src/com/maddyhome/idea/vim/ex/handler/EchoHandler.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2015 The IdeaVim authors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim.ex.handler;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler;
|
||||
import com.maddyhome.idea.vim.ex.ExCommand;
|
||||
import com.maddyhome.idea.vim.ex.ExException;
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel;
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptGlobalEnvironment;
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
public class EchoHandler extends CommandHandler {
|
||||
|
||||
public EchoHandler() {
|
||||
super("ec", "ho", RANGE_FORBIDDEN | ARGUMENT_OPTIONAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Editor editor, @NotNull DataContext context,
|
||||
@NotNull ExCommand cmd) throws ExException {
|
||||
final String argument = cmd.getArgument();
|
||||
final VimScriptGlobalEnvironment env = VimScriptGlobalEnvironment.getInstance();
|
||||
final Map<String, Object> globals = env.getVariables();
|
||||
final Object value = VimScriptParser.evaluate(argument, globals);
|
||||
final String text = VimScriptParser.expressionToString(value) + "\n";
|
||||
ExOutputModel.getInstance(editor).output(text);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
78
src/com/maddyhome/idea/vim/ex/handler/LetHandler.java
Normal file
78
src/com/maddyhome/idea/vim/ex/handler/LetHandler.java
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2015 The IdeaVim authors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim.ex.handler;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler;
|
||||
import com.maddyhome.idea.vim.ex.ExCommand;
|
||||
import com.maddyhome.idea.vim.ex.ExException;
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptCommandHandler;
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptGlobalEnvironment;
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
public class LetHandler extends CommandHandler implements VimScriptCommandHandler {
|
||||
private static Pattern SIMPLE_ASSIGNMENT = Pattern.compile("([A-Za-z_][A-Za-z_0-9]*)[ \\t]*=[ \\t]*(.*)");
|
||||
|
||||
public LetHandler() {
|
||||
super("let", "", RANGE_FORBIDDEN | ARGUMENT_OPTIONAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Editor editor, @NotNull DataContext context,
|
||||
@NotNull ExCommand cmd) throws ExException {
|
||||
execute(cmd);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull ExCommand cmd) throws ExException {
|
||||
final String argument = cmd.getArgument();
|
||||
if (argument.trim().isEmpty()) {
|
||||
showVariables();
|
||||
}
|
||||
else {
|
||||
final Matcher matcher = SIMPLE_ASSIGNMENT.matcher(argument);
|
||||
if (matcher.matches()) {
|
||||
final String name = matcher.group(1);
|
||||
// TODO: Check that 'name' is global
|
||||
final String expression = matcher.group(2);
|
||||
final VimScriptGlobalEnvironment env = VimScriptGlobalEnvironment.getInstance();
|
||||
final Map<String, Object> globals = env.getVariables();
|
||||
final Object value = VimScriptParser.evaluate(expression, globals);
|
||||
globals.put(name, value);
|
||||
}
|
||||
else {
|
||||
throw new ExException("Only simple '=' assignments are supported in 'let' expressions");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showVariables() throws ExException {
|
||||
throw new ExException("'let' without arguments is not supported yet");
|
||||
}
|
||||
}
|
@@ -24,6 +24,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.command.MappingMode;
|
||||
import com.maddyhome.idea.vim.ex.*;
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptCommandHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@@ -23,7 +23,7 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler;
|
||||
import com.maddyhome.idea.vim.ex.ExCommand;
|
||||
import com.maddyhome.idea.vim.ex.ExException;
|
||||
import com.maddyhome.idea.vim.ex.VimScriptCommandHandler;
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptCommandHandler;
|
||||
import com.maddyhome.idea.vim.option.Options;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@@ -21,6 +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.ex.*;
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptCommandHandler;
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
|
@@ -16,8 +16,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim.ex;
|
||||
package com.maddyhome.idea.vim.ex.vimscript;
|
||||
|
||||
import com.maddyhome.idea.vim.ex.ExCommand;
|
||||
import com.maddyhome.idea.vim.ex.ExException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2015 The IdeaVim authors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim.ex.vimscript;
|
||||
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
public class VimScriptGlobalEnvironment {
|
||||
private static final VimScriptGlobalEnvironment ourInstance = new VimScriptGlobalEnvironment();
|
||||
|
||||
private final Map<String, Object> myVariables = new HashMap<String, Object>();
|
||||
|
||||
private VimScriptGlobalEnvironment() {}
|
||||
|
||||
@NotNull
|
||||
public static VimScriptGlobalEnvironment getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<String, Object> getVariables() {
|
||||
return myVariables;
|
||||
}
|
||||
}
|
@@ -16,8 +16,12 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim.ex;
|
||||
package com.maddyhome.idea.vim.ex.vimscript;
|
||||
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler;
|
||||
import com.maddyhome.idea.vim.ex.CommandParser;
|
||||
import com.maddyhome.idea.vim.ex.ExCommand;
|
||||
import com.maddyhome.idea.vim.ex.ExException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -25,6 +29,8 @@ import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
@@ -34,6 +40,9 @@ public class VimScriptParser {
|
||||
public static final String[] VIMRC_FILES = {".ideavimrc", "_ideavimrc"};
|
||||
public static final int BUFSIZE = 4096;
|
||||
private static final Pattern EOL_SPLIT_PATTERN = Pattern.compile(" *(\r\n|\n)+ *");
|
||||
private static final Pattern DOUBLE_QUOTED_STRING = Pattern.compile("\"([^\"]*)\"");
|
||||
private static final Pattern SINGLE_QUOTED_STRING = Pattern.compile("'([^']*)'");
|
||||
private static final Pattern REFERENCE_EXPR = Pattern.compile("([A-Za-z_][A-Za-z_0-9]*)");
|
||||
|
||||
private VimScriptParser() {
|
||||
}
|
||||
@@ -86,6 +95,42 @@ public class VimScriptParser {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Object evaluate(@NotNull String expression, @NotNull Map<String, Object> globals) throws ExException {
|
||||
// This evaluator is very basic, no proper parsing whatsoever. It is here as the very first step necessary to
|
||||
// support mapleader, VIM-650. See also VIM-669.
|
||||
Matcher m;
|
||||
m = DOUBLE_QUOTED_STRING.matcher(expression);
|
||||
if (m.matches()) {
|
||||
return m.group(1);
|
||||
}
|
||||
m = SINGLE_QUOTED_STRING.matcher(expression);
|
||||
if (m.matches()) {
|
||||
return m.group(1);
|
||||
}
|
||||
m = REFERENCE_EXPR.matcher(expression);
|
||||
if (m.matches()) {
|
||||
final String name = m.group(1);
|
||||
final Object value = globals.get(name);
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
else {
|
||||
throw new ExException(String.format("Undefined variable: %s", name));
|
||||
}
|
||||
}
|
||||
throw new ExException(String.format("Invalid expression: %s", expression));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String expressionToString(@NotNull Object value) throws ExException {
|
||||
// TODO: Return meaningful value representations
|
||||
if (value instanceof String) {
|
||||
return (String)value;
|
||||
}
|
||||
throw new ExException(String.format("Cannot convert '%s' to string", value));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String readFile(@NotNull File file) throws IOException {
|
||||
final BufferedReader reader = new BufferedReader(new FileReader(file));
|
@@ -17,7 +17,9 @@
|
||||
*/
|
||||
package com.maddyhome.idea.vim.group;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
@@ -788,6 +790,9 @@ public class ChangeGroup {
|
||||
MotionGroup.moveCaret(editor, VimPlugin.getMotion().moveCaretToLineEnd(editor, startLine, true));
|
||||
for (int i = 1; i < count; i++) {
|
||||
int start = VimPlugin.getMotion().moveCaretToLineEnd(editor);
|
||||
int trailingWhitespaceStart = VimPlugin.getMotion().moveCaretToLineEndSkipLeading(editor);
|
||||
boolean hasTrailingWhitespace = start != trailingWhitespaceStart + 1;
|
||||
|
||||
MotionGroup.moveCaret(editor, start);
|
||||
int offset;
|
||||
if (spaces) {
|
||||
@@ -797,7 +802,7 @@ public class ChangeGroup {
|
||||
offset = VimPlugin.getMotion().moveCaretToLineStartOffset(editor);
|
||||
}
|
||||
deleteText(editor, new TextRange(editor.getCaretModel().getOffset(), offset), null);
|
||||
if (spaces) {
|
||||
if (spaces && !hasTrailingWhitespace) {
|
||||
insertText(editor, start, " ");
|
||||
MotionGroup.moveCaret(editor, VimPlugin.getMotion().moveCaretHorizontal(editor, -1, false));
|
||||
}
|
||||
@@ -1290,18 +1295,14 @@ public class ChangeGroup {
|
||||
end = start;
|
||||
start = t;
|
||||
}
|
||||
end = EditorHelper.normalizeOffset(editor, end);
|
||||
|
||||
CharSequence chars = editor.getDocument().getCharsSequence();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = start; i < end; i++) {
|
||||
if (i >= chars.length()) {
|
||||
break;
|
||||
}
|
||||
|
||||
char ch = CharacterHelper.changeCase(chars.charAt(i), type);
|
||||
if (ch != chars.charAt(i)) {
|
||||
replaceText(editor, i, i + 1, Character.toString(ch));
|
||||
}
|
||||
sb.append(CharacterHelper.changeCase(chars.charAt(i), type));
|
||||
}
|
||||
replaceText(editor, start, end, sb.toString());
|
||||
}
|
||||
|
||||
public void autoIndentLines(@NotNull DataContext context) {
|
||||
@@ -1345,12 +1346,6 @@ public class ChangeGroup {
|
||||
|
||||
int sline = editor.offsetToLogicalPosition(range.getStartOffset()).line;
|
||||
int eline = editor.offsetToLogicalPosition(range.getEndOffset()).line;
|
||||
int eoff = EditorHelper.getLineStartForOffset(editor, range.getEndOffset());
|
||||
boolean elineIsEmpty = EditorHelper.getLineLength(editor, eline) == 0;
|
||||
// Skip an empty ending line
|
||||
if (eoff == range.getEndOffset() && elineIsEmpty) {
|
||||
eline--;
|
||||
}
|
||||
|
||||
if (range.isMultiple()) {
|
||||
int col = editor.offsetToLogicalPosition(range.getStartOffset()).column;
|
||||
@@ -1410,10 +1405,11 @@ public class ChangeGroup {
|
||||
// Shift non-blockwise selection
|
||||
for (int l = sline; l <= eline; l++) {
|
||||
int soff = EditorHelper.getLineStartOffset(editor, l);
|
||||
int eoff = EditorHelper.getLineEndOffset(editor, l, true);
|
||||
int woff = VimPlugin.getMotion().moveCaretToLineStartSkipLeading(editor, l);
|
||||
int col = editor.offsetToVisualPosition(woff).column;
|
||||
int newCol = Math.max(0, col + dir * indentSize * count);
|
||||
if (dir == 1 || col > 0) {
|
||||
if (col > 0 || soff != eoff) {
|
||||
StringBuilder space = new StringBuilder();
|
||||
int tabCnt = 0;
|
||||
int spcCnt;
|
||||
@@ -1550,7 +1546,7 @@ public class ChangeGroup {
|
||||
private boolean sortTextRange(@NotNull Editor editor, int start, int end,
|
||||
@NotNull Comparator<String> lineComparator) {
|
||||
final String selectedText = editor.getDocument().getText(new TextRangeInterval(start, end));
|
||||
final List<String> lines = Arrays.asList(StringUtil.splitByLines(selectedText));
|
||||
final List<String> lines = Lists.newArrayList(Splitter.on("\n").split(selectedText));
|
||||
if (lines.size() < 1) {
|
||||
return false;
|
||||
}
|
||||
|
@@ -87,7 +87,7 @@ public class EditorGroup {
|
||||
public void editorReleased(@NotNull EditorFactoryEvent event) {
|
||||
final Editor editor = event.getEditor();
|
||||
deinitLineNumbers(editor);
|
||||
EditorData.uninitializeEditor(editor);
|
||||
EditorData.unInitializeEditor(editor);
|
||||
VimPlugin.getKey().unregisterShortcutKeys(editor);
|
||||
editor.getSettings().setAnimatedScrolling(isAnimatedScrolling);
|
||||
editor.getSettings().setRefrainFromScrolling(isRefrainFromScrolling);
|
||||
@@ -136,12 +136,27 @@ public class EditorGroup {
|
||||
}
|
||||
|
||||
private void updateLineNumbers(@NotNull Editor editor) {
|
||||
if (!EditorData.isFileEditor(editor)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Options options = Options.getInstance();
|
||||
final boolean relativeLineNumber = options.isSet(Options.RELATIVE_NUMBER);
|
||||
final boolean lineNumber = options.isSet(Options.NUMBER);
|
||||
|
||||
final EditorSettings settings = editor.getSettings();
|
||||
settings.setLineNumbersShown(lineNumber && !relativeLineNumber);
|
||||
final boolean showEditorLineNumbers = (EditorData.isLineNumbersShown(editor) || lineNumber) && !relativeLineNumber;
|
||||
|
||||
if (settings.isLineNumbersShown() ^ showEditorLineNumbers) {
|
||||
// Update line numbers later since it may be called from a caret listener
|
||||
// on the caret move and it may move the caret internally
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
settings.setLineNumbersShown(showEditorLineNumbers);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (relativeLineNumber) {
|
||||
final EditorGutter gutter = editor.getGutter();
|
||||
|
@@ -25,6 +25,8 @@ import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManagerAdapter;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
|
||||
import com.intellij.openapi.fileEditor.TextEditor;
|
||||
import com.intellij.openapi.fileEditor.impl.EditorTabbedContainer;
|
||||
import com.intellij.openapi.fileEditor.impl.EditorWindow;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.maddyhome.idea.vim.EventFacade;
|
||||
@@ -140,7 +142,7 @@ public class MotionGroup {
|
||||
*/
|
||||
private void processMouseClick(@NotNull Editor editor, @NotNull MouseEvent event) {
|
||||
if (ExEntryPanel.getInstance().isActive()) {
|
||||
ExEntryPanel.getInstance().deactivate();
|
||||
ExEntryPanel.getInstance().deactivate(false);
|
||||
}
|
||||
|
||||
ExOutputModel.getInstance(editor).clear();
|
||||
@@ -203,7 +205,7 @@ public class MotionGroup {
|
||||
*/
|
||||
private void processLineSelection(@NotNull Editor editor, boolean update) {
|
||||
if (ExEntryPanel.getInstance().isActive()) {
|
||||
ExEntryPanel.getInstance().deactivate();
|
||||
ExEntryPanel.getInstance().deactivate(false);
|
||||
}
|
||||
|
||||
ExOutputModel.getInstance(editor).clear();
|
||||
@@ -233,7 +235,7 @@ public class MotionGroup {
|
||||
|
||||
private void processMouseReleased(@NotNull Editor editor, @NotNull CommandState.SubMode mode, int startOff, int endOff) {
|
||||
if (ExEntryPanel.getInstance().isActive()) {
|
||||
ExEntryPanel.getInstance().deactivate();
|
||||
ExEntryPanel.getInstance().deactivate(false);
|
||||
}
|
||||
|
||||
ExOutputModel.getInstance(editor).clear();
|
||||
@@ -1043,6 +1045,11 @@ public class MotionGroup {
|
||||
return EditorHelper.getLeadingCharacterOffset(editor, line);
|
||||
}
|
||||
|
||||
public int moveCaretToLineEndSkipLeading(@NotNull Editor editor) {
|
||||
int logicalLine = editor.getCaretModel().getLogicalPosition().line;
|
||||
return moveCaretToLineEndSkipLeading(editor, logicalLine);
|
||||
}
|
||||
|
||||
public int moveCaretToLineEndSkipLeading(@NotNull Editor editor, int line) {
|
||||
int start = EditorHelper.getLineStartOffset(editor, line);
|
||||
int end = EditorHelper.getLineEndOffset(editor, line, true);
|
||||
@@ -1229,17 +1236,32 @@ public class MotionGroup {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int moveCaretGotoPreviousTab(@NotNull Editor editor, @NotNull DataContext context) {
|
||||
final AnAction previousTab = ActionManager.getInstance().getAction("PreviousTab");
|
||||
final AnActionEvent e = new AnActionEvent(null, context, "", new Presentation(), ActionManager.getInstance(), 0);
|
||||
previousTab.actionPerformed(e);
|
||||
/**
|
||||
* If 'absolute' is true, then set tab index to 'value', otherwise add 'value' to tab index with wraparound.
|
||||
*/
|
||||
private void switchEditorTab(@Nullable EditorWindow editorWindow, int value, boolean absolute) {
|
||||
if (editorWindow != null) {
|
||||
final EditorTabbedContainer tabbedPane = editorWindow.getTabbedPane();
|
||||
if (tabbedPane != null) {
|
||||
if (absolute) {
|
||||
tabbedPane.setSelectedIndex(value);
|
||||
}
|
||||
else {
|
||||
int tabIndex = (value + tabbedPane.getSelectedIndex()) % tabbedPane.getTabCount();
|
||||
tabbedPane.setSelectedIndex(tabIndex < 0 ? tabIndex + tabbedPane.getTabCount() : tabIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int moveCaretGotoPreviousTab(@NotNull Editor editor, @NotNull DataContext context, int rawCount) {
|
||||
switchEditorTab(EditorWindow.DATA_KEY.getData(context), rawCount >= 1 ? -rawCount : -1, false);
|
||||
return editor.getCaretModel().getOffset();
|
||||
}
|
||||
|
||||
public int moveCaretGotoNextTab(@NotNull Editor editor, @NotNull DataContext context) {
|
||||
final AnAction nextTab = ActionManager.getInstance().getAction("NextTab");
|
||||
final AnActionEvent e = new AnActionEvent(null, context, "", new Presentation(), ActionManager.getInstance(), 0);
|
||||
nextTab.actionPerformed(e);
|
||||
public int moveCaretGotoNextTab(@NotNull Editor editor, @NotNull DataContext context, int rawCount) {
|
||||
final boolean absolute = rawCount >= 1;
|
||||
switchEditorTab(EditorWindow.DATA_KEY.getData(context), absolute ? rawCount - 1 : 1, absolute);
|
||||
return editor.getCaretModel().getOffset();
|
||||
}
|
||||
|
||||
@@ -1583,29 +1605,8 @@ public class MotionGroup {
|
||||
|
||||
@NotNull
|
||||
public TextRange getVisualRange(@NotNull Editor editor) {
|
||||
final TextRange res = new TextRange(editor.getSelectionModel().getBlockSelectionStarts(),
|
||||
return new TextRange(editor.getSelectionModel().getBlockSelectionStarts(),
|
||||
editor.getSelectionModel().getBlockSelectionEnds());
|
||||
|
||||
final CommandState.SubMode subMode = CommandState.getInstance(editor).getSubMode();
|
||||
if (subMode == CommandState.SubMode.VISUAL_BLOCK) {
|
||||
final int[] ends = res.getEndOffsets();
|
||||
|
||||
// If the last left/right motion was the $ command, simulate each line being selected to end-of-line
|
||||
if (EditorData.getLastColumn(editor) >= MotionGroup.LAST_COLUMN) {
|
||||
final int[] starts = res.getStartOffsets();
|
||||
for (int i = 0; i < starts.length; i++) {
|
||||
if (ends[i] > starts[i]) {
|
||||
ends[i] = EditorHelper.getLineEndForOffset(editor, starts[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < ends.length; ++i) {
|
||||
ends[i] = EditorHelper.normalizeOffset(editor, ends[i] + 1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -1613,6 +1614,10 @@ public class MotionGroup {
|
||||
return new TextRange(visualStart, visualEnd);
|
||||
}
|
||||
|
||||
public void updateSelection(@NotNull Editor editor) {
|
||||
updateSelection(editor, visualEnd);
|
||||
}
|
||||
|
||||
private void updateSelection(@NotNull Editor editor, int offset) {
|
||||
visualEnd = offset;
|
||||
visualOffset = offset;
|
||||
@@ -1643,9 +1648,28 @@ public class MotionGroup {
|
||||
editor.getSelectionModel().setSelection(start, end);
|
||||
}
|
||||
else if (subMode == CommandState.SubMode.VISUAL_BLOCK) {
|
||||
final LogicalPosition lineStart = editor.offsetToLogicalPosition(start);
|
||||
final LogicalPosition lineEnd = editor.offsetToLogicalPosition(end);
|
||||
editor.getSelectionModel().setBlockSelection(lineStart, lineEnd);
|
||||
LogicalPosition blockStart = editor.offsetToLogicalPosition(start);
|
||||
LogicalPosition blockEnd = editor.offsetToLogicalPosition(end);
|
||||
if (blockStart.column < blockEnd.column) {
|
||||
blockEnd = new LogicalPosition(blockEnd.line, blockEnd.column + 1);
|
||||
}
|
||||
else {
|
||||
blockStart = new LogicalPosition(blockStart.line, blockStart.column + 1);
|
||||
}
|
||||
editor.getSelectionModel().setBlockSelection(blockStart, blockEnd);
|
||||
|
||||
for (Caret caret : editor.getCaretModel().getAllCarets()) {
|
||||
int line = caret.getLogicalPosition().line;
|
||||
int lineEndOffset = EditorHelper.getLineEndOffset(editor, line, true);
|
||||
|
||||
if (EditorData.getLastColumn(editor) >= MotionGroup.LAST_COLUMN) {
|
||||
caret.setSelection(caret.getSelectionStart(), lineEndOffset);
|
||||
}
|
||||
if (!EditorHelper.isLineEmpty(editor, line, false)) {
|
||||
caret.moveToOffset(caret.getSelectionEnd() - 1);
|
||||
}
|
||||
}
|
||||
editor.getCaretModel().moveToOffset(end);
|
||||
}
|
||||
|
||||
VimPlugin.getMark().setVisualSelectionMarks(editor, new TextRange(start, end));
|
||||
@@ -1700,7 +1724,7 @@ public class MotionGroup {
|
||||
public static class MotionEditorChange extends FileEditorManagerAdapter {
|
||||
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
|
||||
if (ExEntryPanel.getInstance().isActive()) {
|
||||
ExEntryPanel.getInstance().deactivate();
|
||||
ExEntryPanel.getInstance().deactivate(false);
|
||||
}
|
||||
final FileEditor fileEditor = event.getOldEditor();
|
||||
if (fileEditor instanceof TextEditor) {
|
||||
@@ -1728,7 +1752,6 @@ public class MotionGroup {
|
||||
for (Editor e : EditorFactory.getInstance().getEditors(editor.getDocument())) {
|
||||
if (!e.equals(editor)) {
|
||||
e.getSelectionModel().setSelection(newRange.getStartOffset(), newRange.getEndOffset());
|
||||
e.getCaretModel().moveToOffset(editor.getCaretModel().getOffset());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,13 +19,8 @@
|
||||
package com.maddyhome.idea.vim.group;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.text.CharSequenceReader;
|
||||
import com.maddyhome.idea.vim.KeyHandler;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
@@ -35,7 +30,7 @@ import com.maddyhome.idea.vim.command.MappingMode;
|
||||
import com.maddyhome.idea.vim.common.TextRange;
|
||||
import com.maddyhome.idea.vim.ex.CommandParser;
|
||||
import com.maddyhome.idea.vim.ex.ExException;
|
||||
import com.maddyhome.idea.vim.helper.EditorData;
|
||||
import com.maddyhome.idea.vim.helper.UiHelper;
|
||||
import com.maddyhome.idea.vim.ui.ExEntryPanel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -69,17 +64,7 @@ public class ProcessGroup {
|
||||
|
||||
public String endSearchCommand(@NotNull final Editor editor, @NotNull DataContext context) {
|
||||
ExEntryPanel panel = ExEntryPanel.getInstance();
|
||||
panel.deactivate();
|
||||
|
||||
final Project project = PlatformDataKeys.PROJECT.getData(context); // API change - don't merge
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
VirtualFile vf = EditorData.getVirtualFile(editor);
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode() && project != null && vf != null) {
|
||||
FileEditorManager.getInstance(project).openFile(vf, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
panel.deactivate(true);
|
||||
|
||||
record(editor, panel.getText());
|
||||
return panel.getText();
|
||||
@@ -103,7 +88,7 @@ public class ProcessGroup {
|
||||
|
||||
ExEntryPanel panel = ExEntryPanel.getInstance();
|
||||
if (panel.isActive()) {
|
||||
panel.requestFocus();
|
||||
UiHelper.requestFocus(panel);
|
||||
panel.handleKey(stroke);
|
||||
|
||||
return true;
|
||||
@@ -117,7 +102,7 @@ public class ProcessGroup {
|
||||
|
||||
public boolean processExEntry(@NotNull final Editor editor, @NotNull final DataContext context) {
|
||||
ExEntryPanel panel = ExEntryPanel.getInstance();
|
||||
panel.deactivate();
|
||||
panel.deactivate(true);
|
||||
boolean res = true;
|
||||
int flags = 0;
|
||||
try {
|
||||
@@ -153,23 +138,6 @@ public class ProcessGroup {
|
||||
VimPlugin.indicateError();
|
||||
res = false;
|
||||
}
|
||||
finally {
|
||||
final int flg = flags;
|
||||
final Project project = PlatformDataKeys.PROJECT.getData(context); // API change - don't merge
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
//editor.getContentComponent().requestFocus();
|
||||
// Reopening the file was the only way I could solve the focus problem introduced in IDEA at
|
||||
// version 1050.
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode() && (flg & CommandParser.RES_DONT_REOPEN) == 0) {
|
||||
VirtualFile vf = EditorData.getVirtualFile(editor);
|
||||
if (project != null && vf != null) {
|
||||
FileEditorManager.getInstance(project).openFile(vf, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -178,17 +146,7 @@ public class ProcessGroup {
|
||||
CommandState.getInstance(editor).popState();
|
||||
KeyHandler.getInstance().reset(editor);
|
||||
ExEntryPanel panel = ExEntryPanel.getInstance();
|
||||
panel.deactivate();
|
||||
final Project project = PlatformDataKeys.PROJECT.getData(context); // API change - don't merge
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
//editor.getContentComponent().requestFocus();
|
||||
VirtualFile vf = EditorData.getVirtualFile(editor);
|
||||
if (project != null && vf != null) {
|
||||
FileEditorManager.getInstance(project).openFile(vf, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
panel.deactivate(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -34,6 +34,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
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.CharacterPosition;
|
||||
import com.maddyhome.idea.vim.common.TextRange;
|
||||
@@ -93,6 +94,11 @@ public class SearchGroup {
|
||||
public boolean searchAndReplace(@NotNull Editor editor, @NotNull LineRange range, @NotNull String excmd, String exarg) {
|
||||
boolean res = true;
|
||||
|
||||
// Explicitly exit visual mode here, so that visual mode marks don't change when we move the cursor to a match.
|
||||
if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) {
|
||||
VimPlugin.getMotion().exitVisual(editor);
|
||||
}
|
||||
|
||||
CharPointer cmd = new CharPointer(new StringBuffer(exarg));
|
||||
//sub_nsubs = 0;
|
||||
//sub_nlines = 0;
|
||||
@@ -375,6 +381,7 @@ public class SearchGroup {
|
||||
lastMatch = startoff;
|
||||
newpos = EditorHelper.offsetToCharacterPosition(editor, newend);
|
||||
|
||||
lnum += newpos.line - endpos.line;
|
||||
line2 += newpos.line - endpos.line;
|
||||
}
|
||||
}
|
||||
|
@@ -25,11 +25,13 @@ import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.command.CommandState;
|
||||
import com.maddyhome.idea.vim.command.SelectionType;
|
||||
import com.maddyhome.idea.vim.command.VisualChange;
|
||||
import com.maddyhome.idea.vim.common.TextRange;
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel;
|
||||
import com.maddyhome.idea.vim.group.MotionGroup;
|
||||
import com.maddyhome.idea.vim.ui.ExOutputPanel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -57,7 +59,7 @@ public class EditorData {
|
||||
*
|
||||
* @param editor The editor to cleanup
|
||||
*/
|
||||
public static void uninitializeEditor(@NotNull Editor editor) {
|
||||
public static void unInitializeEditor(@NotNull Editor editor) {
|
||||
if (logger.isDebugEnabled()) logger.debug("editor closed: " + editor);
|
||||
editor.putUserData(COMMAND_STATE, null);
|
||||
editor.putUserData(LAST_HIGHLIGHTS, null);
|
||||
@@ -71,7 +73,7 @@ public class EditorData {
|
||||
/**
|
||||
* This gets the last column the cursor was in for the editor.
|
||||
*
|
||||
* @param editor The editr to get the last column from
|
||||
* @param editor The editor to get the last column from
|
||||
* @return Returns the last column as set by {@link #setLastColumn} or the current cursor column
|
||||
*/
|
||||
public static int getLastColumn(@NotNull Editor editor) {
|
||||
@@ -91,9 +93,16 @@ public class EditorData {
|
||||
* @param editor The editor
|
||||
*/
|
||||
public static void setLastColumn(@NotNull Editor editor, int col) {
|
||||
boolean previousWasDollar = getLastColumn(editor) >= MotionGroup.LAST_COLUMN;
|
||||
boolean currentIsDollar = col >= MotionGroup.LAST_COLUMN;
|
||||
|
||||
editor.putUserData(LAST_COLUMN, col);
|
||||
int t = getLastColumn(editor);
|
||||
if (logger.isDebugEnabled()) logger.debug("setLastColumn(" + col + ") is now " + t);
|
||||
|
||||
if (previousWasDollar != currentIsDollar && CommandState.inVisualBlockMode(editor)) {
|
||||
VimPlugin.getMotion().updateSelection(editor);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -276,8 +285,8 @@ public class EditorData {
|
||||
// coded such that two keys with the same name are treated as different keys - oh well.
|
||||
// This code will work as long as the key I need is the first one in the ConsoleViewImpl.
|
||||
Class cvi = Class.forName("com.intellij.execution.impl.ConsoleViewImpl");
|
||||
Field[] flds = cvi.getDeclaredFields();
|
||||
for (Field f : flds) {
|
||||
Field[] fields = cvi.getDeclaredFields();
|
||||
for (Field f : fields) {
|
||||
if (f.getType().equals(Key.class)) {
|
||||
f.setAccessible(true);
|
||||
CONSOLE_VIEW_IN_EDITOR_VIEW = (Key)f.get(null);
|
||||
@@ -294,7 +303,7 @@ public class EditorData {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if editor is file editor, also it takes into account that editor can be placed in editors hierarhy
|
||||
* Checks if editor is file editor, also it takes into account that editor can be placed in editors hierarchy
|
||||
*/
|
||||
public static boolean isFileEditor(@NotNull Editor editor){
|
||||
final VirtualFile virtualFile = EditorData.getVirtualFile(editor);
|
||||
|
@@ -52,7 +52,7 @@ public class PsiHelper {
|
||||
StructureViewBuilder structureViewBuilder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(file);
|
||||
if (!(structureViewBuilder instanceof TreeBasedStructureViewBuilder)) return -1;
|
||||
TreeBasedStructureViewBuilder builder = (TreeBasedStructureViewBuilder)structureViewBuilder;
|
||||
StructureViewModel model = builder.createStructureViewModel();
|
||||
StructureViewModel model = builder.createStructureViewModel(editor);
|
||||
|
||||
TIntArrayList navigationOffsets = new TIntArrayList();
|
||||
addNavigationElements(model.getRoot(), navigationOffsets, isStart);
|
||||
@@ -109,7 +109,7 @@ public class PsiHelper {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiFile getFile(@NotNull Editor editor) {
|
||||
public static PsiFile getFile(@NotNull Editor editor) {
|
||||
VirtualFile vf = EditorData.getVirtualFile(editor);
|
||||
if (vf != null) {
|
||||
Project proj = editor.getProject();
|
||||
|
@@ -18,9 +18,14 @@
|
||||
|
||||
package com.maddyhome.idea.vim.helper;
|
||||
|
||||
import com.intellij.lang.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.maddyhome.idea.vim.common.TextRange;
|
||||
import com.maddyhome.idea.vim.option.ListOption;
|
||||
import com.maddyhome.idea.vim.option.OptionChangeEvent;
|
||||
@@ -143,6 +148,42 @@ public class SearchHelper {
|
||||
return new TextRange(bstart, bend);
|
||||
}
|
||||
|
||||
private static int findMatchingBlockCommentPair(@NotNull PsiComment comment, int pos, @Nullable String prefix,
|
||||
@Nullable String suffix) {
|
||||
if (prefix != null && suffix != null) {
|
||||
final String commentText = comment.getText();
|
||||
if (commentText.startsWith(prefix) && commentText.endsWith(suffix)) {
|
||||
final int endOffset = comment.getTextOffset() + comment.getTextLength();
|
||||
if (pos < comment.getTextOffset() + prefix.length()) {
|
||||
return endOffset;
|
||||
}
|
||||
else if (pos >= endOffset - suffix.length()) {
|
||||
return comment.getTextOffset();
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static int findMatchingBlockCommentPair(@NotNull PsiElement element, int pos) {
|
||||
final Language language = element.getLanguage();
|
||||
final Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(language);
|
||||
final PsiComment comment = PsiTreeUtil.getParentOfType(element, PsiComment.class, false);
|
||||
if (comment != null) {
|
||||
final int ret = findMatchingBlockCommentPair(comment, pos, commenter.getBlockCommentPrefix(),
|
||||
commenter.getBlockCommentSuffix());
|
||||
if (ret >= 0) {
|
||||
return ret;
|
||||
}
|
||||
if (commenter instanceof CodeDocumentationAwareCommenter) {
|
||||
final CodeDocumentationAwareCommenter docCommenter = (CodeDocumentationAwareCommenter)commenter;
|
||||
return findMatchingBlockCommentPair(comment, pos, docCommenter.getDocumentationCommentPrefix(),
|
||||
docCommenter.getDocumentationCommentSuffix());
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* This looks on the current line, starting at the cursor position for one of {, }, (, ), [, or ]. It then searches
|
||||
* forward or backward, as appropriate for the associated match pair. String in double quotes are skipped over.
|
||||
@@ -153,10 +194,16 @@ public class SearchHelper {
|
||||
* were found on the remainder of the current line.
|
||||
*/
|
||||
public static int findMatchingPairOnCurrentLine(@NotNull Editor editor) {
|
||||
int pos = editor.getCaretModel().getOffset();
|
||||
|
||||
final int commentPos = findMatchingComment(editor, pos);
|
||||
if (commentPos >= 0) {
|
||||
return commentPos;
|
||||
}
|
||||
|
||||
int line = editor.getCaretModel().getLogicalPosition().line;
|
||||
int end = EditorHelper.getLineEndOffset(editor, line, true);
|
||||
CharSequence chars = editor.getDocument().getCharsSequence();
|
||||
int pos = editor.getCaretModel().getOffset();
|
||||
int loc = -1;
|
||||
// Search the remainder of the current line for one of the candidate characters
|
||||
while (pos < end) {
|
||||
@@ -182,6 +229,20 @@ public class SearchHelper {
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* If on the start/end of a block comment, jump to the matching of that comment, or vice versa.
|
||||
*/
|
||||
private static int findMatchingComment(@NotNull Editor editor, int pos) {
|
||||
final PsiFile psiFile = PsiHelper.getFile(editor);
|
||||
if (psiFile != null) {
|
||||
final PsiElement element = psiFile.findElementAt(pos);
|
||||
if (element != null) {
|
||||
return findMatchingBlockCommentPair(element, pos);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static int findBlockLocation(@NotNull CharSequence chars, char found, char match, int dir, int pos, int cnt) {
|
||||
int res = -1;
|
||||
final int inCheckPos = dir < 0 && pos > 0 ? pos - 1 : pos;
|
||||
@@ -235,7 +296,7 @@ public class SearchHelper {
|
||||
|
||||
private final int value;
|
||||
|
||||
private Direction(int i) {
|
||||
Direction(int i) {
|
||||
value = i;
|
||||
}
|
||||
|
||||
|
@@ -21,6 +21,7 @@ package com.maddyhome.idea.vim.helper;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptGlobalEnvironment;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -44,6 +45,10 @@ public class StringHelper {
|
||||
.put("return", VK_ENTER)
|
||||
.put("ins", VK_INSERT)
|
||||
.put("insert", VK_INSERT)
|
||||
.put("home", VK_HOME)
|
||||
.put("end", VK_END)
|
||||
.put("pageup", VK_PAGE_UP)
|
||||
.put("pagedown", VK_PAGE_DOWN)
|
||||
.put("del", VK_DELETE)
|
||||
.put("delete", VK_DELETE)
|
||||
.put("esc", VK_ESCAPE)
|
||||
@@ -70,9 +75,10 @@ public class StringHelper {
|
||||
private static final Map<Integer, String> VIM_KEY_VALUES = invertMap(VIM_KEY_NAMES);
|
||||
|
||||
private static final Map<String, Character> VIM_TYPED_KEY_NAMES = ImmutableMap.<String, Character>builder()
|
||||
.put("leader", '\\')
|
||||
.put("space", ' ')
|
||||
.put("bar", '|')
|
||||
.put("bslash", '\\')
|
||||
.put("lt", '<')
|
||||
.build();
|
||||
|
||||
private static final Set<String> UPPERCASE_DISPLAY_KEY_NAMES = ImmutableSet.<String>builder()
|
||||
@@ -121,7 +127,7 @@ public class StringHelper {
|
||||
return res;
|
||||
}
|
||||
|
||||
private static enum KeyParserState {
|
||||
private enum KeyParserState {
|
||||
INIT,
|
||||
ESCAPE,
|
||||
SPECIAL,
|
||||
@@ -183,8 +189,12 @@ public class StringHelper {
|
||||
throw new IllegalArgumentException("<" + specialKeyName + "> is not supported");
|
||||
}
|
||||
if (!"nop".equals(lower)) {
|
||||
final List<KeyStroke> leader = parseMapLeader(specialKeyName);
|
||||
final KeyStroke specialKey = parseSpecialKey(specialKeyName, 0);
|
||||
if (specialKey != null) {
|
||||
if (leader != null) {
|
||||
result.addAll(leader);
|
||||
}
|
||||
else if (specialKey != null) {
|
||||
result.add(specialKey);
|
||||
}
|
||||
else {
|
||||
@@ -211,6 +221,20 @@ public class StringHelper {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static List<KeyStroke> parseMapLeader(@NotNull String s) {
|
||||
if ("leader".equals(s.toLowerCase())) {
|
||||
final Object mapLeader = VimScriptGlobalEnvironment.getInstance().getVariables().get("mapleader");
|
||||
if (mapLeader instanceof String) {
|
||||
return stringToKeys((String)mapLeader);
|
||||
}
|
||||
else {
|
||||
return stringToKeys("\\");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isControlCharacter(char c) {
|
||||
return c < '\u0020';
|
||||
}
|
||||
|
@@ -18,10 +18,13 @@
|
||||
|
||||
package com.maddyhome.idea.vim.helper;
|
||||
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
@@ -31,10 +34,28 @@ public class UiHelper {
|
||||
private UiHelper() {
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static Font getEditorFont() {
|
||||
final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
|
||||
return new Font(scheme.getEditorFontName(), Font.PLAIN, scheme.getEditorFontSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get focus reliably.
|
||||
*/
|
||||
public static void requestFocus(@NotNull final JComponent component) {
|
||||
final Application application = ApplicationManager.getApplication();
|
||||
// XXX: This workaround is required at least for Oracle Java 6
|
||||
application.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
application.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
component.requestFocus();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -273,45 +273,39 @@ public class CharPointer {
|
||||
|
||||
@Nullable
|
||||
public CharPointer strchr(char c) {
|
||||
if (end()) {
|
||||
if (seq == null || end()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int len = seq.length();
|
||||
final int len = seq.length();
|
||||
for (int i = pointer; i < len; i++) {
|
||||
if (seq.charAt(i) == c) {
|
||||
final char ch = seq.charAt(i);
|
||||
if (ch == '\u0000') {
|
||||
return null;
|
||||
}
|
||||
if (ch == c) {
|
||||
return ref(i - pointer);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
/*
|
||||
String str = seq.subSequence(pointer, pointer + strlen()).toString();
|
||||
int pos = str.indexOf(c);
|
||||
if (pos != -1)
|
||||
{
|
||||
return ref(pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CharPointer istrchr(char c) {
|
||||
if (end()) {
|
||||
if (seq == null || end()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int len = seq.length();
|
||||
char cc = Character.toUpperCase(c);
|
||||
final int len = seq.length();
|
||||
final char cc = Character.toUpperCase(c);
|
||||
c = Character.toLowerCase(c);
|
||||
|
||||
for (int i = pointer; i < len; i++) {
|
||||
char ch = seq.charAt(i);
|
||||
final char ch = seq.charAt(i);
|
||||
if (ch == '\u0000') {
|
||||
return null;
|
||||
}
|
||||
if (ch == c || ch == cc) {
|
||||
return ref(i - pointer);
|
||||
}
|
||||
@@ -329,11 +323,7 @@ public class CharPointer {
|
||||
}
|
||||
|
||||
public boolean end(int offset) {
|
||||
if (seq == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return pointer + offset >= seq.length();
|
||||
return seq == null || pointer + offset >= seq.length();
|
||||
}
|
||||
|
||||
public int OP() {
|
||||
|
@@ -3051,7 +3051,7 @@ public class RegExp {
|
||||
if (--count < minval) {
|
||||
break;
|
||||
}
|
||||
if (reginput == regline) {
|
||||
if (reginput.equals(regline)) {
|
||||
/* backup to last char of previous line */
|
||||
--reglnum;
|
||||
regline = reg_getline(reglnum);
|
||||
@@ -3132,7 +3132,7 @@ public class RegExp {
|
||||
case BEHIND:
|
||||
case NOBEHIND: {
|
||||
regsave_T save_after = new regsave_T(), save_start = new regsave_T();
|
||||
regsave_T save_behind_pos = new regsave_T();
|
||||
regsave_T save_behind_pos;
|
||||
boolean needmatch = (op == BEHIND);
|
||||
|
||||
/*
|
||||
@@ -3153,8 +3153,8 @@ public class RegExp {
|
||||
* line (for multi-line matching).
|
||||
* Set behind_pos to where the match should end, BHPOS
|
||||
* will match it. */
|
||||
save_behind_pos = behind_pos;
|
||||
behind_pos = save_start;
|
||||
save_behind_pos = behind_pos == null ? null : new regsave_T(behind_pos);
|
||||
behind_pos = new regsave_T(save_start);
|
||||
while (true) {
|
||||
reg_restore(save_start);
|
||||
if (regmatch(scan.OPERAND()) && reg_save_equal(behind_pos)) {
|
||||
@@ -3676,9 +3676,9 @@ public class RegExp {
|
||||
*/
|
||||
private boolean reg_save_equal(@NotNull regsave_T save) {
|
||||
if (reg_match == null) {
|
||||
return reglnum == save.pos.lnum && reginput == regline.ref(save.pos.col);
|
||||
return reglnum == save.pos.lnum && reginput.equals(regline.ref(save.pos.col));
|
||||
}
|
||||
return reginput == save.ptr;
|
||||
return reginput.equals(save.ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4694,6 +4694,14 @@ public class RegExp {
|
||||
private static class regsave_T {
|
||||
CharPointer ptr; /* reginput pointer, for single-line regexp */
|
||||
@NotNull lpos_T pos = new lpos_T(); /* reginput pos, for multi-line regexp */
|
||||
|
||||
public regsave_T() {
|
||||
}
|
||||
|
||||
public regsave_T(regsave_T rhs) {
|
||||
ptr = rhs.ptr == null ? null : new CharPointer("").assign(rhs.ptr);
|
||||
pos = new lpos_T(rhs.pos);
|
||||
}
|
||||
}
|
||||
|
||||
/* struct to save start/end pointer/position in for \(\) */
|
||||
|
@@ -30,7 +30,6 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
/**
|
||||
* This is used to enter ex commands such as searches and "colon" commands
|
||||
@@ -88,7 +87,7 @@ public class ExEntryPanel extends JPanel {
|
||||
/**
|
||||
* Turns on the ex entry field for the given editor
|
||||
*
|
||||
* @param editor The editor to use for dislay
|
||||
* @param editor The editor to use for display
|
||||
* @param context The data context
|
||||
* @param label The label for the ex entry (i.e. :, /, or ?)
|
||||
* @param initText The initial text for the entry
|
||||
@@ -146,15 +145,12 @@ public class ExEntryPanel extends JPanel {
|
||||
entry.handleKey(stroke);
|
||||
}
|
||||
|
||||
public void processKey(KeyEvent event) {
|
||||
entry.processKeyEvent(event);
|
||||
}
|
||||
|
||||
private void positionPanel() {
|
||||
if (parent == null) return;
|
||||
|
||||
Container scroll = SwingUtilities.getAncestorOfClass(JScrollPane.class, parent);
|
||||
int height = (int)getPreferredSize().getHeight();
|
||||
if (scroll != null) {
|
||||
Rectangle bounds = scroll.getBounds();
|
||||
bounds.translate(0, scroll.getHeight() - height);
|
||||
bounds.height = height;
|
||||
@@ -163,6 +159,7 @@ public class ExEntryPanel extends JPanel {
|
||||
setBounds(bounds);
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the text entered by the user. This includes any initial text but does not include the label
|
||||
@@ -179,14 +176,17 @@ public class ExEntryPanel extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns off the ex entry field and puts the focus back to the original component
|
||||
*
|
||||
* Turns off the ex entry field and optionally puts the focus back to the original component
|
||||
*/
|
||||
public void deactivate() {
|
||||
public void deactivate(boolean refocusOwningEditor) {
|
||||
logger.info("deactivate");
|
||||
if (!active) return;
|
||||
active = false;
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
if (refocusOwningEditor && parent != null) {
|
||||
UiHelper.requestFocus(parent);
|
||||
}
|
||||
|
||||
oldGlass.removeComponentListener(adapter);
|
||||
oldGlass.setVisible(false);
|
||||
oldGlass.remove(this);
|
||||
|
@@ -19,9 +19,7 @@
|
||||
package com.maddyhome.idea.vim.ui;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.components.JBScrollPane;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.helper.EditorData;
|
||||
@@ -113,22 +111,20 @@ public class ExOutputPanel extends JPanel {
|
||||
myText.setText(data);
|
||||
myText.setCaretPosition(0);
|
||||
if (data.length() > 0) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
activate();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns off the ex entry field and puts the focus back to the original component
|
||||
* Turns off the ex entry field and optionally puts the focus back to the original component
|
||||
*/
|
||||
public void deactivate() {
|
||||
public void deactivate(boolean refocusOwningEditor) {
|
||||
if (!myActive) return;
|
||||
myActive = false;
|
||||
myText.setText("");
|
||||
if (refocusOwningEditor) {
|
||||
UiHelper.requestFocus(myEditor.getContentComponent());
|
||||
}
|
||||
if (myOldGlass != null) {
|
||||
myOldGlass.removeComponentListener(myAdapter);
|
||||
myOldGlass.setVisible(false);
|
||||
@@ -136,7 +132,6 @@ public class ExOutputPanel extends JPanel {
|
||||
myOldGlass.setOpaque(myWasOpaque);
|
||||
myOldGlass.setLayout(myOldLayout);
|
||||
}
|
||||
myEditor.getContentComponent().requestFocus();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,17 +155,9 @@ public class ExOutputPanel extends JPanel {
|
||||
if (myOldGlass != null) {
|
||||
myOldGlass.setVisible(true);
|
||||
}
|
||||
myActive = true;
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
myText.requestFocus();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
myActive = true;
|
||||
UiHelper.requestFocus(myText);
|
||||
}
|
||||
|
||||
private void setFontForElements() {
|
||||
@@ -277,11 +264,7 @@ public class ExOutputPanel extends JPanel {
|
||||
private void close(@Nullable final KeyEvent e) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
deactivate();
|
||||
final VirtualFile vf = EditorData.getVirtualFile(myEditor);
|
||||
if (vf != null) {
|
||||
FileEditorManager.getInstance(myEditor.getProject()).openFile(vf, true);
|
||||
}
|
||||
deactivate(true);
|
||||
|
||||
final Project project = myEditor.getProject();
|
||||
|
||||
|
@@ -1,13 +1,13 @@
|
||||
package org.jetbrains.plugins.ideavim;
|
||||
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.ide.highlighter.XmlFileType;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileTypes.PlainTextFileType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.PlatformTestCase;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestFixture;
|
||||
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
|
||||
@@ -18,6 +18,7 @@ import com.maddyhome.idea.vim.KeyHandler;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.command.CommandState;
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel;
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptGlobalEnvironment;
|
||||
import com.maddyhome.idea.vim.helper.EditorDataContext;
|
||||
import com.maddyhome.idea.vim.helper.RunnableHelper;
|
||||
import com.maddyhome.idea.vim.helper.StringHelper;
|
||||
@@ -34,16 +35,8 @@ import java.util.List;
|
||||
* @author vlan
|
||||
*/
|
||||
public abstract class VimTestCase extends UsefulTestCase {
|
||||
private static final String ULTIMATE_MARKER_CLASS = "com.intellij.psi.css.CssFile";
|
||||
protected CodeInsightTestFixture myFixture;
|
||||
|
||||
public VimTestCase() {
|
||||
// Only in IntelliJ IDEA Ultimate Edition
|
||||
PlatformTestCase.initPlatformLangPrefix();
|
||||
// XXX: IntelliJ IDEA Community and Ultimate 12+
|
||||
//PlatformTestCase.initPlatformPrefix(ULTIMATE_MARKER_CLASS, "PlatformLangXml");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@@ -68,7 +61,8 @@ public abstract class VimTestCase extends UsefulTestCase {
|
||||
protected void tearDown() throws Exception {
|
||||
myFixture.tearDown();
|
||||
myFixture = null;
|
||||
ExEntryPanel.getInstance().deactivate();
|
||||
ExEntryPanel.getInstance().deactivate(false);
|
||||
VimScriptGlobalEnvironment.getInstance().getVariables().clear();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@@ -90,6 +84,12 @@ public abstract class VimTestCase extends UsefulTestCase {
|
||||
return myFixture.getEditor();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Editor configureByXmlText(@NotNull String content) {
|
||||
myFixture.configureByText(XmlFileType.INSTANCE, content);
|
||||
return myFixture.getEditor();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Editor typeText(@NotNull final List<KeyStroke> keys) {
|
||||
final Editor editor = myFixture.getEditor();
|
||||
@@ -149,4 +149,21 @@ public abstract class VimTestCase extends UsefulTestCase {
|
||||
public void assertPluginError(boolean isError) {
|
||||
assertEquals(isError, VimPlugin.isError());
|
||||
}
|
||||
|
||||
public void doTest(final List<KeyStroke> keys, String before, String after) {
|
||||
myFixture.configureByText(PlainTextFileType.INSTANCE, before);
|
||||
final Editor editor = myFixture.getEditor();
|
||||
final KeyHandler keyHandler = KeyHandler.getInstance();
|
||||
final EditorDataContext dataContext = new EditorDataContext(editor);
|
||||
final Project project = myFixture.getProject();
|
||||
RunnableHelper.runWriteCommand(project, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (KeyStroke key : keys) {
|
||||
keyHandler.handleKey(editor, key, dataContext);
|
||||
}
|
||||
}
|
||||
}, null, null);
|
||||
myFixture.checkResult(after);
|
||||
}
|
||||
}
|
||||
|
@@ -1,17 +1,8 @@
|
||||
package org.jetbrains.plugins.ideavim.action;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileTypes.PlainTextFileType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.maddyhome.idea.vim.KeyHandler;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.helper.EditorDataContext;
|
||||
import com.maddyhome.idea.vim.helper.RunnableHelper;
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
|
||||
import static com.maddyhome.idea.vim.helper.StringHelper.parseKeys;
|
||||
import static com.maddyhome.idea.vim.helper.StringHelper.stringToKeys;
|
||||
|
||||
@@ -70,6 +61,30 @@ public class ChangeActionTest extends VimTestCase {
|
||||
"hello worLD\n");
|
||||
}
|
||||
|
||||
public void testToggleCaseMotion() {
|
||||
doTest(parseKeys("g~w"), "<caret>FooBar Baz\n", "fOObAR Baz\n");
|
||||
}
|
||||
|
||||
public void testChangeUpperCase() {
|
||||
doTest(parseKeys("gUw"), "<caret>FooBar Baz\n", "FOOBAR Baz\n");
|
||||
}
|
||||
|
||||
public void testChangeLowerCase() {
|
||||
doTest(parseKeys("guw"), "<caret>FooBar Baz\n", "foobar Baz\n");
|
||||
}
|
||||
|
||||
public void testToggleCaseVisual() {
|
||||
doTest(parseKeys("ve~"), "<caret>FooBar Baz\n", "fOObAR Baz\n");
|
||||
}
|
||||
|
||||
public void testChangeUpperCaseVisual() {
|
||||
doTest(parseKeys("veU"), "<caret>FooBar Baz\n", "FOOBAR Baz\n");
|
||||
}
|
||||
|
||||
public void testChangeLowerCaseVisual() {
|
||||
doTest(parseKeys("veu"), "<caret>FooBar Baz\n", "foobar Baz\n");
|
||||
}
|
||||
|
||||
// VIM-85 |i| |gi| |gg|
|
||||
public void testInsertAtPreviousAction() {
|
||||
doTest(parseKeys("i", "hello", "<Esc>", "gg", "gi", " world! "), "one\n" +
|
||||
@@ -273,6 +288,198 @@ public class ChangeActionTest extends VimTestCase {
|
||||
"quux\n");
|
||||
}
|
||||
|
||||
public void testDeleteJoinLinesSpaces() {
|
||||
doTest(parseKeys("3J"),
|
||||
" a<caret> 1\n" +
|
||||
" b 2\n" +
|
||||
" c 3\n" +
|
||||
"quux\n",
|
||||
" a 1 b 2 c 3\n" +
|
||||
"quux\n");
|
||||
}
|
||||
|
||||
public void testDeleteJoinLines() {
|
||||
doTest(parseKeys("3gJ"),
|
||||
" a<caret> 1\n" +
|
||||
" b 2\n" +
|
||||
" c 3\n" +
|
||||
"quux\n",
|
||||
" a 1 b 2 c 3\n" +
|
||||
"quux\n");
|
||||
}
|
||||
|
||||
public void testDeleteJoinLinesWithTrailingSpaceThenEmptyLine() {
|
||||
doTest(parseKeys("3J"),
|
||||
"foo \n" +
|
||||
"\n" +
|
||||
"bar",
|
||||
"foo bar");
|
||||
}
|
||||
|
||||
public void testDeleteJoinLinesWithTwoTrailingSpaces() {
|
||||
doTest(parseKeys("J"),
|
||||
"foo \n" +
|
||||
"bar",
|
||||
"foo bar");
|
||||
}
|
||||
|
||||
public void testDeleteJoinVisualLinesSpaces() {
|
||||
doTest(parseKeys("v2jJ"),
|
||||
" a<caret> 1\n" +
|
||||
" b 2\n" +
|
||||
" c 3\n" +
|
||||
"quux\n",
|
||||
" a 1 b 2 c 3\n" +
|
||||
"quux\n");
|
||||
}
|
||||
|
||||
public void testDeleteJoinVisualLines() {
|
||||
doTest(parseKeys("v2jgJ"),
|
||||
" a<caret> 1\n" +
|
||||
" b 2\n" +
|
||||
" c 3\n" +
|
||||
"quux\n",
|
||||
" a 1 b 2 c 3\n" +
|
||||
"quux\n");
|
||||
}
|
||||
|
||||
public void testDeleteCharVisualBlockOnLastCharOfLine() {
|
||||
doTest(parseKeys("<C-V>", "x"),
|
||||
"fo<caret>o\n",
|
||||
"fo\n");
|
||||
}
|
||||
|
||||
public void testDeleteCharVisualBlockOnEmptyLinesDoesntDeleteAnything() {
|
||||
doTest(parseKeys("<C-V>", "j", "x"),
|
||||
"\n\n",
|
||||
"\n\n");
|
||||
}
|
||||
|
||||
// VIM-781 |CTRL-V| |j|
|
||||
public void testDeleteCharVisualBlockWithEmptyLineInTheMiddle() {
|
||||
doTest(parseKeys("l", "<C-V>", "jj", "x"),
|
||||
"foo\n" +
|
||||
"\n" +
|
||||
"bar\n",
|
||||
"fo\n" +
|
||||
"\n" +
|
||||
"br\n");
|
||||
}
|
||||
|
||||
// VIM-781 |CTRL-V| |j|
|
||||
public void testDeleteCharVisualBlockWithShorterLineInTheMiddle() {
|
||||
doTest(parseKeys("l", "<C-V>", "jj", "x"),
|
||||
"foo\n" +
|
||||
"x\n" +
|
||||
"bar\n",
|
||||
"fo\n" +
|
||||
"x\n" +
|
||||
"br\n");
|
||||
}
|
||||
|
||||
// VIM-845 |CTRL-V| |x|
|
||||
public void testDeleteVisualBlockOneCharWide() {
|
||||
configureByText("foo\n" +
|
||||
"bar\n");
|
||||
typeText(parseKeys("<C-V>", "j", "x"));
|
||||
myFixture.checkResult("oo\n" +
|
||||
"ar\n");
|
||||
}
|
||||
|
||||
// |r|
|
||||
public void testReplaceOneChar() {
|
||||
doTest(parseKeys("rx"),
|
||||
"b<caret>ar\n",
|
||||
"b<caret>xr\n");
|
||||
}
|
||||
|
||||
// |r|
|
||||
public void testReplaceMultipleCharsWithCount() {
|
||||
doTest(parseKeys("3rX"),
|
||||
"fo<caret>obar\n",
|
||||
"fo<caret>XXXr\n");
|
||||
}
|
||||
|
||||
// |r|
|
||||
public void testReplaceMultipleCharsWithCountPastEndOfLine() {
|
||||
doTest(parseKeys("6rX"),
|
||||
"fo<caret>obar\n",
|
||||
"fo<caret>obar\n");
|
||||
}
|
||||
|
||||
// |r|
|
||||
public void testReplaceMultipleCharsWithVisual() {
|
||||
doTest(parseKeys("v", "ll", "j", "rZ"),
|
||||
"fo<caret>obar\n" +
|
||||
"foobaz\n",
|
||||
"foZZZZ\n" +
|
||||
"ZZZZZz\n");
|
||||
}
|
||||
|
||||
// |r|
|
||||
public void testReplaceOneCharWithNewline() {
|
||||
doTest(parseKeys("r<Enter>"),
|
||||
" fo<caret>obar\n" +
|
||||
"foobaz\n",
|
||||
" fo\n" +
|
||||
" bar\n" +
|
||||
"foobaz\n");
|
||||
}
|
||||
|
||||
// |r|
|
||||
public void testReplaceCharWithNewlineAndCountAddsOnlySingleNewline() {
|
||||
doTest(parseKeys("3r<Enter>"),
|
||||
" fo<caret>obar\n" +
|
||||
"foobaz\n",
|
||||
" fo\n" +
|
||||
" r\n" +
|
||||
"foobaz\n");
|
||||
}
|
||||
|
||||
// |s|
|
||||
public void testReplaceOneCharWithText() {
|
||||
doTest(parseKeys("sxy<Esc>"),
|
||||
"b<caret>ar\n",
|
||||
"bx<caret>yr\n");
|
||||
}
|
||||
|
||||
// |s|
|
||||
public void testReplaceMultipleCharsWithTextWithCount() {
|
||||
doTest(parseKeys("3sxy<Esc>"),
|
||||
"fo<caret>obar\n",
|
||||
"fox<caret>yr\n");
|
||||
}
|
||||
|
||||
// |s|
|
||||
public void testReplaceMultipleCharsWithTextWithCountPastEndOfLine() {
|
||||
doTest(parseKeys("99sxyz<Esc>"),
|
||||
"foo<caret>bar\n" +
|
||||
"biff\n",
|
||||
"fooxy<caret>z\n" +
|
||||
"biff\n");
|
||||
}
|
||||
|
||||
// |R|
|
||||
public void testReplaceMode() {
|
||||
doTest(parseKeys("Rbaz<Esc>"),
|
||||
"foo<caret>bar\n",
|
||||
"fooba<caret>z\n");
|
||||
}
|
||||
|
||||
// |R| |i_<Insert>|
|
||||
public void testReplaceModeSwitchToInsertModeAndBack() {
|
||||
doTest(parseKeys("RXXX<Ins>YYY<Ins>ZZZ<Esc>"),
|
||||
"aaa<caret>bbbcccddd\n",
|
||||
"aaaXXXYYYZZ<caret>Zddd\n");
|
||||
}
|
||||
|
||||
// |i| |i_<Insert>|
|
||||
public void testInsertModeSwitchToReplaceModeAndBack() {
|
||||
doTest(parseKeys("iXXX<Ins>YYY<Ins>ZZZ<Esc>"),
|
||||
"aaa<caret>bbbcccddd\n",
|
||||
"aaaXXXYYYZZ<caret>Zcccddd\n");
|
||||
}
|
||||
|
||||
// VIM-511 |.|
|
||||
public void testRepeatWithBackspaces() {
|
||||
doTest(parseKeys("ce", "foo", "<BS><BS><BS>", "foo", "<Esc>", "j0", "."),
|
||||
@@ -329,21 +536,4 @@ public class ChangeActionTest extends VimTestCase {
|
||||
" }\n" +
|
||||
"}\n");
|
||||
}
|
||||
|
||||
private void doTest(final List<KeyStroke> keys, String before, String after) {
|
||||
myFixture.configureByText(PlainTextFileType.INSTANCE, before);
|
||||
final Editor editor = myFixture.getEditor();
|
||||
final KeyHandler keyHandler = KeyHandler.getInstance();
|
||||
final EditorDataContext dataContext = new EditorDataContext(editor);
|
||||
final Project project = myFixture.getProject();
|
||||
RunnableHelper.runWriteCommand(project, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (KeyStroke key : keys) {
|
||||
keyHandler.handleKey(editor, key, dataContext);
|
||||
}
|
||||
}
|
||||
}, null, null);
|
||||
myFixture.checkResult(after);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,122 @@
|
||||
package org.jetbrains.plugins.ideavim.action;
|
||||
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase;
|
||||
|
||||
import static com.maddyhome.idea.vim.helper.StringHelper.parseKeys;
|
||||
|
||||
/**
|
||||
* @author Tuomas Tynkkynen
|
||||
*/
|
||||
public class ChangeNumberActionTest extends VimTestCase {
|
||||
public void testIncrementDecimalZero() {
|
||||
doTest(parseKeys("<C-A>"), "0", "1");
|
||||
}
|
||||
|
||||
public void testIncrementHexZero() {
|
||||
doTest(parseKeys("<C-A>"), "0x0", "0x1");
|
||||
}
|
||||
|
||||
public void testDecrementZero() {
|
||||
doTest(parseKeys("<C-X>"), "0", "-1");
|
||||
}
|
||||
|
||||
public void testIncrementDecimal() {
|
||||
doTest(parseKeys("<C-A>"), "199", "200");
|
||||
}
|
||||
|
||||
public void testDecrementDecimal() {
|
||||
doTest(parseKeys("<C-X>"), "1000", "999");
|
||||
}
|
||||
|
||||
public void testIncrementOctal() {
|
||||
doTest(parseKeys("<C-A>"), "0477", "0500");
|
||||
}
|
||||
|
||||
public void testDecrementOctal() {
|
||||
doTest(parseKeys("<C-X>"), "010", "007");
|
||||
}
|
||||
|
||||
public void testIncrementHex() {
|
||||
doTest(parseKeys("<C-A>"), "0xff", "0x100");
|
||||
}
|
||||
|
||||
public void testDecrementHex() {
|
||||
doTest(parseKeys("<C-X>"), "0xa100", "0xa0ff");
|
||||
}
|
||||
|
||||
public void testIncrementNegativeDecimal() {
|
||||
doTest(parseKeys("<C-A>"), "-199", "-198");
|
||||
}
|
||||
|
||||
public void testDecrementNegativeDecimal() {
|
||||
doTest(parseKeys("<C-X>"), "-1000", "-1001");
|
||||
}
|
||||
|
||||
public void testIncrementNegativeOctal() {
|
||||
doTest(parseKeys("<C-A>"), "-0477", "-0500");
|
||||
}
|
||||
|
||||
public void testDecrementNegativeOctal() {
|
||||
doTest(parseKeys("<C-X>"), "-010", "-007");
|
||||
}
|
||||
|
||||
public void testIncrementNegativeHex() {
|
||||
doTest(parseKeys("<C-A>"), "-0xff", "-0x100");
|
||||
}
|
||||
|
||||
public void testDecrementNegativeHex() {
|
||||
doTest(parseKeys("<C-X>"), "-0xa100", "-0xa0ff");
|
||||
}
|
||||
|
||||
public void testIncrementWithCount() {
|
||||
doTest(parseKeys("123<C-A>"), "456", "579");
|
||||
}
|
||||
|
||||
public void testDecrementWithCount() {
|
||||
doTest(parseKeys("200<C-X>"), "100", "-100");
|
||||
}
|
||||
|
||||
public void testIncrementAlphaWithoutNumberFormatAlpha() {
|
||||
doTest(parseKeys("<C-A>"), "foo", "foo");
|
||||
}
|
||||
|
||||
public void testIncrementAlphaWithNumberFormatAlpha() {
|
||||
doTest(parseKeys(":set nf=alpha<Enter>", "<C-A>"), "foo", "goo");
|
||||
}
|
||||
|
||||
public void testIncrementZWithNumberFormatAlpha() {
|
||||
doTest(parseKeys(":set nf=alpha<Enter>", "<C-A>"), "zzz", "zzz");
|
||||
}
|
||||
|
||||
public void testIncrementXInHexNumberWithNumberFormatAlphaButNotHex() {
|
||||
doTest(parseKeys(":set nf=alpha<Enter>", "<C-A>"), "0<caret>x1", "0y1");
|
||||
}
|
||||
|
||||
public void testIncrementXInHexNumberWithNumberFormatHexAlpha() {
|
||||
doTest(parseKeys(":set nf=alpha,hex<Enter>", "<C-A>"), "0<caret>x1", "0x2");
|
||||
}
|
||||
|
||||
public void testIncrementHexNumberWithoutNumberFormatHex() {
|
||||
doTest(parseKeys(":set nf=octal<Enter>", "<C-A>"), "0x42", "1x42");
|
||||
}
|
||||
|
||||
public void testIncrementOctalNumberWithoutNumberFormatOctal() {
|
||||
doTest(parseKeys(":set nf=hex<Enter>", "<C-A>"), "077", "078");
|
||||
}
|
||||
|
||||
public void testIncrementNegativeOctalNumberWithoutNumberFormatOctal() {
|
||||
doTest(parseKeys(":set nf=hex<Enter>", "<C-A>"), "-077", "-076");
|
||||
}
|
||||
|
||||
public void testIncrementHexPreservesCaseOfX() {
|
||||
doTest(parseKeys("<C-A>"), "0X88", "0X89");
|
||||
}
|
||||
|
||||
public void testIncrementHexTakesCaseFromLastLetter() {
|
||||
doTest(parseKeys("<C-A>"), "0xaB0", "0xAB1");
|
||||
}
|
||||
|
||||
public void testIncrementLocatesNumberOnTheSameLine() {
|
||||
doTest(parseKeys("<C-A>"), "foo ->* bar 123\n", "foo ->* bar 12<caret>4\n");
|
||||
}
|
||||
}
|
118
test/org/jetbrains/plugins/ideavim/action/MarkTest.java
Normal file
118
test/org/jetbrains/plugins/ideavim/action/MarkTest.java
Normal file
@@ -0,0 +1,118 @@
|
||||
package org.jetbrains.plugins.ideavim.action;
|
||||
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.common.Mark;
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase;
|
||||
|
||||
import static com.maddyhome.idea.vim.helper.StringHelper.parseKeys;
|
||||
|
||||
/**
|
||||
* @author Tuomas Tynkkynen
|
||||
*/
|
||||
public class MarkTest extends VimTestCase {
|
||||
// |m|
|
||||
public void testLocalMark() {
|
||||
typeTextInFile(parseKeys("ma"), " foo\n" +
|
||||
" ba<caret>r\n" +
|
||||
" baz\n");
|
||||
Mark mark = VimPlugin.getMark().getMark(myFixture.getEditor(), 'a');
|
||||
assertNotNull(mark);
|
||||
assertEquals(1, mark.getLogicalLine());
|
||||
assertEquals(6, mark.getCol());
|
||||
}
|
||||
|
||||
// |m|
|
||||
public void testGlobalMark() {
|
||||
typeTextInFile(parseKeys("mG"), " foo\n" +
|
||||
" ba<caret>r\n" +
|
||||
" baz\n");
|
||||
Mark mark = VimPlugin.getMark().getMark(myFixture.getEditor(), 'G');
|
||||
assertNotNull(mark);
|
||||
assertEquals(1, mark.getLogicalLine());
|
||||
assertEquals(6, mark.getCol());
|
||||
}
|
||||
|
||||
// |m|
|
||||
public void testMarkIsDeletedWhenLineIsDeleted() {
|
||||
typeTextInFile(parseKeys("mx", "dd"), " foo\n" +
|
||||
" ba<caret>r\n" +
|
||||
" baz\n");
|
||||
Mark mark = VimPlugin.getMark().getMark(myFixture.getEditor(), 'x');
|
||||
assertNull(mark);
|
||||
}
|
||||
|
||||
// |m|
|
||||
public void testMarkIsMovedUpWhenLinesAreDeletedAbove() {
|
||||
typeTextInFile(parseKeys("mx", "2k", "2dd"), " foo\n" +
|
||||
" ba<r\n" +
|
||||
" ba<caret>z\n");
|
||||
Mark mark = VimPlugin.getMark().getMark(myFixture.getEditor(), 'x');
|
||||
assertNotNull(mark);
|
||||
assertEquals(0, mark.getLogicalLine());
|
||||
assertEquals(6, mark.getCol());
|
||||
}
|
||||
|
||||
// |m|
|
||||
public void testMarkIsMovedDownWhenLinesAreInsertedAbove() {
|
||||
typeTextInFile(parseKeys("mY", "Obiff"), " foo\n" +
|
||||
" ba<caret>r\n" +
|
||||
" baz\n");
|
||||
Mark mark = VimPlugin.getMark().getMark(myFixture.getEditor(), 'Y');
|
||||
assertNotNull(mark);
|
||||
assertEquals(2, mark.getLogicalLine());
|
||||
assertEquals(6, mark.getCol());
|
||||
}
|
||||
|
||||
// |m| |`|
|
||||
public void testMarkAndJumpToMark() {
|
||||
typeTextInFile(parseKeys("6l", "mZ", "G$", "`Z"), " foo\n" +
|
||||
" bar\n" +
|
||||
" baz\n");
|
||||
assertOffset(6);
|
||||
}
|
||||
|
||||
// |m| |'|
|
||||
public void testMarkAndJumpToMarkLeadingSpace() {
|
||||
typeTextInFile(parseKeys("6l", "mb", "G$", "'b"), " foo\n" +
|
||||
" bar\n" +
|
||||
" baz\n");
|
||||
assertOffset(4);
|
||||
}
|
||||
|
||||
// |m| |`|
|
||||
public void testDeleteBacktickMotionIsCharacterWise() {
|
||||
typeTextInFile(parseKeys("mk", "kh", "d`k"), " abcd\n" +
|
||||
" efgh\n" +
|
||||
" ij<caret>kl\n" +
|
||||
" mnop\n");
|
||||
myFixture.checkResult(" abcd\n" +
|
||||
" ekl\n" +
|
||||
" mnop\n");
|
||||
}
|
||||
|
||||
// |m| |`|
|
||||
public void testDeleteSingleQuoteMotionIsLineWise() {
|
||||
typeTextInFile(parseKeys("mk", "kh", "d'k"), " abcd\n" +
|
||||
" efgh\n" +
|
||||
" ij<caret>kl\n" +
|
||||
" mnop\n");
|
||||
myFixture.checkResult(" abcd\n" +
|
||||
" mnop\n");
|
||||
}
|
||||
|
||||
// VIM-43 |i| |`.|
|
||||
public void testGotoLastChangePosition() {
|
||||
typeTextInFile(parseKeys("i", "hello ", "<Esc>", "gg", "`."), "one two\n" +
|
||||
"<caret>hello world\n" +
|
||||
"three four\n");
|
||||
assertOffset(13);
|
||||
}
|
||||
|
||||
// VIM-43 |p| |`.|
|
||||
public void testGotoLastPutPosition() {
|
||||
typeTextInFile(parseKeys("yy", "p", "gg", "`."), "one two\n" +
|
||||
"<caret>three\n" +
|
||||
"four five\n");
|
||||
assertOffset(14);
|
||||
}
|
||||
}
|
@@ -80,7 +80,7 @@ public class MotionActionTest extends VimTestCase {
|
||||
public void testBackToDigraph() {
|
||||
typeTextInFile(parseKeys("F<C-K>O:"),
|
||||
"Hallo, Öster<caret>reich!\n");
|
||||
assertOffset(7);
|
||||
myFixture.checkResult("Hallo, <caret>Österreich!\n");
|
||||
assertMode(COMMAND);
|
||||
}
|
||||
|
||||
@@ -426,6 +426,76 @@ public class MotionActionTest extends VimTestCase {
|
||||
assertOffset(3);
|
||||
}
|
||||
|
||||
// |%|
|
||||
public void testPercentMatchXmlCommentStart() {
|
||||
configureByXmlText("<caret><!-- foo -->");
|
||||
typeText(parseKeys("%"));
|
||||
myFixture.checkResult("<!-- foo --<caret>>");
|
||||
}
|
||||
|
||||
// |%|
|
||||
public void testPercentDoesntMatchPartialXmlComment() {
|
||||
configureByXmlText("<!<caret>-- ");
|
||||
typeText(parseKeys("%"));
|
||||
myFixture.checkResult("<!<caret>-- ");
|
||||
}
|
||||
|
||||
// |%|
|
||||
public void testPercentMatchXmlCommentEnd() {
|
||||
configureByXmlText("<!-- foo --<caret>>");
|
||||
typeText(parseKeys("%"));
|
||||
myFixture.checkResult("<caret><!-- foo -->");
|
||||
}
|
||||
|
||||
// |%|
|
||||
public void testPercentMatchJavaCommentStart() {
|
||||
configureByJavaText("/<caret>* foo */");
|
||||
typeText(parseKeys("%"));
|
||||
myFixture.checkResult("/* foo *<caret>/");
|
||||
}
|
||||
|
||||
// |%|
|
||||
public void testPercentDoesntMatchPartialJavaComment() {
|
||||
configureByJavaText("<caret>/* ");
|
||||
typeText(parseKeys("%"));
|
||||
myFixture.checkResult("<caret>/* ");
|
||||
}
|
||||
|
||||
// |%|
|
||||
public void testPercentMatchJavaCommentEnd() {
|
||||
configureByJavaText("/* foo <caret>*/");
|
||||
typeText(parseKeys("%"));
|
||||
myFixture.checkResult("<caret>/* foo */");
|
||||
}
|
||||
|
||||
// |%|
|
||||
public void testPercentMatchJavaDocCommentStart() {
|
||||
configureByJavaText("/*<caret>* foo */");
|
||||
typeText(parseKeys("%"));
|
||||
myFixture.checkResult("/** foo *<caret>/");
|
||||
}
|
||||
|
||||
// |%|
|
||||
public void testPercentMatchJavaDocCommentEnd() {
|
||||
configureByJavaText("/** foo *<caret>/");
|
||||
typeText(parseKeys("%"));
|
||||
myFixture.checkResult("<caret>/** foo */");
|
||||
}
|
||||
|
||||
// |%|
|
||||
public void testPercentDoesntMatchAfterCommentStart() {
|
||||
configureByJavaText("/*<caret> foo */");
|
||||
typeText(parseKeys("%"));
|
||||
myFixture.checkResult("/*<caret> foo */");
|
||||
}
|
||||
|
||||
// |%|
|
||||
public void testPercentDoesntMatchBeforeCommentEnd() {
|
||||
configureByJavaText("/* foo <caret> */");
|
||||
typeText(parseKeys("%"));
|
||||
myFixture.checkResult("/* foo <caret> */");
|
||||
}
|
||||
|
||||
// |[(|
|
||||
public void testUnmatchedOpenParenthesis() {
|
||||
typeTextInFile(parseKeys("[("),
|
||||
@@ -580,24 +650,6 @@ public class MotionActionTest extends VimTestCase {
|
||||
assertOffset(4);
|
||||
}
|
||||
|
||||
// VIM-43 |i| |`.|
|
||||
public void testGotoLastChangePosition() {
|
||||
typeTextInFile(parseKeys("i", "hello ", "<Esc>", "gg", "`."),
|
||||
"one two\n" +
|
||||
"<caret>hello world\n" +
|
||||
"three four\n");
|
||||
assertOffset(13);
|
||||
}
|
||||
|
||||
// VIM-43 |p| |`.|
|
||||
public void testGotoLastPutPosition() {
|
||||
typeTextInFile(parseKeys("yy", "p", "gg", "`."),
|
||||
"one two\n" +
|
||||
"<caret>three\n" +
|
||||
"four five\n");
|
||||
assertOffset(14);
|
||||
}
|
||||
|
||||
// VIM-262 |c_CTRL-R|
|
||||
public void testSearchFromRegister() {
|
||||
VimPlugin.getRegister().setKeys('a', stringToKeys("two"));
|
||||
@@ -615,6 +667,35 @@ public class MotionActionTest extends VimTestCase {
|
||||
myFixture.checkResult("foo \n");
|
||||
}
|
||||
|
||||
// |CTRL-V|
|
||||
public void testVisualBlockSelectionsDisplayedCorrectlyMovingRight() {
|
||||
typeTextInFile(parseKeys("<C-V>jl"),
|
||||
"<caret>foo\n" +
|
||||
"bar\n");
|
||||
myFixture.checkResult("<selection>fo</selection>o\n" +
|
||||
"<selection>ba</selection>r\n");
|
||||
}
|
||||
|
||||
// |CTRL-V|
|
||||
public void testVisualBlockSelectionsDisplayedCorrectlyMovingLeft() {
|
||||
typeTextInFile(parseKeys("<C-V>jh"),
|
||||
"fo<caret>o\n" +
|
||||
"bar\n");
|
||||
myFixture.checkResult("f<selection>oo</selection>\n" +
|
||||
"b<selection>ar</selection>\n");
|
||||
}
|
||||
|
||||
// |CTRL-V|
|
||||
public void testVisualBlockSelectionsDisplayedCorrectlyInDollarMode() {
|
||||
typeTextInFile(parseKeys("<C-V>jj$"),
|
||||
"a<caret>b\n" +
|
||||
"abc\n" +
|
||||
"ab\n");
|
||||
myFixture.checkResult("a<selection>b</selection>\n" +
|
||||
"a<selection>bc</selection>\n" +
|
||||
"a<selection>b</selection>\n");
|
||||
}
|
||||
|
||||
// |v_o|
|
||||
public void testSwapVisualSelectionEnds() {
|
||||
typeTextInFile(parseKeys("v", "l", "o", "l", "d"),
|
||||
|
@@ -53,6 +53,18 @@ public class ShiftRightLinesActionTest extends VimTestCase {
|
||||
myFixture.checkResult(" Hello,\n world!\n\n");
|
||||
}
|
||||
|
||||
public void testShiftsMultiLineSelectionSkipsNewlineWhenCursorNotInFirstColumn() {
|
||||
myFixture.configureByText("a.txt", "<caret>Hello,\n\nworld!\n");
|
||||
typeText(parseKeys("lVG>"));
|
||||
myFixture.checkResult(" Hello,\n\n world!\n");
|
||||
}
|
||||
|
||||
public void testShiftsMultiLineSelectionAddsTrailingWhitespaceIfTherePreviouslyWas() {
|
||||
myFixture.configureByText("a.txt", "<caret>Hello,\n \nworld!\n");
|
||||
typeText(parseKeys("lVG>"));
|
||||
myFixture.checkResult(" Hello,\n \n world!\n");
|
||||
}
|
||||
|
||||
// VIM-705 repeating a multiline indent would only affect last line
|
||||
public void testShiftsMultiLineSelectionRepeat() {
|
||||
myFixture.configureByText("a.txt", "<caret>a\nb\n");
|
||||
@@ -64,4 +76,10 @@ public class ShiftRightLinesActionTest extends VimTestCase {
|
||||
myFixture.configureByText("a.txt", "\n");
|
||||
typeText(parseKeys("<I<>", "<I<>"));
|
||||
}
|
||||
|
||||
public void testShiftsVisualBlockMode() {
|
||||
myFixture.configureByText("a.txt", "foo<caret>foo\nfoobar\nfoobaz\n");
|
||||
typeText(parseKeys("<C-V>jjl>"));
|
||||
myFixture.checkResult("foo foo\nfoo bar\nfoo baz\n");
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package org.jetbrains.plugins.ideavim.ex;
|
||||
|
||||
import com.maddyhome.idea.vim.command.CommandState;
|
||||
import com.maddyhome.idea.vim.ex.VimScriptParser;
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptParser;
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase;
|
||||
|
||||
import static com.maddyhome.idea.vim.helper.StringHelper.parseKeys;
|
||||
@@ -243,4 +243,37 @@ public class MapCommandTest extends VimTestCase {
|
||||
typeText(parseKeys("A"));
|
||||
myFixture.checkResult("bar\n");
|
||||
}
|
||||
|
||||
// VIM-700 |:map|
|
||||
public void testRemappingZero() {
|
||||
configureByText("x<caret>yz\n");
|
||||
VimScriptParser.executeText("map 0 ~");
|
||||
typeText(parseKeys("0"));
|
||||
myFixture.checkResult("xYz\n");
|
||||
}
|
||||
|
||||
// VIM-700 |:map|
|
||||
public void testRemappingZeroStillAllowsZeroToBeUsedInCount() {
|
||||
configureByText("a<caret>bcdefghijklmnop\n");
|
||||
VimScriptParser.executeText("map 0 ^");
|
||||
typeText(parseKeys("10~"));
|
||||
myFixture.checkResult("aBCDEFGHIJKlmnop\n");
|
||||
}
|
||||
|
||||
// VIM-700 |:map|
|
||||
public void testRemappingDeleteOverridesRemovingLastDigitFromCount() {
|
||||
configureByText("a<caret>bcdefghijklmnop\n");
|
||||
VimScriptParser.executeText("map <Del> ~");
|
||||
typeText(parseKeys("10<Del>"));
|
||||
myFixture.checkResult("aBCDEFGHIJKlmnop\n");
|
||||
}
|
||||
|
||||
// VIM-650 |mapleader|
|
||||
public void testMapLeader() {
|
||||
configureByText("\n");
|
||||
typeText(commandToKeys("let mapleader = \",\""));
|
||||
typeText(commandToKeys("nmap <Leader>z izzz<Esc>"));
|
||||
typeText(parseKeys(",z"));
|
||||
myFixture.checkResult("zzz\n");
|
||||
}
|
||||
}
|
||||
|
122
test/org/jetbrains/plugins/ideavim/ex/RangeTest.java
Normal file
122
test/org/jetbrains/plugins/ideavim/ex/RangeTest.java
Normal file
@@ -0,0 +1,122 @@
|
||||
package org.jetbrains.plugins.ideavim.ex;
|
||||
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase;
|
||||
|
||||
/**
|
||||
* @author Tuomas Tynkkynen
|
||||
*/
|
||||
public class RangeTest extends VimTestCase {
|
||||
public void testNoRange() {
|
||||
myFixture.configureByText("a.txt", "1\n2\n<caret>3\n4\n5\n");
|
||||
typeText(commandToKeys("d"));
|
||||
myFixture.checkResult("1\n2\n4\n5\n");
|
||||
}
|
||||
|
||||
public void testCurrentLine() {
|
||||
myFixture.configureByText("a.txt", "1\n2\n<caret>3\n4\n5\n");
|
||||
typeText(commandToKeys(".d"));
|
||||
myFixture.checkResult("1\n2\n4\n5\n");
|
||||
}
|
||||
|
||||
public void testLastLine() {
|
||||
myFixture.configureByText("a.txt", "1\n2\n3\n4\n5\n");
|
||||
typeText(commandToKeys("$s/5/x/"));
|
||||
myFixture.checkResult("1\n2\n3\n4\nx\n");
|
||||
}
|
||||
|
||||
public void testOneLineNumber() {
|
||||
myFixture.configureByText("a.txt", "1\n2\n3\n4\n5\n");
|
||||
typeText(commandToKeys("3d"));
|
||||
myFixture.checkResult("1\n2\n4\n5\n");
|
||||
}
|
||||
|
||||
public void testPositiveOffset() {
|
||||
myFixture.configureByText("a.txt", "1\n2\n<caret>3\n4\n5\n");
|
||||
typeText(commandToKeys(".+1d"));
|
||||
myFixture.checkResult("1\n2\n3\n5\n");
|
||||
}
|
||||
|
||||
public void testNegativeOffset() {
|
||||
myFixture.configureByText("a.txt", "1\n2\n3\n4\n5\n");
|
||||
typeText(commandToKeys("$-2d"));
|
||||
myFixture.checkResult("1\n2\n4\n5\n");
|
||||
}
|
||||
|
||||
public void testOffsetWithNoNumber() {
|
||||
myFixture.configureByText("a.txt", "1\n2\n<caret>3\n4\n5\n");
|
||||
typeText(commandToKeys(".+d"));
|
||||
myFixture.checkResult("1\n2\n3\n5\n");
|
||||
}
|
||||
|
||||
public void testTwoOffsetsWithSameSign() {
|
||||
myFixture.configureByText("a.txt", "1\n<caret>2\n3\n4\n5\n");
|
||||
typeText(commandToKeys(".+1+1d"));
|
||||
myFixture.checkResult("1\n2\n3\n5\n");
|
||||
}
|
||||
|
||||
public void testTwoOffsetsWithDifferentSign() {
|
||||
myFixture.configureByText("a.txt", "1\n<caret>2\n3\n4\n5\n");
|
||||
typeText(commandToKeys(".+2-1d"));
|
||||
myFixture.checkResult("1\n2\n4\n5\n");
|
||||
}
|
||||
|
||||
public void testSearchForward() {
|
||||
myFixture.configureByText("a.txt", "c\na\n<caret>b\nc\nd\ne\n");
|
||||
typeText(commandToKeys("/c/d"));
|
||||
myFixture.checkResult("c\na\nb\nd\ne\n");
|
||||
}
|
||||
|
||||
public void testSearchBackward() {
|
||||
myFixture.configureByText("a.txt", "c\na\n<caret>b\nc\nd\ne\n");
|
||||
typeText(commandToKeys("?c?d"));
|
||||
myFixture.checkResult("a\nb\nc\nd\ne\n");
|
||||
}
|
||||
|
||||
public void testSearchWithBackslashInPattern() {
|
||||
myFixture.configureByText("a.txt", "+ add\n<caret>- sub\n/ div\n* mul\n");
|
||||
typeText(commandToKeys("/\\/ div/d"));
|
||||
myFixture.checkResult("+ add\n- sub\n* mul\n");
|
||||
}
|
||||
|
||||
public void testAllLinesRange() {
|
||||
myFixture.configureByText("a.txt", "1\n2\n3\n4\n5\n");
|
||||
typeText(commandToKeys("%d"));
|
||||
myFixture.checkResult("\n");
|
||||
}
|
||||
|
||||
public void testMultipleLineNumbersRange() {
|
||||
myFixture.configureByText("a.txt", "1\n2\n3\n4\n5\n");
|
||||
typeText(commandToKeys("2,4d"));
|
||||
myFixture.checkResult("1\n5\n");
|
||||
}
|
||||
|
||||
public void testMultipleLineNumbersWithOffsetInFirst() {
|
||||
myFixture.configureByText("a.txt", "<caret>1\n2\n3\n4\n5\n");
|
||||
typeText(commandToKeys(".+1,4d"));
|
||||
myFixture.checkResult("1\n5\n");
|
||||
}
|
||||
|
||||
public void testMultipleLineNumbersWithOffsetInSecond() {
|
||||
myFixture.configureByText("a.txt", "1\n2\n3\n4\n5\n");
|
||||
typeText(commandToKeys("2,$-1d"));
|
||||
myFixture.checkResult("1\n5\n");
|
||||
}
|
||||
|
||||
public void testSearchStartPositionWithComma() {
|
||||
myFixture.configureByText("a.txt", "1\n2\n3\n4\n5\n");
|
||||
typeText(commandToKeys("/2/,/[0-9]/d"));
|
||||
myFixture.checkResult("1\n3\n4\n5\n");
|
||||
}
|
||||
|
||||
public void testSearchStartPositionWithSemicolon() {
|
||||
myFixture.configureByText("a.txt", "1\n2\n3\n4\n5\n");
|
||||
typeText(commandToKeys("/2/;/[0-9]/d"));
|
||||
myFixture.checkResult("1\n4\n5\n");
|
||||
}
|
||||
|
||||
public void testMultipleSearches() {
|
||||
myFixture.configureByText("a.txt", "a\nfoo\nbar\nfoo\nbar\nbaz\n");
|
||||
typeText(commandToKeys("/bar//foo/d"));
|
||||
myFixture.checkResult("a\nfoo\nbar\nbar\nbaz\n");
|
||||
}
|
||||
}
|
@@ -92,4 +92,10 @@ public class SortCommandTest extends VimTestCase {
|
||||
typeText(commandToKeys("sort"));
|
||||
myFixture.checkResult("a\nb\nc\nwhatever\nzee");
|
||||
}
|
||||
|
||||
public void testSortWithPrecedingWhiteSpace() {
|
||||
myFixture.configureByText("a.txt", " zee\n c\n a\n b\n whatever");
|
||||
typeText(commandToKeys("sort"));
|
||||
myFixture.checkResult(" a\n b\n c\n whatever\n zee");
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,8 @@ package org.jetbrains.plugins.ideavim.ex;
|
||||
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase;
|
||||
|
||||
import static com.maddyhome.idea.vim.helper.StringHelper.parseKeys;
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
@@ -75,6 +77,33 @@ public class SubstituteCommandTest extends VimTestCase {
|
||||
"one\n.two\n.three\n");
|
||||
}
|
||||
|
||||
// VIM-702 |:substitute|
|
||||
public void testEndOfLineToNL() {
|
||||
doTest("%s/$/\\r/g",
|
||||
"<caret>one\ntwo\nthree\n",
|
||||
"one\n\ntwo\n\nthree\n\n");
|
||||
}
|
||||
|
||||
// VIM-702 |:substitute|
|
||||
public void testStartOfLineToNL() {
|
||||
doTest("%s/^/\\r/g",
|
||||
"<caret>one\ntwo\nthree\n",
|
||||
"\none\n\ntwo\n\nthree\n");
|
||||
}
|
||||
|
||||
// VIM-864 |:substitute|
|
||||
public void testVisualSubstituteDoesntChangeVisualMarks() {
|
||||
myFixture.configureByText("a.java", "foo\nbar\nbaz\n");
|
||||
typeText(parseKeys("V", "j", ":'<,'>s/foo/fuu/<Enter>", "gv", "~"));
|
||||
myFixture.checkResult("FUU\nBAR\nbaz\n");
|
||||
}
|
||||
|
||||
public void testOffsetRange() {
|
||||
doTest(".,+2s/a/b/g",
|
||||
"aaa\naa<caret>a\naaa\naaa\naaa\n",
|
||||
"aaa\nbbb\nbbb\nbbb\naaa\n");
|
||||
}
|
||||
|
||||
private void doTest(final String command, String before, String after) {
|
||||
myFixture.configureByText("a.java", before);
|
||||
typeText(commandToKeys(command));
|
||||
|
@@ -0,0 +1,21 @@
|
||||
package org.jetbrains.plugins.ideavim.ex;
|
||||
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase;
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
public class VimScriptParserTest extends VimTestCase {
|
||||
public void testEchoStringLiteral() {
|
||||
configureByText("\n");
|
||||
typeText(commandToKeys("echo \"Hello, World!\""));
|
||||
assertExOutput("Hello, World!\n");
|
||||
}
|
||||
|
||||
public void testLetStringLiteralEcho() {
|
||||
configureByText("\n");
|
||||
typeText(commandToKeys("let s = \"foo\""));
|
||||
typeText(commandToKeys("echo s"));
|
||||
assertExOutput("foo\n");
|
||||
}
|
||||
}
|
@@ -74,6 +74,26 @@ public class SearchGroupTest extends VimTestCase {
|
||||
assertEquals(5, pos);
|
||||
}
|
||||
|
||||
// VIM-855 |/|
|
||||
public void testCharacterClassRegression() {
|
||||
final int pos = search("[^c]b",
|
||||
"<caret>bb\n");
|
||||
assertEquals(0, pos);
|
||||
}
|
||||
|
||||
// VIM-855 |/|
|
||||
public void testCharacterClassRegressionCaseInsensitive() {
|
||||
final int pos = search("\\c[ABC]D",
|
||||
"<caret>dd\n");
|
||||
assertEquals(-1, pos);
|
||||
}
|
||||
|
||||
// VIM-856 |/|
|
||||
public void testNegativeLookbehindRegression() {
|
||||
final int pos = search("a\\@<!b",
|
||||
"<caret>ab\n");
|
||||
assertEquals(-1, pos);
|
||||
}
|
||||
|
||||
// |/|
|
||||
public void testSearchMotion() {
|
||||
|
Reference in New Issue
Block a user