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

Compare commits

...

84 Commits
0.39 ... 0.41

Author SHA1 Message Date
Andrey Vlasovskikh
68c20ed48d Version 0.41 2015-06-10 15:42:02 +03:00
Andrey Vlasovskikh
c5760ceaab VIM-957 Fixed compatibility with IDEs other than IntelliJ 2015-06-10 15:41:33 +03:00
Andrey Vlasovskikh
8c7c9a67a6 Version 0.40 2015-06-09 23:01:54 +03:00
Andrey Vlasovskikh
85231b314f More readable test data 2015-04-24 16:29:56 +03:00
Andrey Vlasovskikh
210b2efd47 Updated changelog 2015-04-24 16:12:30 +03:00
Andrey Vlasovskikh
ae5b1385ea Merge branch 'matching-comments' 2015-04-24 16:08:54 +03:00
Andrey Vlasovskikh
011ce28251 More readable tests for '%' 2015-04-24 16:08:32 +03:00
Andrey Vlasovskikh
efb58b45df Cleanup 2015-04-24 16:02:20 +03:00
Andrey Vlasovskikh
7d033787eb Better place for cleaning global variables 2015-04-24 14:31:06 +03:00
Andrey Vlasovskikh
3a47583cf9 Clean global variables 2015-04-24 14:27:38 +03:00
Andrey Vlasovskikh
565b4b3f2f Updated changelog 2015-04-24 14:25:10 +03:00
Andrey Vlasovskikh
574f32a6dd Merge pull request #84 from JetBrains/mapleader
Mapleader support based on the prototype of a Vim script expressions evaluator
2015-04-24 13:33:38 +03:00
Andrey Vlasovskikh
0e67c8ff69 Removed unnecessary 'static' declaration 2015-04-24 13:32:26 +03:00
Andrey Vlasovskikh
b886073c11 VIM-650 Added support for 'mapleader' 2015-04-24 13:32:04 +03:00
Andrey Vlasovskikh
57c35b9a74 Merge remote-tracking branch 'origin/master' 2015-04-22 20:27:31 +03:00
Andrey Vlasovskikh
f5100694d6 VIM-930 Get editor focus after closing Ex entry box on Oracle Java 6 2015-04-22 20:26:41 +03:00
Andrey Vlasovskikh
3ff9bfcc13 Initial support for 'let' and 'echo' commands
These commands evaluate Vim script expressions. Right now they are
limited to a highly limited subset of Vim script expressions that is
however enough for settings the 'mapleader' variable for VIM-650.
2015-04-05 22:54:40 +03:00
Andrey Vlasovskikh
6c8d2bfd9e Merge pull request #83 from khromalabs/master
Added deployment instructions to README.md
2015-04-04 23:10:24 +03:00
Rubén Gómez
637f7f48ad Modified deployment instructions in README.md as suggested in pull request #83 2015-04-02 09:11:52 +02:00
Rubén Gómez
8eae80d30f Added deployment instructions to README.md 2015-03-30 23:55:04 +02:00
Andrey Vlasovskikh
9a103276e3 Merge pull request #82 from jflorian/master
Added note about where .ideavimrc is located
2015-03-30 16:39:52 +03:00
John Florian
6386f011f7 Merge remote-tracking branch 'upstream/master' 2015-03-30 09:32:09 -04:00
John Florian
742d6e63d9 Change - note regarding non-default user.home setting
Some users (e.g., me) have a non-default user.home VM option and this
affects where IdeaVim looks for its configuration file.  This note might
save some head scratching.
2015-03-30 09:26:32 -04:00
Andrey Vlasovskikh
f6141603ef Merge pull request #81 from jflorian/master
Аdd mapping example using :action
2015-03-29 02:20:19 +03:00
John Florian
7a5b4e565a Change - add mapping example using :action
This example may be helpful to regular VIM users since the :action and
:actionlist commands are specific to IdeaVIM.
2015-03-28 11:12:02 -04:00
Andrey Vlasovskikh
373e1527c1 Extracted Vim script parts into 'vimscript' package 2015-03-28 14:16:38 +03:00
Andrey Vlasovskikh
9cb05b6a7d Updated changelog 2015-03-27 21:55:45 +03:00
Andrey Vlasovskikh
74bf5ff044 Formatting and typos 2015-03-27 21:43:36 +03:00
Andrey Vlasovskikh
0f7e9d11b6 Added test for VIM-845 2015-03-27 21:43:19 +03:00
Andrey Vlasovskikh
5fadc2fb9f Removed unused imports 2015-03-27 21:30:05 +03:00
Andrey Vlasovskikh
96bbcf623f Removed unnecessary 'static' in enums 2015-03-27 21:20:17 +03:00
Andrey Vlasovskikh
89e853158c Typos 2015-03-27 21:19:56 +03:00
Andrey Vlasovskikh
5c31fcc03e Extracted CommandState.inVisualBlockMode() 2015-03-27 21:18:08 +03:00
Andrey Vlasovskikh
3fee4a803b Merge remote-tracking branch 'dezgeg/fixes/visual-block-mode-overhaul' 2015-03-27 20:56:58 +03:00
Andrey Vlasovskikh
8b61f559d7 Updated default code style settings 2015-03-24 23:52:04 +03:00
Andrey Vlasovskikh
4bd058f5dc Updated changelog 2015-03-24 23:51:34 +03:00
Andrey Vlasovskikh
999ccf87fc Merge remote-tracking branch 'dezgeg/fixes/vim-700-remap-zero' 2015-03-24 23:48:11 +03:00
Andrey Vlasovskikh
4e45e885b9 Merge remote-tracking branch 'dezgeg/feature/ant-improvements' 2015-03-24 23:25:31 +03:00
Tuomas Tynkkynen
6aee9ccaf1 build.xml: forkmode=once makes tests much faster
Since classloading of the IntelliJ platform takes a lot of time,
using forkmode=once in the Ant file makes running the unit tests from
Ant much faster (down to 16 seconds from 93 seconds) and is also more
closer to how the tests are run in the IDE.
2015-02-21 21:25:47 +02:00
Tuomas Tynkkynen
af3c6ff012 build.xml: Generate XML reports from JUnit test reports
The XML reports are useful for private CI servers like Jenkins.
2015-02-21 21:25:47 +02:00
Tuomas Tynkkynen
0c9bdf5168 Visual block mode overhaul
The current visual block mode implementation has several bugs:

- The GUI never displays the rightmost characters as selected (blue)
- Due to some off-by-one, commands can't act on each line's last character
- It's possible for newlines to get deleted/changed into something else
- If the '$' mode is entered, the GUI doesn't always indicate this
- It's impossible to move to an empty line (VIM-781)

This commit fixes all of those problems. The only remaining problem are
the visible secondary carets, which makes seeing the real cursor a bit
difficult. This could be fixed later if support for per-caret visibility
would be added to IntelliJ core.
2015-02-21 17:17:36 +02:00
Tuomas Tynkkynen
82a9587b4f Support comments in brace matching
In Vim, '%' can be used to jump between the '/*' and '*/' of block
comments. Support this functionality in a language-independent manner.
2015-02-21 15:14:38 +02:00
Tuomas Tynkkynen
850f4d7ec5 Make IdeaVIM build on latest intellij-community master
The zero-parameter overload of createStructureViewModel() has been
marked deprecated and is now removed.
2015-02-21 15:12:16 +02:00
Tuomas Tynkkynen
8d1dcc4568 VIM-700 Remapping '0' should still allow zero to be entered in count
Previously, remapping '0' in command mode would prevent a number zero
from being entered in a command count.
2015-02-21 15:09:13 +02:00
Andrey Vlasovskikh
3650ab85df Updated changelog 2015-01-21 19:50:50 +03:00
Andrey Vlasovskikh
e1e1cc2666 Code style
Use javadoc comments, added nullity annotations, extracted common
expressions.
2015-01-21 19:49:41 +03:00
Tuomas Tynkkynen
79fd32088b VIM-868 Allow count on 'gt' and 'gT'
'{count}gt' can now be used to switch to a specific tab.
'{count}gT' can now be used to switch to a n:th previous tab.
2015-01-21 18:11:48 +02:00
Andrey Vlasovskikh
458e0fc76d Updated changelog 2015-01-21 16:31:26 +03:00
Tuomas Tynkkynen
5090c81632 VIM-856 Fix regex lookbehind bugs
The regex code has the following bugs, mostly related to lookbehind:
    - Comparison of CharPointers with == is wrong, .equals should be
      used instead.

    - In the original C code, the behind_pos variable is declared as
      'static regsave_T behind_pos;', i.e. not a pointer, and the same
      for other variables of type regsave_T. So assignments to these
      types of variables need to make deep copies.
2015-01-20 17:52:08 +02:00
Andrey Vlasovskikh
dcd035353b Updated IntelliJ version to the latest one available for download 2015-01-20 18:41:00 +03:00
Andrey Vlasovskikh
8606ce21bd Added Jackson Popkin to the contributors 2015-01-20 17:47:50 +03:00
Andrey Vlasovskikh
72537c6ffb Merge remote-tracking branch 'jdpopkin/relative_range'
Conflicts:
	test/org/jetbrains/plugins/ideavim/ex/SubstituteCommandTest.java
2015-01-20 17:17:27 +03:00
Andrey Vlasovskikh
30f9888f51 Merge remote-tracking branch 'selesse/sort-fix' 2015-01-20 16:06:36 +03:00
Andrey Vlasovskikh
d5a2b92121 Updated changelog 2015-01-20 15:59:39 +03:00
Andrey Vlasovskikh
fd3eee6870 Merge remote-tracking branch 'dezgeg/fixes/vim-864-visual-substitute-incorrect-visual-marks' 2015-01-20 15:50:17 +03:00
Andrey Vlasovskikh
2d6d1003b7 Merge remote-tracking branch 'dezgeg/fixes/vim-575-split-cursor' 2015-01-20 15:44:46 +03:00
Andrey Vlasovskikh
499c590f5a Merge remote-tracking branch 'dezgeg/unit-tests' 2015-01-20 15:36:18 +03:00
Andrey Vlasovskikh
787b78ef36 Typo 2015-01-20 15:31:46 +03:00
Andrey Vlasovskikh
88a0b0fa23 Removed unused ExEntryPanel.processKey() 2015-01-20 15:31:33 +03:00
Andrey Vlasovskikh
1519f04930 Fixed potential NPEs 2015-01-20 15:30:17 +03:00
Andrey Vlasovskikh
e0a1291de0 Merge remote-tracking branch 'dezgeg/fixes/vim-210-ex-focus' 2015-01-20 15:27:55 +03:00
Andrey Vlasovskikh
8a2d881002 Cleanup
Removed commented code, renamed '\0' to '\u0000' for consistency,
fixed nullable warnings, declared some variables final.
2015-01-20 14:50:55 +03:00
Tuomas Tynkkynen
4802b6f460 VIM-864 Fix visual marks getting changed during visual substitute
Previously, running a substitute command in visual mode would
incorrectly set the visual mode end mark (>) to the location of the last
search match.
2014-12-24 18:19:53 +02:00
Jackson Popkin
8c0e116a1c Fix incorrect behavior in substitution with offset ranges
Substitution commands with offset ranges like .,+2s/a/b/g previously
did not work the way they do in Vim (replace a with b on the current
line and the next two lines). This change fixes that bug.
2014-12-23 21:14:42 -05:00
Alex Selesse
8862878011 Fix broken sorting when sorting with leading whitespace 2014-12-14 12:17:51 -05:00
Tuomas Tynkkynen
bdf3361243 VIM-575 Don't change cursor position of other splits in visual mode
If a file is opened in multiple splits, entering visual mode in one
split would change the cursor position in other splits as well.
2014-12-14 15:20:36 +02:00
Tuomas Tynkkynen
6b5216077b Add few simple mark tests. 2014-12-12 23:05:28 +02:00
Tuomas Tynkkynen
7e119f7963 Add tests for change number operations (<C-A>, <C-X>) 2014-12-12 23:05:28 +02:00
Tuomas Tynkkynen
933cbc7e51 Add unit tests for some replace commands
Adds tests for: |r|, |s|, |R|, and <Ins> in insert mode.
2014-12-12 23:05:28 +02:00
Tuomas Tynkkynen
65f30d4480 Add testcase for '>' in visual block mode 2014-12-12 23:05:28 +02:00
Tuomas Tynkkynen
1f8d3f119e Add unit tests for Ex ranges
Adds tests for ranges in Ex commands. Almost every kind of range has
basic tests, except the following are still totally untested:
    - \/, \?, \&
    - register ranges
    - syntax errors in ranges
2014-12-12 23:05:28 +02:00
Tuomas Tynkkynen
45fe858503 Add tests for case changing operations
Add tests for the following commands:
- gu, gU, g~ in normal mode
- u, U, ~ in visual mode
2014-12-12 23:05:28 +02:00
Tuomas Tynkkynen
0cc06ad186 Move ChangeActionTest.doTest() to VimTestCase.
This method is convenient in other tests as well.
2014-12-12 23:05:28 +02:00
Tuomas Tynkkynen
18cd7547ad VIM-210 Fix focus issues with the Ex panel
Previously, if the editor window had been splitted, under certain
conditions some actions related to the Ex panel would cause the editor
focus to change to a different split.

The required conditions for this bug to occur:
    - no docked windows (like the Project sidebar) are open
    - 'View -> Navigation bar' is disabled

At least these actions triggered the bug:
    - search with /
    - successfully executing an Ex command
    - dismissing the Ex window with Esc
    - Ex commands that opened the output panel (e.g. :!)

All the deleted lines of the form
    FileEditorManager.getInstance(project).openFile(vf, true);
seem to be very old, non-functional workarounds for the focus issue.
2014-12-09 13:36:03 +02:00
Tuomas Tynkkynen
7746a26062 VIM-855 Fix regexp character class bugs
Previously strchr and istrchr didn't consider NUL chars as end-of-string
terminators. This caused problems in regexps using character classes:
a regexp like "[^a]bc" would be effectively treated as "[^abc]bc" - i.e.
some literal characters from the rest of the pattern would accidentally be
included in the character class.
2014-12-09 01:01:53 +02:00
Andrey Vlasovskikh
a47fc9d3be Don't share editor data contexts
The previous code threw "cannot share data context between Swing events"
throwables from DataManagerImpl$MyDataContext.getData since we used to
share DataContext objects passed to
VimShortcutKeyAction.actionPerformed() and
VimTypedActionHandler.execute() inside AnActionEvent objects with
runnables we invoked via SwingUtilities.invokeLater().
2014-12-07 18:40:51 +03:00
Andrey Vlasovskikh
8fdf75330c Updated changelog 2014-12-07 16:43:52 +03:00
Andrey Vlasovskikh
d6ebaa26b0 Merge branch 'invoke-shortcuts-handler-later' 2014-12-07 16:42:31 +03:00
Andrey Vlasovskikh
27bd7ec836 Merge remote-tracking branch 'dezgeg/fixes/misc-issues' 2014-12-07 16:28:15 +03:00
Andrey Vlasovskikh
f2a0408801 VIM-586 Try to invoke Vim shortcuts handler later to restore input events sequence 2014-11-27 15:09:06 +03:00
Tuomas Tynkkynen
7ccb6c8411 Optimize character case changing operations
Previously, performing e.g. visual '~' on a large file would completely
lock up the IDE. The culprit seemed to be the calls to replaceText() one
character at a time, which is not a cheap operation since each
replaceText() will for example trigger a DocumentChanged event.
2014-11-22 13:15:15 +02:00
Tuomas Tynkkynen
1518831f37 Add some missing key names. 2014-11-22 13:15:15 +02:00
Tuomas Tynkkynen
3bdfaa02e1 'J' shouldn't add whitespace if there is trailing whitespace 2014-11-22 13:15:11 +02:00
Tuomas Tynkkynen
e8de9f915c Make '>' not add trailing whitespace to empty lines. 2014-11-22 13:14:23 +02:00
50 changed files with 1440 additions and 293 deletions

View File

@@ -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>

View File

@@ -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.

View File

@@ -4,6 +4,43 @@ The Changelog
History of changes in IdeaVim for the IntelliJ platform.
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
----------------

View File

@@ -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.

View File

@@ -1,4 +1,4 @@
version-id:0.39
version-id:0.41
platform-version:135.0
idea.download.url=http://download.jetbrains.com/idea/ideaIU-14.0.1.zip
idea.download.url=http://download.jetbrains.com/idea/ideaIU-14.0.2.zip
build.number=dev

View File

@@ -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}">

View File

@@ -1,8 +1,17 @@
<idea-plugin url="http://plugins.jetbrains.com/plugin/164">
<name>IdeaVim</name>
<id>IdeaVIM</id>
<change-notes>
<![CDATA[
<change-notes><![CDATA[
<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>
@@ -25,30 +34,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>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>

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);
}
}
});
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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,

View File

@@ -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 == '\\') {

View File

@@ -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);
}
}

View 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;
}
}

View 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");
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View 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;
/**

View File

@@ -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;
}
}

View File

@@ -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));

View 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;
}

View File

@@ -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);

View File

@@ -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());
}
}
}

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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';
}

View File

@@ -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();
}
});
}
});
}
}

View File

@@ -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() {

View File

@@ -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 \(\) */

View File

@@ -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);

View File

@@ -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();

View File

@@ -1,6 +1,7 @@
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;
@@ -18,6 +19,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;
@@ -68,7 +70,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 +93,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 +158,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);
}
}

View File

@@ -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);
}
}

View File

@@ -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");
}
}

View 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);
}
}

View File

@@ -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"),

View File

@@ -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");
}
}

View File

@@ -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");
}
}

View 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");
}
}

View File

@@ -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");
}
}

View File

@@ -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
*/
@@ -89,6 +91,19 @@ public class SubstituteCommandTest extends VimTestCase {
"\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));

View File

@@ -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");
}
}

View File

@@ -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() {