mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-18 01:31:44 +02:00
Compare commits
224 Commits
0.55.1-EAP
...
0.57.1-EAP
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0adde753f4 | ||
![]() |
5f28a22666 | ||
![]() |
a975b53894 | ||
![]() |
98aee5d0ab | ||
![]() |
f57af8bf9e | ||
![]() |
c6c3b6643e | ||
![]() |
af94079b92 | ||
![]() |
7203cc5cb3 | ||
![]() |
028423cf58 | ||
![]() |
2ead6af96a | ||
![]() |
bf853e3c0c | ||
![]() |
c85f41e65b | ||
![]() |
2759bed1b2 | ||
![]() |
89c2a8ec9b | ||
![]() |
aa2c1257ac | ||
![]() |
f9fa15b7ac | ||
![]() |
93a9be41bc | ||
![]() |
ecd2f2032c | ||
![]() |
de5ce5f635 | ||
![]() |
2eb6fd6819 | ||
![]() |
22ea4e7ffa | ||
![]() |
3d98f3035f | ||
![]() |
ec1d6ac477 | ||
![]() |
0dc236cb5b | ||
![]() |
98349a49fd | ||
![]() |
ab8be2cada | ||
![]() |
b8c22d0928 | ||
![]() |
c6cf77e4b8 | ||
![]() |
6c0511a898 | ||
![]() |
366c862bcf | ||
![]() |
03493e2390 | ||
![]() |
8f9c71dd55 | ||
![]() |
11beb1e331 | ||
![]() |
01b4dc233a | ||
![]() |
9f1e80e969 | ||
![]() |
7e319e11c6 | ||
![]() |
d11bf1c4d2 | ||
![]() |
3e2f18b757 | ||
![]() |
61677aa811 | ||
![]() |
fb04e835ef | ||
![]() |
bb133922d6 | ||
![]() |
44dd5ef872 | ||
![]() |
bcc8e1c055 | ||
![]() |
71117ed335 | ||
![]() |
de07fb3b74 | ||
![]() |
e31d5a4dcf | ||
![]() |
e14aae761d | ||
![]() |
47db2a247c | ||
![]() |
e449bb9692 | ||
![]() |
b8fc72b6a7 | ||
![]() |
64c01c1bd1 | ||
![]() |
0a0e3df42b | ||
![]() |
949c69a7e9 | ||
![]() |
69caf7a604 | ||
![]() |
23860ad5f9 | ||
![]() |
ace5234d8d | ||
![]() |
4654f821a9 | ||
![]() |
927e0e7865 | ||
![]() |
d47c9735b5 | ||
![]() |
6100433636 | ||
![]() |
43f79e8183 | ||
![]() |
f58fda0c87 | ||
![]() |
64b49e37d7 | ||
![]() |
e44418d410 | ||
![]() |
ca8d05ff13 | ||
![]() |
626871e34d | ||
![]() |
4b659fe643 | ||
![]() |
d5055506b0 | ||
![]() |
55f54b2e82 | ||
![]() |
1b18065e68 | ||
![]() |
053dc02152 | ||
![]() |
b8cb4a1295 | ||
![]() |
cd2cbf68a1 | ||
![]() |
73f3be8af0 | ||
![]() |
8cce059fb4 | ||
![]() |
db641ec6f6 | ||
![]() |
9d8239b68d | ||
![]() |
4ec0bac275 | ||
![]() |
613c234cfb | ||
![]() |
83dca71f69 | ||
![]() |
f7ea9cdb6e | ||
![]() |
762cb1804f | ||
![]() |
962cfb7ae2 | ||
![]() |
9bc2ec7d8a | ||
![]() |
8415d104e9 | ||
![]() |
abd0f9b961 | ||
![]() |
0a4683d908 | ||
![]() |
4c280b0193 | ||
![]() |
e88a3deafd | ||
![]() |
7de08e08d0 | ||
![]() |
bd172b3300 | ||
![]() |
95c7a13cb5 | ||
![]() |
b1ddf03385 | ||
![]() |
a83c326736 | ||
![]() |
b1acb56247 | ||
![]() |
caa4731a13 | ||
![]() |
5b0ece7a91 | ||
![]() |
a4cd94847e | ||
![]() |
a0a7386b51 | ||
![]() |
535a72000f | ||
![]() |
60531b9cd2 | ||
![]() |
8f86ad696d | ||
![]() |
c9bda98a6a | ||
![]() |
9ea08da133 | ||
![]() |
5762ec0518 | ||
![]() |
7db74460fa | ||
![]() |
c8d64e0a06 | ||
![]() |
1a3dea0de6 | ||
![]() |
17b642280e | ||
![]() |
1c1717b78b | ||
![]() |
4bbbdf8108 | ||
![]() |
04a193309d | ||
![]() |
f106ffa176 | ||
![]() |
8d5d099542 | ||
![]() |
4849992ca9 | ||
![]() |
623105650e | ||
![]() |
5e2c01daa6 | ||
![]() |
58bf3a4d30 | ||
![]() |
2d434c38b9 | ||
![]() |
246f5cd8cf | ||
![]() |
5a174d21f1 | ||
![]() |
e632c653f6 | ||
![]() |
174d17b088 | ||
![]() |
3a35c931e4 | ||
![]() |
b768b26c85 | ||
![]() |
123ce6ebaf | ||
![]() |
276c8db512 | ||
![]() |
f898b8d181 | ||
![]() |
e9f9e531e4 | ||
![]() |
a7d813cb86 | ||
![]() |
75b6eedb12 | ||
![]() |
ec6860aa90 | ||
![]() |
5cf661c6ae | ||
![]() |
8c62caae7c | ||
![]() |
cc6fe21af6 | ||
![]() |
1902151efa | ||
![]() |
b7af1e6289 | ||
![]() |
0c77b320db | ||
![]() |
ee41adc4e9 | ||
![]() |
93462d7505 | ||
![]() |
2f5946640e | ||
![]() |
7cdb7dc308 | ||
![]() |
2f148255f7 | ||
![]() |
cb00b8b335 | ||
![]() |
559b56c8a2 | ||
![]() |
c0038d0373 | ||
![]() |
2820decb5e | ||
![]() |
c64f368e6a | ||
![]() |
b7c8e84f5e | ||
![]() |
5acf6c9158 | ||
![]() |
a8197b0c84 | ||
![]() |
2e03062c24 | ||
![]() |
7fb60a185b | ||
![]() |
0327ea972b | ||
![]() |
561cc77ecc | ||
![]() |
a1ab4acd14 | ||
![]() |
d4939803da | ||
![]() |
730ce3aca9 | ||
![]() |
1893dc6afd | ||
![]() |
6ec39314ee | ||
![]() |
158cea51db | ||
![]() |
33d34f35e9 | ||
![]() |
1f4f40fd7c | ||
![]() |
7c908b247e | ||
![]() |
c87528939b | ||
![]() |
41c822fde1 | ||
![]() |
e56646105d | ||
![]() |
b8a40d93f7 | ||
![]() |
4bfc025248 | ||
![]() |
36f6027b0e | ||
![]() |
e032377e68 | ||
![]() |
929eee4a12 | ||
![]() |
61ce50264a | ||
![]() |
48927b1207 | ||
![]() |
0820893dc6 | ||
![]() |
dd6079cfa6 | ||
![]() |
2a6569742d | ||
![]() |
3d7d75bae4 | ||
![]() |
6da4d0ce5e | ||
![]() |
4994d70b1a | ||
![]() |
c873081dc3 | ||
![]() |
070237f77f | ||
![]() |
eb01b25f35 | ||
![]() |
c0c9cfaf86 | ||
![]() |
304f860eb2 | ||
![]() |
2f18b25593 | ||
![]() |
14c8b6a248 | ||
![]() |
adaa683e58 | ||
![]() |
9b71215cde | ||
![]() |
8be572f976 | ||
![]() |
4f43bcffb9 | ||
![]() |
29e4dc5fb5 | ||
![]() |
0dc95cb13c | ||
![]() |
5ee0a93675 | ||
![]() |
767b3c4a39 | ||
![]() |
bb948a463c | ||
![]() |
e4e9a03d0a | ||
![]() |
50ba386f59 | ||
![]() |
79d0565c2d | ||
![]() |
bcc9b0a7b1 | ||
![]() |
2c8f4940b9 | ||
![]() |
41876cf8fd | ||
![]() |
f6fd0b52f0 | ||
![]() |
843faa7cc6 | ||
![]() |
a8af2c3242 | ||
![]() |
e5bfad974e | ||
![]() |
59d87e0c94 | ||
![]() |
50c2d04503 | ||
![]() |
480de62686 | ||
![]() |
955b501058 | ||
![]() |
d985527624 | ||
![]() |
afbe7f0e69 | ||
![]() |
94e65ddce6 | ||
![]() |
cb9f144255 | ||
![]() |
ac84624faa | ||
![]() |
c2196785e7 | ||
![]() |
30097fbae6 | ||
![]() |
c295dd5c62 | ||
![]() |
373fef2824 | ||
![]() |
cfc255bf2b | ||
![]() |
ea7e58535b | ||
![]() |
9fad4a74ed | ||
![]() |
ff209d0120 | ||
![]() |
ea2fe618b5 |
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,6 +1,13 @@
|
||||
*.swp
|
||||
/.gradle/
|
||||
|
||||
/.idea/
|
||||
!/.idea/scopes
|
||||
!/.idea/copyright
|
||||
!/.idea/icon.png
|
||||
|
||||
/build/
|
||||
/out/
|
||||
/tmp/
|
||||
|
||||
*.DS_Store
|
6
.idea/copyright/IdeaVim.xml
generated
Normal file
6
.idea/copyright/IdeaVim.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<component name="CopyrightManager">
|
||||
<copyright>
|
||||
<option name="notice" value="IdeaVim - Vim emulator for IDEs based on the IntelliJ platform Copyright (C) 2003-&#36;today.year 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 <https://www.gnu.org/licenses/>." />
|
||||
<option name="myName" value="IdeaVim" />
|
||||
</copyright>
|
||||
</component>
|
7
.idea/copyright/profiles_settings.xml
generated
Normal file
7
.idea/copyright/profiles_settings.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<component name="CopyrightManager">
|
||||
<settings>
|
||||
<module2copyright>
|
||||
<element module="Copyright" copyright="IdeaVim" />
|
||||
</module2copyright>
|
||||
</settings>
|
||||
</component>
|
BIN
.idea/icon.png
generated
Normal file
BIN
.idea/icon.png
generated
Normal file
Binary file not shown.
After Width: | Height: | Size: 113 KiB |
3
.idea/scopes/Copyright.xml
generated
Normal file
3
.idea/scopes/Copyright.xml
generated
Normal file
@@ -0,0 +1,3 @@
|
||||
<component name="DependencyValidationManager">
|
||||
<scope name="Copyright" pattern="file[IdeaVIM.main]:com//*||file[IdeaVIM.test]:*/" />
|
||||
</component>
|
28
AUTHORS.md
28
AUTHORS.md
@@ -271,6 +271,34 @@ Contributors:
|
||||
[![icon][github]](https://github.com/igrekster)
|
||||
|
||||
igrekster
|
||||
* [![icon][mail]](mailto:lokomot476@gmail.com)
|
||||
[![icon][github]](https://github.com/fan-tom)
|
||||
|
||||
Alexey Gerasimov
|
||||
* [![icon][mail]](mailto:a.grison+github@gmail.com)
|
||||
[![icon][github]](https://github.com/agrison)
|
||||
|
||||
Alexandre Grison
|
||||
* [![icon][mail]](mailto:angel@knight-industries.com)
|
||||
[![icon][github]](https://github.com/angelbot)
|
||||
|
||||
John Weigel
|
||||
* [![icon][mail]](mailto:kevinz@weghst.com)
|
||||
[![icon][github]](https://github.com/kevin70)
|
||||
|
||||
kk
|
||||
* [![icon][mail]](mailto:runforprogram@163.com)
|
||||
[![icon][github]](https://github.com/runforprogram)
|
||||
|
||||
runforprogram
|
||||
* [![icon][mail]](mailto:valery.isaev@jetbrains.com)
|
||||
[![icon][github]](https://github.com/valis)
|
||||
|
||||
valis
|
||||
* [![icon][mail]](mailto:pmikulski@voleon.com)
|
||||
[![icon][github]](https://github.com/pmnoxx)
|
||||
|
||||
Piotr Mikulski
|
||||
|
||||
If you are a contributor and your name is not listed here, feel free to
|
||||
contact the maintainers.
|
||||
|
83
CHANGES.md
83
CHANGES.md
@@ -3,6 +3,12 @@ The Changelog
|
||||
|
||||
History of changes in IdeaVim for the IntelliJ platform.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project DOES NOT adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
Stable versions use X.Y format.
|
||||
EAP versions use X.Y.Z format.
|
||||
|
||||
|
||||
Get an Early Access
|
||||
-------------------
|
||||
@@ -17,17 +23,78 @@ Please note that the quality of EAP versions may at times be way below even
|
||||
usual beta standards.
|
||||
|
||||
To Be Released
|
||||
--------------
|
||||
-------------
|
||||
|
||||
_Available since 0.55.1 EAP:_
|
||||
_Available since 0.57.1 EAP:_
|
||||
|
||||
**Features:**
|
||||
* `exchange` plugin emulation ([vim-exchange](https://github.com/tommcdo/vim-exchange)).
|
||||
* `~/.ideavimrc` file can be reloaded using the new floating action.
|
||||
|
||||
* <details>
|
||||
<summary><strong>Click to see details</strong></summary>
|
||||
<img src="resources/changes/0.58/reload_ideavimrc.png" alt="IdeaVimRc reload"/>
|
||||
</details>
|
||||
|
||||
* Add `:buffer` command.
|
||||
|
||||
**Changes:**
|
||||
* Support IntelliJ's smooth scrolling. Use "Enable smooth scrolling" checkbox in _Preferences | Editor | General_ to disable.
|
||||
|
||||
**Fixes:**
|
||||
* [VIM-1284](https://youtrack.jetbrains.com/issue/VIM-1284) Fix mapping of digits
|
||||
* Fix handling of counts on both operator and motion, e.g. `3d2w` deletes 6 words, instead of 32
|
||||
* Allow mapping of `<C-K>` and `<C-V>`/`<C-Q>`
|
||||
* [VIM-1899](https://youtrack.jetbrains.com/issue/VIM-1899) Add argument to `:registers` command
|
||||
* [VIM-1835](https://youtrack.jetbrains.com/issue/VIM-1835) Macros record input keystrokes instead of mapped keystrokes
|
||||
* [VIM-1900](https://youtrack.jetbrains.com/issue/VIM-1900) Ensure non-printable output for `:registers`, `:marks` and `:jumps` is encoded correctly
|
||||
* [VIM-1994](https://youtrack.jetbrains.com/issue/VIM-1994) Correct paste after `y}P` command.
|
||||
* [VIM-1924](https://youtrack.jetbrains.com/issue/VIM-1924) Select next occurrence doesn't become block selection.
|
||||
|
||||
**Merged PRs:**
|
||||
* [233](https://github.com/JetBrains/ideavim/pull/233) by [valis](https://github.com/valis): [VIM-1994] Correct paste after `y}P` command.
|
||||
* [224](https://github.com/JetBrains/ideavim/pull/224) by [pmnoxx](https://github.com/pmnoxx): Populate intelij navigation history together with ideavim jumplist.
|
||||
* [227](https://github.com/JetBrains/ideavim/pull/227) by [angelbot](https://github.com/angelbot): Add support for buffer command.
|
||||
* [230](https://github.com/JetBrains/ideavim/pull/230) by [fan-tom](https://github.com/fan-tom): VIM-1924.
|
||||
* [231](https://github.com/JetBrains/ideavim/pull/231) by [citizenmatt](https://github.com/citizenmatt): Support smooth scrolling.
|
||||
|
||||
_To Be Released..._
|
||||
|
||||
...
|
||||
|
||||
|
||||
0.57, 2020-04-28
|
||||
-------------
|
||||
|
||||
**Fixes:**
|
||||
* [VIM-1992](https://youtrack.jetbrains.com/issue/VIM-1992) Fix mappings to `<S-Letter>`
|
||||
* [VIM-1991](https://youtrack.jetbrains.com/issue/VIM-1991) Fix working with number registers
|
||||
|
||||
**Merged PRs:**
|
||||
* [234](https://github.com/JetBrains/ideavim/pull/234) by [runforprogram](https://github.com/runforprogram): [VIM-1991] fix >0 number register not work
|
||||
|
||||
0.56, 2020-04-09
|
||||
--------------
|
||||
|
||||
**Features:**
|
||||
* `ReplaceWithRegister` plugin emulation ([ReplaceWithRegister](https://www.vim.org/scripts/script.php?script_id=2703)).
|
||||
* `argtextobj.vim` plugin emulation ([argtextobj.vim](https://vim.sourceforge.io/scripts/script.php?script_id=2699)).
|
||||
* `vim-textobj-entire` plugin emulation ([vim-textobj-entire](https://github.com/kana/vim-textobj-entire)).
|
||||
* [VIM-434](https://youtrack.jetbrains.com/issue/VIM-434) Add `'showcmd'` support, on by default.
|
||||
* Support `ls/buffers/files` commands.
|
||||
|
||||
**Changes:**
|
||||
* Replace `ideastatusbar` option with `ideastatusicon`. Now you can make the icon gray.
|
||||
|
||||
**Deprecations:**
|
||||
* `ideastatusbar` option is deprecated now. See `ideastatusicon`.
|
||||
|
||||
**Fixes:**
|
||||
* [VIM-1284](https://youtrack.jetbrains.com/issue/VIM-1284) Fix mapping of digits.
|
||||
* Fix handling of counts on both operator and motion, e.g. `3d2w` deletes 6 words, instead of 32.
|
||||
* Allow mapping of `<C-K>` and `<C-V>`/`<C-Q>`.
|
||||
* [VIM-1899](https://youtrack.jetbrains.com/issue/VIM-1899) Add argument to `:registers` command.
|
||||
* [VIM-1835](https://youtrack.jetbrains.com/issue/VIM-1835) Macros record input keystrokes instead of mapped keystrokes.
|
||||
* [VIM-1900](https://youtrack.jetbrains.com/issue/VIM-1900) Ensure non-printable output for `:registers`, `:marks` and `:jumps` is encoded correctly.
|
||||
* [VIM-570](https://youtrack.jetbrains.com/issue/VIM-570) Print non-ascii characters in ex panel.
|
||||
* [VIM-926](https://youtrack.jetbrains.com/issue/VIM-926) Fix `<S-Space>` mapping.
|
||||
* [VIM-1958](https://youtrack.jetbrains.com/issue/VIM-1958) Fix `X` command for linewise selection.
|
||||
* [VIM-1911](https://youtrack.jetbrains.com/issue/VIM-1911) Lookup keys respect `IDE` handler.
|
||||
* [VIM-1008](https://youtrack.jetbrains.com/issue/VIM-1008) Correct `ci{` behavior.
|
||||
|
||||
0.55, 2020-01-20
|
||||
--------------
|
||||
|
@@ -1,21 +1,4 @@
|
||||
<div>
|
||||
<a href="https://teamcity.jetbrains.com/viewType.html?buildTypeId=IdeaVim_TestsForIntelliJ20183&guest=1">
|
||||
<img src="https://teamcity.jetbrains.com/app/rest/builds/buildType:(id:IdeaVim_TestsForIntelliJ20183)/statusIcon.svg?guest=1"/>
|
||||
</a>
|
||||
<span>2018.3 Tests</span>
|
||||
</div>
|
||||
<div>
|
||||
<a href="https://teamcity.jetbrains.com/viewType.html?buildTypeId=IdeaVim_TestsForIntelliJ20191&guest=1">
|
||||
<img src="https://teamcity.jetbrains.com/app/rest/builds/buildType:(id:IdeaVim_TestsForIntelliJ20191)/statusIcon.svg?guest=1"/>
|
||||
</a>
|
||||
<span>2019.1 Tests</span>
|
||||
</div>
|
||||
<div>
|
||||
<a href="https://teamcity.jetbrains.com/viewType.html?buildTypeId=IdeaVim_TestsForIntelliJ20192&guest=1">
|
||||
<img src="https://teamcity.jetbrains.com/app/rest/builds/buildType:(id:IdeaVim_TestsForIntelliJ20192)/statusIcon.svg?guest=1"/>
|
||||
</a>
|
||||
<span>2019.2 Tests</span>
|
||||
</div>
|
||||
[![TeamCity Build][teamcity-build-status-svg]][teamcity-build-status]
|
||||
|
||||
|
||||
### Where to Start
|
||||
@@ -34,6 +17,8 @@ You can start by:
|
||||
in the issue tracker.
|
||||
- Read about the `@VimBehaviorDiffers` annotation and fix the corresponding functionality.
|
||||
|
||||
Also join the brand new [](https://gitter.im/JetBrains/ideavim?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) for IdeaVim developers!
|
||||
|
||||
|
||||
### Development Environment
|
||||
|
||||
@@ -42,7 +27,6 @@ in the issue tracker.
|
||||
2. Import the project from the existing sources in IntelliJ IDEA 2018.1 or newer (Community or
|
||||
Ultimate), by selecting "File | New | Project from Existing Sources..." or selecting "Import
|
||||
Project" from the Welcome screen.
|
||||
|
||||
* In the project wizard, select "Import project from external model | Gradle".
|
||||
|
||||
* Select your Java 8+ JDK as the Gradle JVM; leave other parameters unchanged.
|
||||
@@ -67,36 +51,6 @@ in the issue tracker.
|
||||
* You can install this file by selecting "Settings | Plugins | Install plugin
|
||||
from disk...".
|
||||
|
||||
### Copyright
|
||||
|
||||
1. Go to `Preferences | Appearance & Behavior | Scopes`, press "+" button, `Shared`.
|
||||
Name: Copyright scope
|
||||
Pattern: `file[IdeaVIM.main]:com//*||file[IdeaVIM.test]:*/`
|
||||
|
||||
2. Go to `Preferences | Editor | Copyright | Copyright Profiles` and click the "+" button.
|
||||
Name: IdeaVim
|
||||
Text:
|
||||
|
||||
IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
Copyright (C) 2003-$today.year 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
3. Go to `Preferences | Editor | Copyright`, click the "+" button.
|
||||
Scope: Copyright scope
|
||||
Copyright: IdeaVim
|
||||
|
||||
### Testing
|
||||
|
||||
1. Read about the `@VimBehaviorDiffers` annotation.
|
||||
@@ -110,3 +64,8 @@ For example, take a few lines from your favorite poem, or use
|
||||
3. Test your functionality properly.
|
||||
Especially check whether your command works with:
|
||||
line start, line end, file start, file end, empty line, multiple carets, dollar motion, etc.
|
||||
|
||||
<!-- Badges -->
|
||||
|
||||
[teamcity-build-status]: https://teamcity.jetbrains.com/viewType.html?buildTypeId=IdeaVim_TestsForIntelliJ20201&guest=1
|
||||
[teamcity-build-status-svg]: https://teamcity.jetbrains.com/app/rest/builds/buildType:(id:IdeaVim_TestsForIntelliJ20201)/statusIcon.svg?guest=1
|
||||
|
132
README.md
132
README.md
@@ -3,14 +3,12 @@
|
||||
IdeaVim
|
||||
===
|
||||
|
||||
<div>
|
||||
<a href="https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub">
|
||||
<img src="https://jb.gg/badges/official.svg" alt="official JetBrains project"/>
|
||||
</a>
|
||||
<a href="https://teamcity.jetbrains.com/viewType.html?buildTypeId=IdeaVim_TestsForIntelliJ20191&guest=1">
|
||||
<img src="https://teamcity.jetbrains.com/app/rest/builds/buildType:(id:IdeaVim_TestsForIntelliJ20191)/statusIcon.svg?guest=1"/>
|
||||
</a>
|
||||
</div>
|
||||
[![Official JetBrains Project][jb-official-svg]][jb-official]
|
||||
[![Downloads][plugin-downloads-svg]][plugin-repo]
|
||||
[![Rating][plugin-rating-svg]][plugin-repo]
|
||||
[![Version][plugin-version-svg]][plugin-repo]
|
||||
[![Gitter][gitter-svg]][gitter]
|
||||
[![Twitter][twitter-svg]][twitter]
|
||||
|
||||
IdeaVim is a Vim emulation plugin for IDEs based on the IntelliJ Platform.
|
||||
IdeaVim can be used with IntelliJ IDEA, PyCharm, CLion, PhpStorm, WebStorm,
|
||||
@@ -24,24 +22,20 @@ Resources:
|
||||
* [Continuous integration builds](https://teamcity.jetbrains.com/project.html?projectId=IdeaVim&guest=1)
|
||||
* [@IdeaVim](https://twitter.com/ideavim) in Twitter
|
||||
|
||||
|
||||
Installation
|
||||
Setup
|
||||
------------
|
||||
|
||||
Use the IDE's plugin manager to install the latest version of the plugin.
|
||||
Start the IDE normally and enable the Vim emulation using "Tools | Vim
|
||||
Emulator" menu item. At this point you must use Vim keystrokes in all editors.
|
||||
- IdeaVim can be installed via `Settings | Plugins`.
|
||||
See [detailed instructions](https://www.jetbrains.com/help/idea/managing-plugins.html#).
|
||||
|
||||
If you wish to disable the plugin, select the "Tools | Vim Emulator" menu so
|
||||
it is unchecked. At this point your IDE will work with its regular keyboard
|
||||
shortcuts.
|
||||
- Use `Tools | Vim Emulator` to enable or disable emulation.
|
||||
|
||||
Keyboard shortcut conflicts between the Vim emulation and the IDE can be
|
||||
resolved via "File | Settings | Editor | Vim Emulation", "File | Settings |
|
||||
Keymap" on Linux & Windows, and via "Preferences | Editor | Vim Emulation",
|
||||
"Preferences | Keymap" on macOS. They can also be resolved by key-mapping
|
||||
commands in your ~/.ideavimrc file.
|
||||
- Use `~/.ideavimrc` file as an analog of `~/.vimrc` ([details](#Files)). XGD standard is supported as well.
|
||||
|
||||
- Shortcut conflicts can be resolved using:
|
||||
- Linux & Windows: `File | Settings | Editor | Vim Emulation` & `File | Settings | Keymap`,
|
||||
- macOS: `Preferences | Editor | Vim Emulation` & `Preferences | Keymap`,
|
||||
- regular vim mappings in the `~/.ideavimrc` file.
|
||||
|
||||
Get Early Access
|
||||
-------------------
|
||||
@@ -49,7 +43,9 @@ Get Early Access
|
||||
Would you like to try new features and fixes? Join the Early Access Program and
|
||||
receive EAP builds as updates!
|
||||
|
||||
1. Click the IdeaVim icon in the status bar | `EAP` | `Get Early Access...`
|
||||
1. Click the IdeaVim icon <img src="resources/META-INF/pluginIcon_noBorders.svg" width="16" height="16" alt="icon"/>
|
||||
in the status bar | `EAP` | `Get Early Access...`
|
||||
|
||||
|
||||
Or subscribe to EAP updates manually:
|
||||
|
||||
@@ -57,7 +53,7 @@ Or subscribe to EAP updates manually:
|
||||
2. Click the gear icon :gear:, select `Manage Plugin Repositories`, and add the following url:
|
||||
`https://plugins.jetbrains.com/plugins/eap/ideavim`
|
||||
|
||||
See [the changelog](CHANGES.md) for the list of hot unreleased features.
|
||||
See [the changelog](CHANGES.md) for the list of unreleased features.
|
||||
|
||||
It is important to distinguish EAP builds from traditional pre-release software.
|
||||
Please note that the quality of EAP versions may at times be way below even
|
||||
@@ -91,12 +87,16 @@ Supported:
|
||||
* Vim web help
|
||||
* Select mode
|
||||
|
||||
Emulated Vim plugins:
|
||||
[Emulated Vim plugins](doc/emulated-plugins.md):
|
||||
|
||||
* vim-easymotion
|
||||
* vim-surround
|
||||
* vim-multiple-cursors
|
||||
* vim-commentary
|
||||
* argtextobj.vim
|
||||
* vim-textobj-entire
|
||||
* ReplaceWithRegister
|
||||
* vim-exchange [To Be Released]
|
||||
|
||||
Not supported (yet):
|
||||
|
||||
@@ -112,19 +112,19 @@ See also:
|
||||
Files
|
||||
-----
|
||||
|
||||
* ~/.ideavimrc
|
||||
* `~/.ideavimrc`
|
||||
* Your IdeaVim-specific Vim initialization commands
|
||||
|
||||
You can read your ~/.vimrc file from ~/.ideavimrc with this command:
|
||||
You can read your `~/.vimrc` file from `~/.ideavimrc` with this command:
|
||||
|
||||
source ~/.vimrc
|
||||
|
||||
Note, that IdeaVim currently parses ~/.ideavimrc file via simple pattern matching.
|
||||
Note, that IdeaVim currently parses `~/.ideavimrc` file via simple pattern matching.
|
||||
See [VIM-669](https://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 affect where IdeaVim looks for your .ideavimrc file. For example, if you
|
||||
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`.
|
||||
|
||||
@@ -135,40 +135,25 @@ Put your settings to `$XDG_CONFIG_HOME$/ideavim/ideavimrc` file.
|
||||
Emulated Vim Plugins
|
||||
--------------------
|
||||
|
||||
IdeaVim extensions emulate some plugins of the original Vim. In order to use
|
||||
IdeaVim extensions, you have to enable them via this command in your `~/.ideavimrc`:
|
||||
|
||||
set <extension-name>
|
||||
|
||||
Available extensions:
|
||||
|
||||
* easymotion
|
||||
* Setup:
|
||||
* Install [IdeaVim-EasyMotion](https://plugins.jetbrains.com/plugin/13360-ideavim-easymotion/)
|
||||
and [AceJump](https://plugins.jetbrains.com/plugin/7086-acejump/) plugins.
|
||||
* `set easymotion`
|
||||
* Emulates [vim-easymotion](https://github.com/easymotion/vim-easymotion)
|
||||
* Commands: All commands with the mappings are supported. See the [full list of supported commands](https://github.com/AlexPl292/IdeaVim-EasyMotion#supported-commands).
|
||||
|
||||
* surround
|
||||
* Setup: `set surround`
|
||||
* Emulates [vim-surround](https://github.com/tpope/vim-surround)
|
||||
* Commands: `ys`, `cs`, `ds`, `S`
|
||||
|
||||
* multiple-cursors
|
||||
* Setup: `set multiple-cursors`
|
||||
* Emulates [vim-multiple-cursors](https://github.com/terryma/vim-multiple-cursors)
|
||||
* Commands: `<A-n>`, `<A-x>`, `<A-p>`, `g<A-n>`
|
||||
|
||||
* commentary
|
||||
* Setup: `set commentary`
|
||||
* Emulates [commentary.vim](https://github.com/tpope/vim-commentary)
|
||||
* Commands: `gcc`, `gc + motion`, `v_gc`
|
||||
|
||||
See [doc/emulated-plugins.md](doc/emulated-plugins.md)
|
||||
|
||||
Changes to the IDE
|
||||
------------------
|
||||
|
||||
### Executing IDE Actions
|
||||
|
||||
IdeaVim adds two commands for listing and executing arbitrary IDE actions as
|
||||
Ex commands or via `:map` command mappings:
|
||||
|
||||
* `:actionlist [pattern]`
|
||||
* Find IDE actions by name or keymap pattern (E.g. `:actionlist extract`, `:actionlist <C-D`)
|
||||
* `:action {name}`
|
||||
* Execute an action named `NAME`
|
||||
|
||||
For example, here `\r` is mapped to the Reformat Code action:
|
||||
|
||||
:map \r :action ReformatCode<CR>
|
||||
|
||||
### Undo/Redo
|
||||
|
||||
The IdeaVim plugin uses the undo/redo functionality of the IntelliJ Platform,
|
||||
@@ -187,21 +172,6 @@ improvement.
|
||||
|
||||
See also [unresolved escape issues](https://youtrack.jetbrains.com/issues/VIM?q=%23Unresolved+Help+topic%3A+i_Esc).
|
||||
|
||||
### Executing IDE Actions
|
||||
|
||||
IdeaVim adds two commands for listing and executing arbitrary IDE actions as
|
||||
Ex commands or via `:map` command mappings:
|
||||
|
||||
* `:actionlist [pattern]`
|
||||
* Find IDE actions by name or keymap pattern (E.g. `:actionlist extract`, `:actionlist <C-D`)
|
||||
* `:action {name}`
|
||||
* Execute an action named `NAME`
|
||||
|
||||
For example, here `\r` is mapped to the Reformat Code action:
|
||||
|
||||
:map \r :action ReformatCode<CR>
|
||||
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
@@ -219,3 +189,19 @@ License
|
||||
|
||||
IdeaVim is licensed under the terms of the GNU Public License version 2
|
||||
or any later version.
|
||||
|
||||
|
||||
<!-- Badges -->
|
||||
[jb-official]: https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub
|
||||
[jb-official-svg]: https://jb.gg/badges/official.svg
|
||||
|
||||
[plugin-repo]: https://plugins.jetbrains.com/plugin/164-ideavim
|
||||
[plugin-downloads-svg]: http://img.shields.io/jetbrains/plugin/d/IdeaVIM
|
||||
[plugin-rating-svg]: http://img.shields.io/jetbrains/plugin/r/rating/IdeaVIM
|
||||
[plugin-version-svg]: https://img.shields.io/jetbrains/plugin/v/ideavim?label=version
|
||||
|
||||
[gitter-svg]: https://badges.gitter.im/JetBrains/ideavim.svg
|
||||
[gitter]: https://gitter.im/JetBrains/ideavim?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
||||
|
||||
[twitter]: https://twitter.com/ideavim
|
||||
[twitter-svg]: https://img.shields.io/twitter/follow/ideavim?label=twitter%20%40ideavim
|
||||
|
53
build.gradle
53
build.gradle
@@ -9,7 +9,7 @@ buildscript {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'org.jetbrains.intellij' version '0.4.9'
|
||||
id 'org.jetbrains.intellij' version '0.4.18'
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
@@ -37,11 +37,7 @@ intellij {
|
||||
downloadSources Boolean.valueOf(downloadIdeaSources)
|
||||
instrumentCode Boolean.valueOf(instrumentPluginCode)
|
||||
intellijRepo = "https://www.jetbrains.com/intellij-repository"
|
||||
if (!Boolean.valueOf(legacyNoJavaPlugin)) {
|
||||
// Since 192 version of IJ java plugin should be defined separately
|
||||
// Set `legacyNoJavaPlugin` to true if you are going to run tests under idea version < 192
|
||||
plugins = ['java']
|
||||
}
|
||||
|
||||
publishPlugin {
|
||||
channels publishChannels.split(',')
|
||||
@@ -56,7 +52,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
|
||||
compileOnly "org.jetbrains:annotations:17.0.0"
|
||||
compileOnly "org.jetbrains:annotations:19.0.0"
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
@@ -74,15 +70,56 @@ tasks.register("slackEapNotification") {
|
||||
doLast {
|
||||
if (!slackUrl) return
|
||||
def post = new URL(slackUrl).openConnection()
|
||||
def message = "{\"text\":\"New EAP released: $version\"}"
|
||||
def changeLog = extractChangelog()
|
||||
changeLog = changeLog.replace("* ", "• ") // Replace stars with bullets
|
||||
changeLog = changeLog.replace("**", "*") // Enable bold text
|
||||
changeLog = changeLog.replaceAll("\\[([^]]+)]\\(([^)]+)\\)", '<$2|$1>') // Enable links
|
||||
def message ="""
|
||||
{
|
||||
"text": "New version of IdeaVim",
|
||||
"blocks": [
|
||||
{
|
||||
"type": "section",
|
||||
"text": {
|
||||
"type": "mrkdwn",
|
||||
"text": "IdeaVim EAP $version has been relesed\\n$changeLog"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
"""
|
||||
post.setRequestMethod("POST")
|
||||
post.setDoOutput(true)
|
||||
post.setRequestProperty("Content-Type", "application/json")
|
||||
post.getOutputStream().write(message.getBytes("UTF-8"))
|
||||
def postRC = post.getResponseCode()
|
||||
println(postRC)
|
||||
if(postRC.equals(200)) {
|
||||
if(postRC == 200) {
|
||||
println(post.getInputStream().getText())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Very primitive changelog extraction code
|
||||
def extractChangelog() {
|
||||
def startLine = "_Available since $version EAP:_"
|
||||
def endLine = "_To Be Released..._"
|
||||
def startSaving = false
|
||||
def res = new StringBuilder()
|
||||
new File("./CHANGES.md").eachLine { line ->
|
||||
if (startSaving) {
|
||||
if (line == endLine) {
|
||||
startSaving = false
|
||||
}
|
||||
else {
|
||||
res.append(line).append('\n')
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (line == startLine) {
|
||||
startSaving = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return res.toString()
|
||||
}
|
68
doc/emulated-plugins.md
Normal file
68
doc/emulated-plugins.md
Normal file
@@ -0,0 +1,68 @@
|
||||
Emulated Vim Plugins
|
||||
--------------------
|
||||
|
||||
IdeaVim extensions emulate plugins of the original Vim. In order to use
|
||||
IdeaVim extensions, you have to enable them via this command in your `~/.ideavimrc`:
|
||||
|
||||
set <extension-name>
|
||||
|
||||
Available extensions:
|
||||
|
||||
## easymotion
|
||||
|
||||
* Setup:
|
||||
* Install [IdeaVim-EasyMotion](https://plugins.jetbrains.com/plugin/13360-ideavim-easymotion/)
|
||||
and [AceJump](https://plugins.jetbrains.com/plugin/7086-acejump/) plugins.
|
||||
* `set easymotion`
|
||||
* Emulates [vim-easymotion](https://github.com/easymotion/vim-easymotion)
|
||||
* Commands: All commands with the mappings are supported. See the [full list of supported commands](https://github.com/AlexPl292/IdeaVim-EasyMotion#supported-commands).
|
||||
|
||||
## surround
|
||||
|
||||
* Setup: `set surround`
|
||||
* Emulates [vim-surround](https://github.com/tpope/vim-surround)
|
||||
* Commands: `ys`, `cs`, `ds`, `S`
|
||||
|
||||
## multiple-cursors
|
||||
|
||||
* Setup: `set multiple-cursors`
|
||||
* Emulates [vim-multiple-cursors](https://github.com/terryma/vim-multiple-cursors)
|
||||
* Commands: `<A-n>`, `<A-x>`, `<A-p>`, `g<A-n>`
|
||||
|
||||
## commentary
|
||||
|
||||
* Setup: `set commentary`
|
||||
* Emulates [commentary.vim](https://github.com/tpope/vim-commentary)
|
||||
* Commands: `gcc`, `gc + motion`, `v_gc`
|
||||
|
||||
## ReplaceWithRegister
|
||||
|
||||
* Setup: `set ReplaceWithRegister`
|
||||
* Emulates [ReplaceWithRegister](https://github.com/vim-scripts/ReplaceWithRegister)
|
||||
* Commands: `gr`, `grr`
|
||||
|
||||
## argtextobj
|
||||
|
||||
* Setup:
|
||||
* `set argtextobj`
|
||||
* By default, only the arguments inside parenthesis are considered. To extend the functionality
|
||||
to other types of brackets, set `g:argtextobj_pairs` variable to a comma-separated
|
||||
list of colon-separated pairs (same as VIM's `matchpairs` option), like
|
||||
`let g:argtextobj_pairs="(:),{:},<:>"`. The order of pairs matters when
|
||||
handling symbols that can also be operators: `func(x << 5, 20) >> 17`. To handle
|
||||
this syntax parenthesis, must come before angle brackets in the list.
|
||||
* Emulates [argtextobj.vim](https://www.vim.org/scripts/script.php?script_id=2699)
|
||||
* Additional text objects: `aa`, `ia`
|
||||
|
||||
## exchange [To Be Released]
|
||||
|
||||
* Setup: `set exchange`
|
||||
* Emulates [vim-exchange](https://github.com/tommcdo/vim-exchange)
|
||||
* Commands: `cx`, `cxx`, `X`, `cxc`
|
||||
|
||||
## textobj-entire
|
||||
|
||||
* Setup: `set textobj-entire`
|
||||
* Emulates [vim-textobj-entire](https://github.com/kana/vim-textobj-entire)
|
||||
* Additional text objects: `ae`, `ie`
|
||||
|
@@ -65,6 +65,7 @@ The following `:set` commands can appear in `~/.ideavimrc` or be set manually in
|
||||
same as ideaselection - IdeaVim ONLY
|
||||
|
||||
'showmode' 'smd' message on the status line to show current mode
|
||||
'showcmd' 'sc' show (partial) command in the status bar
|
||||
'sidescroll' 'ss' minimum number of columns to scroll horizontally
|
||||
'sidescrolloff' 'siso' min. number of columns to left and right of cursor
|
||||
'smartcase' 'scs' no ignore case when pattern is uppercase
|
||||
@@ -104,10 +105,20 @@ The following `:set` commands can appear in `~/.ideavimrc` or be set manually in
|
||||
See wiki/`ideajoin` examples
|
||||
|
||||
`ideastatusbar` `ideastatusbar` Boolean (default true)
|
||||
DEPRECATED. Please use `ideastatusicon`
|
||||
|
||||
If false, IdeaVim icon won't be shown in the status bar.
|
||||
Works only from `~/.ideavimrc` after the IDE restart.
|
||||
|
||||
`ideastatusicon` `ideastatusicon` String(default "enabled")
|
||||
|
||||
Define the behavior of IdeaVim icon in the status bar.
|
||||
|
||||
Use one of the following values:
|
||||
- enabled - icon is shown in the status bar
|
||||
- gray - use the gray version of the icon
|
||||
- disabled - hide the icon
|
||||
|
||||
`lookupkeys` `lookupkeys` List of strings
|
||||
|
||||
List of keys that should be processed by the IDE during the active lookup (autocompletion).
|
||||
|
@@ -1,16 +1,13 @@
|
||||
# suppress inspection "UnusedProperty" for whole file
|
||||
|
||||
ideaVersion=201-EAP-SNAPSHOT
|
||||
ideaVersion=2020.1
|
||||
downloadIdeaSources=true
|
||||
instrumentPluginCode=true
|
||||
version=SNAPSHOT
|
||||
javaVersion=1.8
|
||||
kotlinVersion=1.3.61
|
||||
kotlinVersion=1.3.71
|
||||
publishUsername=username
|
||||
publishToken=token
|
||||
publishChannels=eap
|
||||
# Since 192 version of IJ java plugin should be defined separately
|
||||
# Set this value to true if you are going to run tests under idea version < 192
|
||||
legacyNoJavaPlugin=false
|
||||
|
||||
slackUrl=
|
||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
#Fri Nov 22 14:42:01 MSK 2019
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
|
||||
#Fri Apr 10 10:57:10 MSK 2020
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStorePath=wrapper/dists
|
||||
|
22
gradlew
vendored
22
gradlew
vendored
@@ -1,5 +1,21 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
@@ -28,7 +44,7 @@ APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m"'
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
@@ -109,8 +125,8 @@ if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
18
gradlew.bat
vendored
18
gradlew.bat
vendored
@@ -1,3 +1,19 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m"
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
@@ -197,8 +197,8 @@
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.change.insert.InsertSingleCommandAction" mappingModes="I" keys="«C-O»"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.change.insert.VisualBlockInsertAction" mappingModes="X" keys="I"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.change.insert.VisualBlockAppendAction" mappingModes="X" keys="A"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.change.insert.StartInsertDigraphAction" mappingModes="IC" keys="«C-K»"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.change.insert.StartInsertLiteralAction" mappingModes="IC" keys="«C-V»,«C-Q»"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.change.insert.InsertCompletedDigraphAction" mappingModes="IC" keys="«C-K»"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.change.insert.InsertCompletedLiteralAction" mappingModes="IC" keys="«C-V»,«C-Q»"/>
|
||||
|
||||
<!-- Delete -->
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.change.delete.DeleteCharacterAction" mappingModes="N" keys="«DEL»"/>
|
||||
@@ -260,14 +260,16 @@
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.copy.PutTextBeforeCursorNoIndentAction" mappingModes="N" keys="[P,]P,[p"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.copy.PutTextAfterCursorActionMoveCursor" mappingModes="N" keys="gp"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.copy.PutTextBeforeCursorActionMoveCursor" mappingModes="N" keys="gP"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.copy.SelectRegisterAction" mappingModes="NXO" keys='"'/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.copy.YankLineAction" mappingModes="N" keys="Y"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.copy.YankMotionAction" mappingModes="N" keys="y"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.copy.YankVisualAction" mappingModes="X" keys="y"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.copy.YankVisualLinesAction" mappingModes="X" keys="Y"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.copy.PutVisualTextAction" mappingModes="X" keys="p,P"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.copy.PutVisualTextNoIndentAction" mappingModes="X" keys="[p,]p,]P,[P"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.copy.PutVisualTextMoveCursorAction" mappingModes="X" keys="gp,gP"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.copy.PutVisualTextBeforeCursorAction" mappingModes="X" keys="P"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.copy.PutVisualTextAfterCursorAction" mappingModes="X" keys="p"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.copy.PutVisualTextBeforeCursorNoIndentAction" mappingModes="X" keys="]P,[P"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.copy.PutVisualTextAfterCursorNoIndentAction" mappingModes="X" keys="[p,]p"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.copy.PutVisualTextBeforeCursorMoveCursorAction" mappingModes="X" keys="gP"/>
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.copy.PutVisualTextAfterCursorMoveCursorAction" mappingModes="X" keys="gp"/>
|
||||
|
||||
<!-- File -->
|
||||
<vimAction implementation="com.maddyhome.idea.vim.action.file.FileSaveCloseAction" mappingModes="N" keys="ZQ,ZZ"/>
|
||||
|
@@ -60,5 +60,7 @@
|
||||
<vimExCommand implementation="com.maddyhome.idea.vim.ex.handler.NextTabHandler" names="tabn[ext]"/>
|
||||
<vimExCommand implementation="com.maddyhome.idea.vim.ex.handler.PreviousTabHandler" names="tabp[revious],tabN[ext]"/>
|
||||
<vimExCommand implementation="com.maddyhome.idea.vim.ex.handler.TabOnlyHandler" names="tabo[nly]"/>
|
||||
<vimExCommand implementation="com.maddyhome.idea.vim.ex.handler.BufferListHandler" names="buffers,ls,files"/>
|
||||
<vimExCommand implementation="com.maddyhome.idea.vim.ex.handler.BufferHandler" names="b[uffer]"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
|
@@ -3,5 +3,9 @@
|
||||
<vimExtension implementation="com.maddyhome.idea.vim.extension.surround.VimSurroundExtension"/>
|
||||
<vimExtension implementation="com.maddyhome.idea.vim.extension.multiplecursors.VimMultipleCursorsExtension"/>
|
||||
<vimExtension implementation="com.maddyhome.idea.vim.extension.commentary.CommentaryExtension"/>
|
||||
<vimExtension implementation="com.maddyhome.idea.vim.extension.textobjentire.VimTextObjEntireExtension"/>
|
||||
<vimExtension implementation="com.maddyhome.idea.vim.extension.argtextobj.VimArgTextObjExtension"/>
|
||||
<vimExtension implementation="com.maddyhome.idea.vim.extension.replacewithregister.ReplaceWithRegister"/>
|
||||
<vimExtension implementation="com.maddyhome.idea.vim.extension.exchange.VimExchangeExtension"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
|
25
resources/META-INF/includes/VimListeners.xml
Normal file
25
resources/META-INF/includes/VimListeners.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<idea-plugin>
|
||||
<applicationListeners>
|
||||
<listener class="com.maddyhome.idea.vim.ui.ExEntryPanel$LafListener"
|
||||
topic="com.intellij.ide.ui.LafManagerListener"/>
|
||||
</applicationListeners>
|
||||
<projectListeners>
|
||||
<listener class="com.maddyhome.idea.vim.ui.ExOutputPanel$LafListener"
|
||||
topic="com.intellij.ide.ui.LafManagerListener"/>
|
||||
|
||||
<listener class="com.maddyhome.idea.vim.listener.VimListenerManager$VimFileEditorManagerListener"
|
||||
topic="com.intellij.openapi.fileEditor.FileEditorManagerListener"/>
|
||||
|
||||
<listener class="com.maddyhome.idea.vim.listener.IdeaSpecifics$VimActionListener"
|
||||
topic="com.intellij.openapi.actionSystem.ex.AnActionListener"/>
|
||||
|
||||
<listener class="com.maddyhome.idea.vim.listener.IdeaSpecifics$VimTemplateManagerListener"
|
||||
topic="com.intellij.codeInsight.template.TemplateManagerListener"/>
|
||||
|
||||
<listener class="com.maddyhome.idea.vim.group.MarkGroup$MarkListener"
|
||||
topic="com.intellij.ide.bookmarks.BookmarksListener"/>
|
||||
|
||||
<listener class="com.maddyhome.idea.vim.listener.IdeaSpecifics$VimFindModelListener"
|
||||
topic="com.intellij.find.FindModelListener"/>
|
||||
</projectListeners>
|
||||
</idea-plugin>
|
@@ -3,9 +3,8 @@
|
||||
<id>IdeaVIM</id>
|
||||
<change-notes><![CDATA[
|
||||
<ul>
|
||||
<li>Support dot command for Surround and Commentary extensions</li>
|
||||
<li>Support XDG settings standard</li>
|
||||
<li>Add option to remove the status bar icon</li>
|
||||
<li>vim-exchange plugin emulation</li>
|
||||
<li>A new floating action for reloading .ideavimrc</li>
|
||||
<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>
|
||||
@@ -24,7 +23,7 @@
|
||||
|
||||
<!-- Please search for "[VERSION UPDATE]" in project in case you update the since-build version -->
|
||||
<!-- Check for [Version Update] tag in YouTrack as well -->
|
||||
<idea-version since-build="183.4284.148"/>
|
||||
<idea-version since-build="201.5985"/>
|
||||
|
||||
<!-- Mark the plugin as compatible with RubyMine and other products based on the IntelliJ platform -->
|
||||
<depends>com.intellij.modules.lang</depends>
|
||||
@@ -34,25 +33,16 @@
|
||||
<component>
|
||||
<implementation-class>com.maddyhome.idea.vim.DynamicLoaderStopper</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>com.maddyhome.idea.vim.VimPlugin</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>com.maddyhome.idea.vim.VimLocalConfig</implementation-class>
|
||||
</component>
|
||||
</application-components>
|
||||
<project-components>
|
||||
<component>
|
||||
<implementation-class>com.maddyhome.idea.vim.VimProjectComponent</implementation-class>
|
||||
</component>
|
||||
</project-components>
|
||||
|
||||
<extensionPoints>
|
||||
<extensionPoint name="vimExtension" interface="com.maddyhome.idea.vim.extension.VimExtension"/>
|
||||
<extensionPoint name="vimExtension" interface="com.maddyhome.idea.vim.extension.VimExtension" dynamic="true"/>
|
||||
|
||||
<!-- For internal use only -->
|
||||
<extensionPoint name="vimExCommand" beanClass="com.maddyhome.idea.vim.ex.ExBeanClass" dynamic="true">
|
||||
<with attribute="implementation" implements="com.maddyhome.idea.vim.ex.CommandHandler"/>
|
||||
</extensionPoint>
|
||||
<!-- For internal use only -->
|
||||
<extensionPoint name="vimAction" beanClass="com.maddyhome.idea.vim.handler.ActionBeanClass" dynamic="true">
|
||||
<with attribute="implementation" implements="com.maddyhome.idea.vim.handler.EditorActionHandlerBase"/>
|
||||
</extensionPoint>
|
||||
@@ -61,14 +51,25 @@
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<applicationConfigurable groupId="editor" instance="com.maddyhome.idea.vim.ui.VimEmulationConfigurable"/>
|
||||
<projectService serviceImplementation="com.maddyhome.idea.vim.group.NotificationService"/>
|
||||
<statusBarWidgetProvider implementation="com.maddyhome.idea.vim.StatusBarIconProvider"/>
|
||||
<statusBarWidgetFactory implementation="com.maddyhome.idea.vim.ui.StatusBarIconFactory"/>
|
||||
<statusBarWidgetFactory implementation="com.maddyhome.idea.vim.ui.ShowCmdStatusBarWidgetFactory" order="first"/>
|
||||
|
||||
<applicationService serviceImplementation="com.maddyhome.idea.vim.VimLocalConfig"/>
|
||||
<applicationService serviceImplementation="com.maddyhome.idea.vim.VimPlugin"/>
|
||||
|
||||
<!-- Initialise as early as possible so that we're ready to edit quickly. This is especially important for Rider,
|
||||
which (at least for 2020.1) has some long running activities that block other startup extensions. None of the
|
||||
core platform activities have IDs, so we can't use "before ID". We have to use "first" -->
|
||||
<postStartupActivity implementation="com.maddyhome.idea.vim.PluginStartup" order="first"/>
|
||||
|
||||
<editorFloatingToolbarProvider implementation="com.maddyhome.idea.vim.ui.ReloadFloatingToolbar"/>
|
||||
</extensions>
|
||||
|
||||
<xi:include href="/META-INF/includes/ApplicationServices.xml" xpointer="xpointer(/idea-plugin/*)"/>
|
||||
|
||||
<xi:include href="/META-INF/includes/VimActions.xml" xpointer="xpointer(/idea-plugin/*)"/>
|
||||
<xi:include href="/META-INF/includes/VimExCommands.xml" xpointer="xpointer(/idea-plugin/*)"/>
|
||||
<xi:include href="/META-INF/includes/VimExtensions.xml" xpointer="xpointer(/idea-plugin/*)"/>
|
||||
<xi:include href="/META-INF/includes/VimListeners.xml" xpointer="xpointer(/idea-plugin/*)"/>
|
||||
|
||||
<actions>
|
||||
<action id="VimPluginToggle" class="com.maddyhome.idea.vim.action.VimPluginToggleAction" text="Vim Emulator" description="Toggle the vim plugin On/off">
|
||||
@@ -79,6 +80,20 @@
|
||||
<action id="VimInternalAddInlays" class="com.maddyhome.idea.vim.action.internal.AddInlaysAction" text="Add Test Inlays | IdeaVim Internal" internal="true"/>
|
||||
|
||||
<action id="VimShortcutKeyAction" class="com.maddyhome.idea.vim.action.VimShortcutKeyAction" text="Shortcuts"/>
|
||||
<action id="VimActions" class="com.maddyhome.idea.vim.VimActions" text="Vim Actions"/>
|
||||
<action id="VimActions" class="com.maddyhome.idea.vim.ui.VimActions" text="Vim Actions"/>
|
||||
|
||||
<!-- [Version Update] 202+ use-shortcut-of="ExternalSystem.ProjectRefreshAction" -->
|
||||
<group id="IdeaVim.ReloadVimRc.group" class="com.maddyhome.idea.vim.ui.ReloadFloatingToolbarActionGroup">
|
||||
<action id="IdeaVim.ReloadVimRc.reload" class="com.maddyhome.idea.vim.ui.ReloadVimRc">
|
||||
<keyboard-shortcut first-keystroke="control shift O" keymap="$default"/>
|
||||
<keyboard-shortcut first-keystroke="control shift O" keymap="Eclipse" remove="true"/>
|
||||
<keyboard-shortcut first-keystroke="control shift O" keymap="NetBeans 6.5" remove="true"/>
|
||||
<keyboard-shortcut first-keystroke="control shift O" keymap="Visual Studio" remove="true"/>
|
||||
<keyboard-shortcut first-keystroke="meta shift O" keymap="Mac OS X" replace-all="true"/>
|
||||
<keyboard-shortcut first-keystroke="meta shift O" keymap="Eclipse (Mac OS X)" replace-all="true" remove="true"/>
|
||||
<keyboard-shortcut first-keystroke="meta shift O" keymap="Xcode" replace-all="true" remove="true"/>
|
||||
<keyboard-shortcut first-keystroke="meta shift I" keymap="Mac OS X 10.5+" replace-all="true"/>
|
||||
</action>
|
||||
</group>
|
||||
</actions>
|
||||
</idea-plugin>
|
||||
|
9
resources/META-INF/pluginIcon_noBorders.svg
Normal file
9
resources/META-INF/pluginIcon_noBorders.svg
Normal file
@@ -0,0 +1,9 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40">
|
||||
<defs>
|
||||
<linearGradient id="ideavim_plugin-a" x1="-6.748%" x2="47.286%" y1="33.61%" y2="85.907%">
|
||||
<stop offset="0%" stop-color="#3BEA62"/>
|
||||
<stop offset="100%" stop-color="#087CFA"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<polygon fill="url(#ideavim_plugin-a)" fill-rule="evenodd" points="29.019 0 13.988 26.119 13.988 0 0 0 0 40 16.953 40 40 0"/>
|
||||
</svg>
|
After Width: | Height: | Size: 450 B |
BIN
resources/changes/0.58/reload_ideavimrc.png
Normal file
BIN
resources/changes/0.58/reload_ideavimrc.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 194 KiB |
@@ -53,16 +53,14 @@ import java.util.Map;
|
||||
* @author vlan
|
||||
*/
|
||||
public class EventFacade {
|
||||
@NotNull private static final EventFacade ourInstance = new EventFacade();
|
||||
private static final @NotNull EventFacade ourInstance = new EventFacade();
|
||||
|
||||
@Nullable private TypedActionHandler myOriginalTypedActionHandler;
|
||||
private Map<Project, MessageBusConnection> connections = new HashMap<>();
|
||||
private @Nullable TypedActionHandler myOriginalTypedActionHandler;
|
||||
|
||||
private EventFacade() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static EventFacade getInstance() {
|
||||
public static @NotNull EventFacade getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
@@ -93,31 +91,6 @@ public class EventFacade {
|
||||
action.unregisterCustomShortcutSet(component);
|
||||
}
|
||||
|
||||
public void connectFileEditorManagerListener(@NotNull Project project, @NotNull FileEditorManagerListener listener) {
|
||||
final MessageBusConnection connection = getConnection(project);
|
||||
connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener);
|
||||
}
|
||||
|
||||
public void connectAnActionListener(@NotNull Project project, @NotNull AnActionListener listener) {
|
||||
final MessageBusConnection connection = getConnection(project);
|
||||
connection.subscribe(AnActionListener.TOPIC, listener);
|
||||
}
|
||||
|
||||
public void connectTemplateStartedListener(@NotNull Project project, @NotNull TemplateManagerListener listener) {
|
||||
final MessageBusConnection connection = getConnection(project);
|
||||
connection.subscribe(TemplateManager.TEMPLATE_STARTED_TOPIC, listener);
|
||||
}
|
||||
|
||||
public void connectBookmarkListener(@NotNull Project project, @NotNull BookmarksListener bookmarksListener) {
|
||||
final MessageBusConnection connection = getConnection(project);
|
||||
connection.subscribe(BookmarksListener.TOPIC, bookmarksListener);
|
||||
}
|
||||
|
||||
public void connectFindModelListener(@NotNull Project project, @NotNull FindModelListener findModelListener) {
|
||||
final MessageBusConnection connection = getConnection(project);
|
||||
connection.subscribe(FindManager.FIND_MODEL_TOPIC, findModelListener);
|
||||
}
|
||||
|
||||
public void addDocumentListener(@NotNull Document document, @NotNull DocumentListener listener) {
|
||||
document.addDocumentListener(listener);
|
||||
}
|
||||
@@ -169,32 +142,15 @@ public class EventFacade {
|
||||
}
|
||||
|
||||
public void registerLookupListener(@NotNull Project project, @NotNull PropertyChangeListener propertyChangeListener) {
|
||||
LookupManager.getInstance(project).addPropertyChangeListener(propertyChangeListener, project);
|
||||
VimProjectService parentDisposable = VimProjectService.getInstance(project);
|
||||
LookupManager.getInstance(project).addPropertyChangeListener(propertyChangeListener, parentDisposable);
|
||||
}
|
||||
|
||||
public void removeLookupListener(@NotNull Project project, @NotNull PropertyChangeListener propertyChangeListener) {
|
||||
LookupManager.getInstance(project).removePropertyChangeListener(propertyChangeListener);
|
||||
}
|
||||
|
||||
public void disableBusConnection() {
|
||||
connections.values().forEach(MessageBusConnection::disconnect);
|
||||
connections.clear();
|
||||
}
|
||||
|
||||
private MessageBusConnection getConnection(Project project) {
|
||||
if (!connections.containsKey(project)) {
|
||||
final MessageBusConnection connection = project.getMessageBus().connect();
|
||||
connections.put(project, connection);
|
||||
Disposer.register(project, () -> {
|
||||
connection.disconnect();
|
||||
connections.remove(project);
|
||||
});
|
||||
}
|
||||
return connections.get(project);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private TypedAction getTypedAction() {
|
||||
private @NotNull TypedAction getTypedAction() {
|
||||
return EditorActionManager.getInstance().getTypedAction();
|
||||
}
|
||||
}
|
||||
|
@@ -35,6 +35,8 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.ui.popup.ListPopup;
|
||||
import com.maddyhome.idea.vim.action.change.VimRepeater;
|
||||
import com.maddyhome.idea.vim.action.change.insert.InsertCompletedDigraphAction;
|
||||
import com.maddyhome.idea.vim.action.change.insert.InsertCompletedLiteralAction;
|
||||
import com.maddyhome.idea.vim.action.macro.ToggleRecordingAction;
|
||||
import com.maddyhome.idea.vim.command.*;
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionHandler;
|
||||
@@ -48,6 +50,7 @@ import com.maddyhome.idea.vim.key.*;
|
||||
import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor;
|
||||
import com.maddyhome.idea.vim.listener.VimListenerSuppressor;
|
||||
import com.maddyhome.idea.vim.option.OptionsManager;
|
||||
import com.maddyhome.idea.vim.ui.ShowCmd;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -56,8 +59,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -74,8 +79,7 @@ public class KeyHandler {
|
||||
*
|
||||
* @return A reference to the singleton
|
||||
*/
|
||||
@NotNull
|
||||
public static KeyHandler getInstance() {
|
||||
public static @NotNull KeyHandler getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new KeyHandler();
|
||||
}
|
||||
@@ -154,16 +158,6 @@ public class KeyHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void startDigraphSequence(@NotNull Editor editor) {
|
||||
final CommandState editorState = CommandState.getInstance(editor);
|
||||
editorState.startDigraphSequence();
|
||||
}
|
||||
|
||||
public void startLiteralSequence(@NotNull Editor editor) {
|
||||
final CommandState editorState = CommandState.getInstance(editor);
|
||||
editorState.startLiteralSequence();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the main key handler for the Vim plugin. Every keystroke not handled directly by Idea is sent here for
|
||||
* processing.
|
||||
@@ -220,7 +214,7 @@ public class KeyHandler {
|
||||
try {
|
||||
if (!allowKeyMappings || !handleKeyMapping(editor, key, context)) {
|
||||
if (isCommandCountKey(chKey, editorState)) {
|
||||
commandBuilder.addCountCharacter(chKey);
|
||||
commandBuilder.addCountCharacter(key);
|
||||
} else if (isDeleteCommandCountKey(key, editorState)) {
|
||||
commandBuilder.deleteCountCharacter();
|
||||
} else if (isEditorReset(key, editorState)) {
|
||||
@@ -231,21 +225,29 @@ public class KeyHandler {
|
||||
else if (isExpectingCharArgument(commandBuilder)) {
|
||||
handleCharArgument(key, chKey, editorState);
|
||||
}
|
||||
else if (editorState.getSubMode() == CommandState.SubMode.REGISTER_PENDING) {
|
||||
commandBuilder.addKey(key);
|
||||
handleSelectRegister(editorState, chKey);
|
||||
}
|
||||
// If we are this far, then the user must be entering a command or a non-single-character argument
|
||||
// to an entered command. Let's figure out which it is.
|
||||
else if (!handleDigraph(editor, key, context, editorState)) {
|
||||
|
||||
commandBuilder.addKey(key);
|
||||
|
||||
// Ask the key/action tree if this is an appropriate key at this point in the command and if so,
|
||||
// return the node matching this keystroke
|
||||
final Node node = mapOpCommand(key, commandBuilder.getChildNode(key), editorState);
|
||||
|
||||
if (node instanceof CommandNode) {
|
||||
handleCommandNode(editor, context, key, (CommandNode) node, editorState);
|
||||
commandBuilder.addKey(key);
|
||||
} else if (node instanceof CommandPartNode) {
|
||||
commandBuilder.setCurrentCommandPartNode((CommandPartNode) node);
|
||||
} else {
|
||||
commandBuilder.addKey(key);
|
||||
} else if (isSelectRegister(key, editorState)) {
|
||||
editorState.pushModes(CommandState.Mode.COMMAND, CommandState.SubMode.REGISTER_PENDING);
|
||||
commandBuilder.addKey(key);
|
||||
}
|
||||
else { // node == null
|
||||
|
||||
// If we are in insert/replace mode send this key in for processing
|
||||
if (editorState.getMode() == CommandState.Mode.INSERT || editorState.getMode() == CommandState.Mode.REPLACE) {
|
||||
shouldRecord &= VimPlugin.getChange().processKey(editor, context, key);
|
||||
@@ -270,10 +272,11 @@ public class KeyHandler {
|
||||
|
||||
// Do we have a fully entered command at this point? If so, let's execute it.
|
||||
if (commandBuilder.isReady()) {
|
||||
executeCommand(editor, key, context, editorState);
|
||||
executeCommand(editor, context, editorState);
|
||||
}
|
||||
else if (commandBuilder.isBad()) {
|
||||
editorState.resetOpPending();
|
||||
editorState.resetRegisterPending();
|
||||
VimPlugin.indicateError();
|
||||
reset(editor);
|
||||
}
|
||||
@@ -282,6 +285,9 @@ public class KeyHandler {
|
||||
if (shouldRecord && editorState.isRecording()) {
|
||||
VimPlugin.getRegister().recordKeyStroke(key);
|
||||
}
|
||||
|
||||
// This will update immediately, if we're on the EDT (which we are)
|
||||
ShowCmd.INSTANCE.update();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -306,7 +312,7 @@ public class KeyHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void handleEditorReset(@NotNull Editor editor, @NotNull KeyStroke key, @NotNull final DataContext context, @NotNull CommandState editorState) {
|
||||
private void handleEditorReset(@NotNull Editor editor, @NotNull KeyStroke key, final @NotNull DataContext context, @NotNull CommandState editorState) {
|
||||
if (editorState.getCommandBuilder().isAtDefaultState()) {
|
||||
RegisterGroup register = VimPlugin.getRegister();
|
||||
if (register.getCurrentRegister() == register.getDefaultRegister()) {
|
||||
@@ -321,9 +327,9 @@ public class KeyHandler {
|
||||
ChangeGroup.resetCaret(editor, false);
|
||||
}
|
||||
|
||||
private boolean handleKeyMapping(@NotNull final Editor editor,
|
||||
@NotNull final KeyStroke key,
|
||||
@NotNull final DataContext context) {
|
||||
private boolean handleKeyMapping(final @NotNull Editor editor,
|
||||
final @NotNull KeyStroke key,
|
||||
final @NotNull DataContext context) {
|
||||
|
||||
final CommandState commandState = CommandState.getInstance(editor);
|
||||
final MappingState mappingState = commandState.getMappingState();
|
||||
@@ -430,10 +436,8 @@ public class KeyHandler {
|
||||
|
||||
final EditorDataContext currentContext = new EditorDataContext(editor);
|
||||
|
||||
final List<KeyStroke> toKeys = mappingInfo.getToKeys();
|
||||
final VimExtensionHandler extensionHandler = mappingInfo.getExtensionHandler();
|
||||
|
||||
if (toKeys != null) {
|
||||
if (mappingInfo instanceof ToKeysMappingInfo) {
|
||||
final List<KeyStroke> toKeys = ((ToKeysMappingInfo)mappingInfo).getToKeys();
|
||||
final boolean fromIsPrefix = isPrefix(mappingInfo.getFromKeys(), toKeys);
|
||||
boolean first = true;
|
||||
for (KeyStroke keyStroke : toKeys) {
|
||||
@@ -442,7 +446,8 @@ public class KeyHandler {
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
else if (extensionHandler != null) {
|
||||
else if (mappingInfo instanceof ToHandlerMappingInfo) {
|
||||
final VimExtensionHandler extensionHandler = ((ToHandlerMappingInfo)mappingInfo).getExtensionHandler();
|
||||
final CommandProcessor processor = CommandProcessor.getInstance();
|
||||
|
||||
// Cache isOperatorPending in case the extension changes the mode while moving the caret
|
||||
@@ -558,7 +563,9 @@ public class KeyHandler {
|
||||
private boolean isCommandCountKey(char chKey, @NotNull CommandState editorState) {
|
||||
// Make sure to avoid handling '0' as the start of a count.
|
||||
final CommandBuilder commandBuilder = editorState.getCommandBuilder();
|
||||
return (editorState.getMode() == CommandState.Mode.COMMAND || editorState.getMode() == CommandState.Mode.VISUAL)
|
||||
return ((editorState.getMode() == CommandState.Mode.COMMAND
|
||||
&&editorState.getSubMode()!=CommandState.SubMode.REGISTER_PENDING)
|
||||
|| editorState.getMode() == CommandState.Mode.VISUAL)
|
||||
&& commandBuilder.isExpectingCount() && Character.isDigit(chKey) && (commandBuilder.getCount() > 0 || chKey != '0');
|
||||
}
|
||||
|
||||
@@ -570,7 +577,29 @@ public class KeyHandler {
|
||||
}
|
||||
|
||||
private boolean isEditorReset(@NotNull KeyStroke key, @NotNull CommandState editorState) {
|
||||
return (editorState.getMode() == CommandState.Mode.COMMAND) && StringHelper.isCloseKeyStroke(key);
|
||||
return editorState.getMode() == CommandState.Mode.COMMAND && StringHelper.isCloseKeyStroke(key);
|
||||
}
|
||||
|
||||
private boolean isSelectRegister(@NotNull KeyStroke key, @NotNull CommandState editorState) {
|
||||
if (editorState.getMode() != CommandState.Mode.COMMAND && editorState.getMode() != CommandState.Mode.VISUAL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (editorState.getSubMode() == CommandState.SubMode.REGISTER_PENDING) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return key.getKeyChar() == '"' && !editorState.isOperatorPending() && editorState.getCommandBuilder().getExpectedArgumentType() == null;
|
||||
}
|
||||
|
||||
private void handleSelectRegister(@NotNull CommandState commandState, char chKey) {
|
||||
commandState.resetRegisterPending();
|
||||
if (VimPlugin.getRegister().isValid(chKey)) {
|
||||
commandState.getCommandBuilder().pushCommandPart(chKey);
|
||||
}
|
||||
else {
|
||||
commandState.getCommandBuilder().setCommandState(CurrentCommandState.BAD_COMMAND);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isExpectingCharArgument(@NotNull CommandBuilder commandBuilder) {
|
||||
@@ -615,10 +644,12 @@ public class KeyHandler {
|
||||
if (commandBuilder.getExpectedArgumentType() == Argument.Type.DIGRAPH) {
|
||||
if (DigraphSequence.isDigraphStart(key)) {
|
||||
editorState.startDigraphSequence();
|
||||
editorState.getCommandBuilder().addKey(key);
|
||||
return true;
|
||||
}
|
||||
if (DigraphSequence.isLiteralStart(key)) {
|
||||
editorState.startLiteralSequence();
|
||||
editorState.getCommandBuilder().addKey(key);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -626,7 +657,7 @@ public class KeyHandler {
|
||||
DigraphResult res = editorState.processDigraphKey(key, editor);
|
||||
switch (res.getResult()) {
|
||||
case DigraphResult.RES_HANDLED:
|
||||
case DigraphResult.RES_BAD:
|
||||
editorState.getCommandBuilder().addKey(key);
|
||||
return true;
|
||||
|
||||
case DigraphResult.RES_DONE:
|
||||
@@ -637,10 +668,20 @@ public class KeyHandler {
|
||||
if (stroke == null) {
|
||||
return false;
|
||||
}
|
||||
editorState.getCommandBuilder().addKey(key);
|
||||
handleKey(editor, stroke, context);
|
||||
return true;
|
||||
|
||||
case DigraphResult.RES_BAD:
|
||||
// BAD is an error. We were expecting a valid character, and we didn't get it.
|
||||
if (commandBuilder.getExpectedArgumentType() != null) {
|
||||
commandBuilder.setCommandState(CurrentCommandState.BAD_COMMAND);
|
||||
}
|
||||
return true;
|
||||
|
||||
case DigraphResult.RES_UNHANDLED:
|
||||
// UNHANDLED means the key stroke made no sense in the context of a digraph, but isn't an error in the current
|
||||
// state. E.g. waiting for {char} <BS> {char}. Let the key handler have a go at it.
|
||||
if (commandBuilder.getExpectedArgumentType() == Argument.Type.DIGRAPH) {
|
||||
commandBuilder.fallbackToCharacterArgument();
|
||||
handleKey(editor, key, context);
|
||||
@@ -653,7 +694,6 @@ public class KeyHandler {
|
||||
}
|
||||
|
||||
private void executeCommand(@NotNull Editor editor,
|
||||
@NotNull KeyStroke key,
|
||||
@NotNull DataContext context,
|
||||
@NotNull CommandState editorState) {
|
||||
final Command command = editorState.getCommandBuilder().buildCommand();
|
||||
@@ -676,7 +716,7 @@ public class KeyHandler {
|
||||
}
|
||||
|
||||
if (ApplicationManager.getApplication().isDispatchThread()) {
|
||||
Runnable action = new ActionRunner(editor, context, command, key);
|
||||
Runnable action = new ActionRunner(editor, context, command);
|
||||
EditorActionHandlerBase cmdAction = command.getAction();
|
||||
String name = cmdAction.getId();
|
||||
|
||||
@@ -714,7 +754,7 @@ public class KeyHandler {
|
||||
}
|
||||
else {
|
||||
final Argument.Type argumentType = action.getArgumentType();
|
||||
startWaitingForArgument(editor, context, key.getKeyChar(), argumentType, editorState);
|
||||
startWaitingForArgument(editor, context, key.getKeyChar(), action, argumentType, editorState);
|
||||
partialReset(editor);
|
||||
}
|
||||
|
||||
@@ -751,6 +791,7 @@ public class KeyHandler {
|
||||
private void startWaitingForArgument(Editor editor,
|
||||
DataContext context,
|
||||
char key,
|
||||
@NotNull EditorActionHandlerBase action,
|
||||
@NotNull Argument.Type argument,
|
||||
CommandState editorState) {
|
||||
final CommandBuilder commandBuilder = editorState.getCommandBuilder();
|
||||
@@ -761,6 +802,17 @@ public class KeyHandler {
|
||||
}
|
||||
editorState.pushModes(editorState.getMode(), CommandState.SubMode.OP_PENDING);
|
||||
break;
|
||||
case DIGRAPH:
|
||||
// Command actions represent the completion of a command. Showcmd relies on this - if the action represents a
|
||||
// part of a command, the showcmd output is reset part way through. This means we need to special case entering
|
||||
// digraph/literal input mode. We have an action that takes a digraph as an argument, and pushes it back through
|
||||
// the key handler when it's complete.
|
||||
if (action instanceof InsertCompletedDigraphAction) {
|
||||
editorState.startDigraphSequence();
|
||||
} else if (action instanceof InsertCompletedLiteralAction) {
|
||||
editorState.startLiteralSequence();
|
||||
}
|
||||
break;
|
||||
case EX_STRING:
|
||||
// The current Command expects an EX_STRING argument. E.g. SearchEntry(Fwd|Rev)Action. This won't execute until
|
||||
// state hits READY. Start the ex input field, push CMD_LINE mode and wait for the argument.
|
||||
@@ -810,8 +862,7 @@ public class KeyHandler {
|
||||
editorState.getCommandBuilder().resetAll(getKeyRoot(editorState.getMappingState().getMappingMode()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private CommandPartNode getKeyRoot(MappingMode mappingMode) {
|
||||
private @NotNull CommandPartNode getKeyRoot(MappingMode mappingMode) {
|
||||
return VimPlugin.getKey().getKeyRoot(mappingMode);
|
||||
}
|
||||
|
||||
@@ -825,7 +876,10 @@ public class KeyHandler {
|
||||
VimPlugin.clearError();
|
||||
CommandState.getInstance(editor).reset();
|
||||
reset(editor);
|
||||
VimPlugin.getRegister().resetRegister();
|
||||
RegisterGroup registerGroup = VimPlugin.getRegisterIfCreated();
|
||||
if (registerGroup != null) {
|
||||
registerGroup.resetRegister();
|
||||
}
|
||||
if (editor != null) {
|
||||
VisualGroupKt.updateCaretState(editor);
|
||||
editor.getSelectionModel().removeSelection();
|
||||
@@ -833,9 +887,8 @@ public class KeyHandler {
|
||||
}
|
||||
|
||||
// This method is copied from com.intellij.openapi.editor.actionSystem.EditorAction.getProjectAwareDataContext
|
||||
@NotNull
|
||||
private static DataContext getProjectAwareDataContext(@NotNull final Editor editor,
|
||||
@NotNull final DataContext original) {
|
||||
private static @NotNull DataContext getProjectAwareDataContext(final @NotNull Editor editor,
|
||||
final @NotNull DataContext original) {
|
||||
if (PROJECT.getData(original) == editor.getProject()) {
|
||||
return new DialogAwareDataContext(original);
|
||||
}
|
||||
@@ -853,7 +906,7 @@ public class KeyHandler {
|
||||
}
|
||||
|
||||
// This class is copied from com.intellij.openapi.editor.actionSystem.DialogAwareDataContext.DialogAwareDataContext
|
||||
private final static class DialogAwareDataContext implements DataContext {
|
||||
private static final class DialogAwareDataContext implements DataContext {
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final DataKey[] keys = {PROJECT, PROJECT_FILE_DIRECTORY, EDITOR, VIRTUAL_FILE, PSI_FILE};
|
||||
private final Map<String, Object> values = new HashMap<>();
|
||||
@@ -865,9 +918,8 @@ public class KeyHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object getData(@NotNull @NonNls String dataId) {
|
||||
public @Nullable Object getData(@NotNull @NonNls String dataId) {
|
||||
if (values.containsKey(dataId)) {
|
||||
return values.get(dataId);
|
||||
}
|
||||
@@ -884,11 +936,10 @@ public class KeyHandler {
|
||||
*/
|
||||
static class ActionRunner implements Runnable {
|
||||
@Contract(pure = true)
|
||||
ActionRunner(Editor editor, DataContext context, Command cmd, KeyStroke key) {
|
||||
ActionRunner(Editor editor, DataContext context, Command cmd) {
|
||||
this.editor = editor;
|
||||
this.context = context;
|
||||
this.cmd = cmd;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -897,6 +948,11 @@ public class KeyHandler {
|
||||
|
||||
editorState.getCommandBuilder().setCommandState(CurrentCommandState.NEW_COMMAND);
|
||||
|
||||
final Character register = cmd.getRegister();
|
||||
if (register != null) {
|
||||
VimPlugin.getRegister().selectRegister(register);
|
||||
}
|
||||
|
||||
executeVimAction(editor, cmd.getAction(), context);
|
||||
if (editorState.getMode() == CommandState.Mode.INSERT || editorState.getMode() == CommandState.Mode.REPLACE) {
|
||||
VimPlugin.getChange().processCommand(editor, cmd);
|
||||
@@ -905,10 +961,8 @@ public class KeyHandler {
|
||||
// Now the command has been executed let's clean up a few things.
|
||||
|
||||
// By default, the "empty" register is used by all commands, so we want to reset whatever the last register
|
||||
// selected by the user was to the empty register - unless we just executed the "select register" command.
|
||||
if (cmd.getType() != Command.Type.SELECT_REGISTER) {
|
||||
// selected by the user was to the empty register
|
||||
VimPlugin.getRegister().resetRegister();
|
||||
}
|
||||
|
||||
// If, at this point, we are not in insert, replace, or visual modes, we need to restore the previous
|
||||
// mode we were in. This handles commands in those modes that temporarily allow us to execute normal
|
||||
@@ -925,7 +979,6 @@ public class KeyHandler {
|
||||
private final Editor editor;
|
||||
private final DataContext context;
|
||||
private final Command cmd;
|
||||
private final KeyStroke key;
|
||||
}
|
||||
|
||||
private TypedActionHandler origHandler;
|
||||
|
45
src/com/maddyhome/idea/vim/PluginStartup.kt
Normal file
45
src/com/maddyhome/idea/vim/PluginStartup.kt
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.startup.StartupActivity
|
||||
import com.maddyhome.idea.vim.listener.VimListenerManager
|
||||
|
||||
/**
|
||||
* @author Alex Plate
|
||||
*/
|
||||
class PluginStartup : StartupActivity.DumbAware {
|
||||
|
||||
private var firstInitializationOccurred = false
|
||||
|
||||
override fun runActivity(project: Project) {
|
||||
if (firstInitializationOccurred && VimPlugin.isEnabled()) {
|
||||
// This code should be executed on every project open
|
||||
// Project listeners are self-disposable, so there is no need to unregister them on project close
|
||||
VimListenerManager.ProjectListeners.add(project)
|
||||
}
|
||||
|
||||
if (firstInitializationOccurred) return
|
||||
firstInitializationOccurred = true
|
||||
|
||||
// This code should be executed once
|
||||
VimPlugin.getInstance().initialize()
|
||||
}
|
||||
}
|
@@ -23,6 +23,7 @@ import com.intellij.openapi.extensions.PluginDescriptor;
|
||||
import com.maddyhome.idea.vim.group.KeyGroup;
|
||||
import com.maddyhome.idea.vim.handler.ActionBeanClass;
|
||||
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase;
|
||||
import com.maddyhome.idea.vim.key.MappingOwner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -33,58 +34,41 @@ public class RegisterActions {
|
||||
|
||||
public static final ExtensionPointName<ActionBeanClass> VIM_ACTIONS_EP =
|
||||
ExtensionPointName.create("IdeaVIM.vimAction");
|
||||
private static boolean initialRegistration = false;
|
||||
|
||||
static {
|
||||
// IdeaVim doesn't support contribution to VIM_ACTIONS_EP extension point, so technically we can skip this update,
|
||||
// but let's support dynamic plugins in a more classic way and reload actions on every EP change.
|
||||
// TODO: [VERSION UPDATE] since 191 use
|
||||
// ExtensionPoint.addExtensionPointListener(ExtensionPointListener<T>, boolean, Disposable)
|
||||
// TODO: [VERSION UPDATE] since 201 use
|
||||
// ExtensionPoint.addExtensionPointListener(ExtensionPointChangeListener, boolean, Disposable)
|
||||
VIM_ACTIONS_EP.getPoint(null).addExtensionPointListener(new ExtensionPointListener<ActionBeanClass>() {
|
||||
@Override
|
||||
public void extensionAdded(@NotNull ActionBeanClass extension, @NotNull PluginDescriptor pluginDescriptor) {
|
||||
// Suppress listener before the `VimPlugin.turnOn()` function execution. This logic should be rewritten after
|
||||
// version update (or earlier).
|
||||
if (!initialRegistration) return;
|
||||
unregisterActions();
|
||||
registerActions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extensionRemoved(@NotNull ActionBeanClass extension, @NotNull PluginDescriptor pluginDescriptor) {
|
||||
if (!initialRegistration) return;
|
||||
unregisterActions();
|
||||
registerActions();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all the key/action mappings for the plugin.
|
||||
*/
|
||||
static void registerActions() {
|
||||
public static void registerActions() {
|
||||
registerVimCommandActions();
|
||||
registerEmptyShortcuts();
|
||||
initialRegistration = true;
|
||||
registerEpListener();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static EditorActionHandlerBase findAction(@NotNull String id) {
|
||||
private static void registerEpListener() {
|
||||
// IdeaVim doesn't support contribution to VIM_ACTIONS_EP extension point, so technically we can skip this update,
|
||||
// but let's support dynamic plugins in a more classic way and reload actions on every EP change.
|
||||
VIM_ACTIONS_EP.getPoint(null).addExtensionPointListener(() -> {
|
||||
unregisterActions();
|
||||
registerActions();
|
||||
}, false, VimPlugin.getInstance());
|
||||
}
|
||||
|
||||
public static @Nullable EditorActionHandlerBase findAction(@NotNull String id) {
|
||||
return VIM_ACTIONS_EP.extensions().filter(vimActionBean -> vimActionBean.getActionId().equals(id)).findFirst()
|
||||
.map(ActionBeanClass::getAction).orElse(null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static EditorActionHandlerBase findActionOrDie(@NotNull String id) {
|
||||
public static @NotNull EditorActionHandlerBase findActionOrDie(@NotNull String id) {
|
||||
EditorActionHandlerBase action = findAction(id);
|
||||
if (action == null) throw new RuntimeException("Action " + id + " is not registered");
|
||||
return action;
|
||||
}
|
||||
|
||||
public static void unregisterActions() {
|
||||
VimPlugin.getKey().unregisterCommandActions();
|
||||
KeyGroup keyGroup = VimPlugin.getKeyIfCreated();
|
||||
if (keyGroup != null) {
|
||||
keyGroup.unregisterCommandActions();
|
||||
}
|
||||
}
|
||||
|
||||
private static void registerVimCommandActions() {
|
||||
@@ -97,6 +81,6 @@ public class RegisterActions {
|
||||
|
||||
// The {char1} <BS> {char2} shortcut is handled directly by KeyHandler#handleKey, so doesn't have an action. But we
|
||||
// still need to register the shortcut, to make sure the editor doesn't swallow it.
|
||||
parser.registerShortcutWithoutAction(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0));
|
||||
parser.registerShortcutWithoutAction(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), MappingOwner.IdeaVim.INSTANCE);
|
||||
}
|
||||
}
|
||||
|
@@ -20,9 +20,9 @@ package com.maddyhome.idea.vim
|
||||
|
||||
import com.intellij.openapi.components.PersistentStateComponent
|
||||
import com.intellij.openapi.components.RoamingType
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.components.State
|
||||
import com.intellij.openapi.components.Storage
|
||||
import com.maddyhome.idea.vim.VimPlugin.STATE_VERSION
|
||||
import org.jdom.Element
|
||||
|
||||
/**
|
||||
@@ -31,28 +31,26 @@ import org.jdom.Element
|
||||
|
||||
@State(name = "VimLocalSettings", storages = [
|
||||
Storage("\$APP_CONFIG$$/vim_local_settings.xml", roamingType = RoamingType.DISABLED, deprecated = true),
|
||||
Storage("\$APP_CONFIG$/vim_local_settings.xml", roamingType = RoamingType.DISABLED)
|
||||
])
|
||||
// TODO: 27.01.2020 [VERSION UPDATE] 2019.3 https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_services.html#light-services
|
||||
Storage("\$APP_CONFIG$/vim_local_settings.xml", roamingType = RoamingType.DISABLED, deprecated = true)
|
||||
])
|
||||
@Deprecated("The data from this class will be stored in vim_settings")
|
||||
class VimLocalConfig : PersistentStateComponent<Element> {
|
||||
override fun getState(): Element {
|
||||
val element = Element("ideavim-local")
|
||||
|
||||
val state = Element("state")
|
||||
state.setAttribute("version", STATE_VERSION.toString())
|
||||
element.addContent(state)
|
||||
|
||||
VimPlugin.getMark().saveData(element)
|
||||
VimPlugin.getRegister().saveData(element)
|
||||
VimPlugin.getSearch().saveData(element)
|
||||
VimPlugin.getHistory().saveData(element)
|
||||
return element
|
||||
}
|
||||
override fun getState(): Element? = null
|
||||
|
||||
override fun loadState(state: Element) {
|
||||
// This is initialization of state from the legacy configuration structure.
|
||||
// This code should be performed only once on settings migration.
|
||||
// After the migration is done, the file with settings gets removed and this method won't be called again.
|
||||
VimPlugin.getMark().readData(state)
|
||||
VimPlugin.getRegister().readData(state)
|
||||
VimPlugin.getSearch().readData(state)
|
||||
VimPlugin.getHistory().readData(state)
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun initialize() {
|
||||
@Suppress("DEPRECATION")
|
||||
ServiceManager.getService(VimLocalConfig::class.java)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,14 +19,15 @@ package com.maddyhome.idea.vim;
|
||||
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptor;
|
||||
import com.intellij.ide.plugins.PluginManager;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationListener;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationInfo;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PermanentInstallationID;
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.PluginId;
|
||||
import com.intellij.openapi.keymap.Keymap;
|
||||
@@ -36,12 +37,9 @@ import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.openapi.wm.StatusBar;
|
||||
import com.intellij.openapi.wm.WindowManager;
|
||||
import com.intellij.util.io.HttpRequests;
|
||||
import com.maddyhome.idea.vim.ex.CommandParser;
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptParser;
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionRegistrar;
|
||||
@@ -53,18 +51,20 @@ import com.maddyhome.idea.vim.helper.MacKeyRepeat;
|
||||
import com.maddyhome.idea.vim.listener.VimListenerManager;
|
||||
import com.maddyhome.idea.vim.option.OptionsManager;
|
||||
import com.maddyhome.idea.vim.ui.ExEntryPanel;
|
||||
import com.maddyhome.idea.vim.ui.StatusBarIconFactory;
|
||||
import com.maddyhome.idea.vim.ui.VimEmulationConfigurable;
|
||||
import com.maddyhome.idea.vim.ui.VimRcFileState;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.List;
|
||||
|
||||
import static com.maddyhome.idea.vim.group.EditorGroup.EDITOR_STORE_ELEMENT;
|
||||
import static com.maddyhome.idea.vim.group.KeyGroup.SHORTCUT_CONFLICTS_ELEMENT;
|
||||
|
||||
/**
|
||||
* This plugin attempts to emulate the key binding and general functionality of Vim and gVim. See the supplied
|
||||
@@ -75,11 +75,9 @@ import java.util.concurrent.TimeUnit;
|
||||
* Registers and marks are shared across open projects so you can copy and paste between files of different projects.
|
||||
*/
|
||||
@State(name = "VimSettings", storages = {@Storage("$APP_CONFIG$/vim_settings.xml")})
|
||||
public class VimPlugin implements BaseComponent, PersistentStateComponent<Element>, Disposable {
|
||||
private static final String IDEAVIM_COMPONENT_NAME = "VimPlugin";
|
||||
public class VimPlugin implements PersistentStateComponent<Element>, Disposable {
|
||||
private static final String IDEAVIM_PLUGIN_ID = "IdeaVIM";
|
||||
private static final String IDEAVIM_STATISTICS_TIMESTAMP_KEY = "ideavim.statistics.timestamp";
|
||||
public static final int STATE_VERSION = 5;
|
||||
private static final int STATE_VERSION = 6;
|
||||
|
||||
private static long lastBeepTimeMillis;
|
||||
|
||||
@@ -94,21 +92,25 @@ public class VimPlugin implements BaseComponent, PersistentStateComponent<Elemen
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(VimPlugin.class);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getComponentName() {
|
||||
return IDEAVIM_COMPONENT_NAME;
|
||||
}
|
||||
private final @NotNull VimState state = new VimState();
|
||||
|
||||
|
||||
@NotNull private final VimState state = new VimState();
|
||||
|
||||
// [VERSION UPDATE] 193+ replace with com.intellij.openapi.components.PersistentStateComponent.initializeComponent
|
||||
@Override
|
||||
public void initComponent() {
|
||||
public void initialize() {
|
||||
LOG.debug("initComponent");
|
||||
|
||||
if (enabled) turnOnPlugin();
|
||||
// Initialize a legacy local config.
|
||||
if (previousStateVersion == 5) {
|
||||
//noinspection deprecation
|
||||
VimLocalConfig.Companion.initialize();
|
||||
}
|
||||
if (enabled) {
|
||||
Application application = ApplicationManager.getApplication();
|
||||
if (application.isUnitTestMode()) {
|
||||
application.invokeAndWait(this::turnOnPlugin);
|
||||
}
|
||||
else {
|
||||
application.invokeLater(this::turnOnPlugin);
|
||||
}
|
||||
}
|
||||
|
||||
LOG.debug("done");
|
||||
}
|
||||
@@ -123,174 +125,105 @@ public class VimPlugin implements BaseComponent, PersistentStateComponent<Elemen
|
||||
/**
|
||||
* @return NotificationService as applicationService if project is null and projectService otherwise
|
||||
*/
|
||||
@NotNull
|
||||
public static NotificationService getNotifications(@Nullable Project project) {
|
||||
public static @NotNull NotificationService getNotifications(@Nullable Project project) {
|
||||
if (project == null) {
|
||||
return ServiceManager.getService(NotificationService.class);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return ServiceManager.getService(project, NotificationService.class);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static VimState getVimState() {
|
||||
public static @NotNull VimState getVimState() {
|
||||
return getInstance().state;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static MotionGroup getMotion() {
|
||||
public static @NotNull MotionGroup getMotion() {
|
||||
return ServiceManager.getService(MotionGroup.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports statistics about installed IdeaVim and enabled Vim emulation.
|
||||
* <p>
|
||||
* See https://github.com/go-lang-plugin-org/go-lang-idea-plugin/commit/5182ab4a1d01ad37f6786268a2fe5e908575a217
|
||||
*/
|
||||
public static void statisticReport() {
|
||||
final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
|
||||
final long lastUpdate = propertiesComponent.getOrInitLong(IDEAVIM_STATISTICS_TIMESTAMP_KEY, 0);
|
||||
final boolean outOfDate =
|
||||
lastUpdate == 0 || System.currentTimeMillis() - lastUpdate > TimeUnit.DAYS.toMillis(1);
|
||||
if (outOfDate && isEnabled()) {
|
||||
ApplicationManager.getApplication().executeOnPooledThread(() -> {
|
||||
try {
|
||||
final String buildNumber = ApplicationInfo.getInstance().getBuild().asString();
|
||||
final String version = URLEncoder.encode(getVersion(), CharsetToolkit.UTF8);
|
||||
final String os =
|
||||
URLEncoder.encode(SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION, CharsetToolkit.UTF8);
|
||||
final String uid = PermanentInstallationID.get();
|
||||
final String url = "https://plugins.jetbrains.com/plugins/list" +
|
||||
"?pluginId=" + IDEAVIM_PLUGIN_ID +
|
||||
"&build=" +
|
||||
buildNumber +
|
||||
"&pluginVersion=" +
|
||||
version +
|
||||
"&os=" +
|
||||
os +
|
||||
"&uuid=" +
|
||||
uid;
|
||||
PropertiesComponent.getInstance()
|
||||
.setValue(IDEAVIM_STATISTICS_TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
|
||||
HttpRequests.request(url).connect(request -> {
|
||||
LOG.info("Sending statistics: " + url);
|
||||
try {
|
||||
JDOMUtil.load(request.getInputStream());
|
||||
}
|
||||
catch (JDOMException e) {
|
||||
LOG.warn(e);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.warn(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ChangeGroup getChange() {
|
||||
public static @NotNull ChangeGroup getChange() {
|
||||
return ServiceManager.getService(ChangeGroup.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static CommandGroup getCommand() {
|
||||
public static @NotNull CommandGroup getCommand() {
|
||||
return ServiceManager.getService(CommandGroup.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static MarkGroup getMark() {
|
||||
public static @NotNull MarkGroup getMark() {
|
||||
return ServiceManager.getService(MarkGroup.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static RegisterGroup getRegister() {
|
||||
public static @NotNull RegisterGroup getRegister() {
|
||||
return ServiceManager.getService(RegisterGroup.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FileGroup getFile() {
|
||||
public static @Nullable RegisterGroup getRegisterIfCreated() {
|
||||
return ServiceManager.getServiceIfCreated(RegisterGroup.class);
|
||||
}
|
||||
|
||||
public static @NotNull FileGroup getFile() {
|
||||
return ServiceManager.getService(FileGroup.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SearchGroup getSearch() {
|
||||
public static @NotNull SearchGroup getSearch() {
|
||||
return ServiceManager.getService(SearchGroup.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ProcessGroup getProcess() {
|
||||
public static @Nullable SearchGroup getSearchIfCreated() {
|
||||
return ServiceManager.getServiceIfCreated(SearchGroup.class);
|
||||
}
|
||||
|
||||
public static @NotNull ProcessGroup getProcess() {
|
||||
return ServiceManager.getService(ProcessGroup.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static MacroGroup getMacro() {
|
||||
public static @NotNull MacroGroup getMacro() {
|
||||
return ServiceManager.getService(MacroGroup.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static DigraphGroup getDigraph() {
|
||||
public static @NotNull DigraphGroup getDigraph() {
|
||||
return ServiceManager.getService(DigraphGroup.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HistoryGroup getHistory() {
|
||||
public static @NotNull HistoryGroup getHistory() {
|
||||
return ServiceManager.getService(HistoryGroup.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static KeyGroup getKey() {
|
||||
public static @NotNull KeyGroup getKey() {
|
||||
return ServiceManager.getService(KeyGroup.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static WindowGroup getWindow() {
|
||||
public static @Nullable KeyGroup getKeyIfCreated() {
|
||||
return ServiceManager.getServiceIfCreated(KeyGroup.class);
|
||||
}
|
||||
|
||||
public static @NotNull WindowGroup getWindow() {
|
||||
return ServiceManager.getService(WindowGroup.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static EditorGroup getEditor() {
|
||||
public static @NotNull EditorGroup getEditor() {
|
||||
return ServiceManager.getService(EditorGroup.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static VisualMotionGroup getVisualMotion() {
|
||||
public static @Nullable EditorGroup getEditorIfCreated() {
|
||||
return ServiceManager.getServiceIfCreated(EditorGroup.class);
|
||||
}
|
||||
|
||||
public static @NotNull VisualMotionGroup getVisualMotion() {
|
||||
return ServiceManager.getService(VisualMotionGroup.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static YankGroup getYank() {
|
||||
public static @NotNull YankGroup getYank() {
|
||||
return ServiceManager.getService(YankGroup.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PutGroup getPut() {
|
||||
public static @NotNull PutGroup getPut() {
|
||||
return ServiceManager.getService(PutGroup.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element getState() {
|
||||
LOG.debug("Saving state");
|
||||
|
||||
final Element element = new Element("ideavim");
|
||||
// Save whether the plugin is enabled or not
|
||||
final Element state = new Element("state");
|
||||
state.setAttribute("version", Integer.toString(STATE_VERSION));
|
||||
state.setAttribute("enabled", Boolean.toString(enabled));
|
||||
element.addContent(state);
|
||||
|
||||
getKey().saveData(element);
|
||||
getEditor().saveData(element);
|
||||
this.state.saveData(element);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static NotificationService getNotifications() {
|
||||
private static @NotNull NotificationService getNotifications() {
|
||||
return getNotifications(null);
|
||||
}
|
||||
|
||||
@@ -301,22 +234,23 @@ public class VimPlugin implements BaseComponent, PersistentStateComponent<Elemen
|
||||
ideavimrcRegistered = true;
|
||||
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
final File ideaVimRc = VimScriptParser.findIdeaVimRc();
|
||||
if (ideaVimRc != null) {
|
||||
VimScriptParser.executeFile(ideaVimRc);
|
||||
}
|
||||
executeIdeaVimRc();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PluginId getPluginId() {
|
||||
public void executeIdeaVimRc() {
|
||||
final File ideaVimRc = VimScriptParser.findIdeaVimRc();
|
||||
if (ideaVimRc != null) {
|
||||
List<String> parsedLines = VimScriptParser.executeFile(ideaVimRc);
|
||||
VimRcFileState.INSTANCE.saveFileState(ideaVimRc.getAbsolutePath(), parsedLines);
|
||||
}
|
||||
}
|
||||
|
||||
public static @NotNull PluginId getPluginId() {
|
||||
return PluginId.getId(IDEAVIM_PLUGIN_ID);
|
||||
}
|
||||
|
||||
// [VERSION UPDATE] 193+ remove suppress
|
||||
@SuppressWarnings({"MissingRecentApi", "UnstableApiUsage"})
|
||||
@NotNull
|
||||
public static String getVersion() {
|
||||
public static @NotNull String getVersion() {
|
||||
final IdeaPluginDescriptor plugin = PluginManager.getPlugin(getPluginId());
|
||||
if (!ApplicationManager.getApplication().isInternal()) {
|
||||
return plugin != null ? plugin.getVersion() : "SNAPSHOT";
|
||||
@@ -343,7 +277,7 @@ public class VimPlugin implements BaseComponent, PersistentStateComponent<Elemen
|
||||
getInstance().turnOnPlugin();
|
||||
}
|
||||
|
||||
VimStatusBar.INSTANCE.update();
|
||||
StatusBarIconFactory.Companion.updateIcon();
|
||||
}
|
||||
|
||||
public static boolean isError() {
|
||||
@@ -400,18 +334,13 @@ public class VimPlugin implements BaseComponent, PersistentStateComponent<Elemen
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static VimPlugin getInstance() {
|
||||
return ApplicationManager.getApplication().getComponent(VimPlugin.class);
|
||||
public static @NotNull VimPlugin getInstance() {
|
||||
return ServiceManager.getService(VimPlugin.class);
|
||||
}
|
||||
|
||||
private void turnOnPlugin() {
|
||||
ApplicationManager.getApplication().invokeLater(this::updateState);
|
||||
|
||||
getEditor().turnOn();
|
||||
getSearch().turnOn();
|
||||
VimListenerManager.INSTANCE.turnOn();
|
||||
|
||||
// Register vim actions in command mode
|
||||
RegisterActions.registerActions();
|
||||
|
||||
@@ -423,21 +352,27 @@ public class VimPlugin implements BaseComponent, PersistentStateComponent<Elemen
|
||||
|
||||
// Execute ~/.ideavimrc
|
||||
registerIdeavimrc();
|
||||
|
||||
// Turing on should be performed after all commands registration
|
||||
getSearch().turnOn();
|
||||
VimListenerManager.INSTANCE.turnOn();
|
||||
}
|
||||
|
||||
private void turnOffPlugin() {
|
||||
KeyHandler.getInstance().fullReset(null);
|
||||
|
||||
SearchGroup searchGroup = getSearchIfCreated();
|
||||
if (searchGroup != null) {
|
||||
searchGroup.turnOff();
|
||||
}
|
||||
VimListenerManager.INSTANCE.turnOff();
|
||||
ExEntryPanel.fullReset();
|
||||
|
||||
// Unregister vim actions in command mode
|
||||
RegisterActions.unregisterActions();
|
||||
|
||||
// Unregister ex handlers
|
||||
CommandParser.getInstance().unregisterHandlers();
|
||||
|
||||
getEditor().turnOff();
|
||||
getSearch().turnOff();
|
||||
VimListenerManager.INSTANCE.turnOff();
|
||||
ExEntryPanel.fullReset();
|
||||
}
|
||||
|
||||
private boolean stateUpdated = false;
|
||||
@@ -485,7 +420,7 @@ public class VimPlugin implements BaseComponent, PersistentStateComponent<Elemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(@NotNull final Element element) {
|
||||
public void loadState(final @NotNull Element element) {
|
||||
LOG.debug("Loading state");
|
||||
|
||||
// Restore whether the plugin is enabled or not
|
||||
@@ -500,6 +435,27 @@ public class VimPlugin implements BaseComponent, PersistentStateComponent<Elemen
|
||||
previousKeyMap = state.getAttributeValue("keymap");
|
||||
}
|
||||
|
||||
legacyStateLoading(element);
|
||||
this.state.readData(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element getState() {
|
||||
LOG.debug("Saving state");
|
||||
|
||||
final Element element = new Element("ideavim");
|
||||
// Save whether the plugin is enabled or not
|
||||
final Element state = new Element("state");
|
||||
state.setAttribute("version", Integer.toString(STATE_VERSION));
|
||||
state.setAttribute("enabled", Boolean.toString(enabled));
|
||||
element.addContent(state);
|
||||
|
||||
this.state.saveData(element);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
private void legacyStateLoading(@NotNull Element element) {
|
||||
if (previousStateVersion > 0 && previousStateVersion < 5) {
|
||||
// Migrate settings from 4 to 5 version
|
||||
getMark().readData(element);
|
||||
@@ -507,8 +463,11 @@ public class VimPlugin implements BaseComponent, PersistentStateComponent<Elemen
|
||||
getSearch().readData(element);
|
||||
getHistory().readData(element);
|
||||
}
|
||||
if (element.getChild(SHORTCUT_CONFLICTS_ELEMENT) != null) {
|
||||
getKey().readData(element);
|
||||
}
|
||||
if (element.getChild(EDITOR_STORE_ELEMENT) != null) {
|
||||
getEditor().readData(element);
|
||||
this.state.readData(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,17 +18,22 @@
|
||||
|
||||
package com.maddyhome.idea.vim
|
||||
|
||||
import com.intellij.openapi.components.ProjectComponent
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.maddyhome.idea.vim.listener.VimListenerManager
|
||||
|
||||
/**
|
||||
* @author Alex Plate
|
||||
*/
|
||||
class VimProjectComponent(private val project: Project) : ProjectComponent {
|
||||
override fun projectOpened() {
|
||||
if (!VimPlugin.isEnabled()) return
|
||||
// Project listeners are self-disposable, so there is no need to unregister them on project close
|
||||
VimListenerManager.ProjectListeners.add(project)
|
||||
@Service
|
||||
class VimProjectService(val project: Project) : Disposable {
|
||||
override fun dispose() {}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun getInstance(project: Project): VimProjectService {
|
||||
return ServiceManager.getService(project, VimProjectService::class.java)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val Project.vimDisposable
|
||||
get() = VimProjectService.getInstance(this)
|
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actionSystem.ActionPlan;
|
||||
import com.intellij.openapi.editor.actionSystem.TypedActionHandler;
|
||||
import com.intellij.openapi.editor.actionSystem.TypedActionHandlerEx;
|
||||
import com.maddyhome.idea.vim.helper.EditorDataContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* Accepts all regular keystrokes and passes them on to the Vim key handler.
|
||||
*
|
||||
* IDE shortcut keys used by Vim commands are handled by {@link com.maddyhome.idea.vim.action.VimShortcutKeyAction}.
|
||||
*/
|
||||
public class VimTypedActionHandler implements TypedActionHandlerEx {
|
||||
private static final Logger logger = Logger.getInstance(VimTypedActionHandler.class.getName());
|
||||
|
||||
@NotNull private final KeyHandler handler;
|
||||
|
||||
public VimTypedActionHandler(TypedActionHandler origHandler) {
|
||||
handler = KeyHandler.getInstance();
|
||||
handler.setOriginalHandler(origHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeExecute(@NotNull Editor editor, char charTyped, @NotNull DataContext context, @NotNull ActionPlan plan) {
|
||||
handler.beforeHandleKey(editor, KeyStroke.getKeyStroke(charTyped), context, plan);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull final Editor editor, final char charTyped, @NotNull final DataContext context) {
|
||||
try {
|
||||
handler.handleKey(editor, KeyStroke.getKeyStroke(charTyped), new EditorDataContext(editor));
|
||||
}
|
||||
catch (Throwable e) {
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
}
|
74
src/com/maddyhome/idea/vim/VimTypedActionHandler.kt
Normal file
74
src/com/maddyhome/idea/vim/VimTypedActionHandler.kt
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.maddyhome.idea.vim
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.actionSystem.ActionPlan
|
||||
import com.intellij.openapi.editor.actionSystem.TypedActionHandler
|
||||
import com.intellij.openapi.editor.actionSystem.TypedActionHandlerEx
|
||||
import com.maddyhome.idea.vim.helper.EditorDataContext
|
||||
import java.awt.event.KeyAdapter
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
/**
|
||||
* Accepts all regular keystrokes and passes them on to the Vim key handler.
|
||||
*
|
||||
* IDE shortcut keys used by Vim commands are handled by [com.maddyhome.idea.vim.action.VimShortcutKeyAction].
|
||||
*/
|
||||
class VimTypedActionHandler(origHandler: TypedActionHandler?) : TypedActionHandlerEx {
|
||||
private val handler = KeyHandler.getInstance()
|
||||
|
||||
init {
|
||||
handler.originalHandler = origHandler
|
||||
}
|
||||
|
||||
override fun beforeExecute(editor: Editor, charTyped: Char, context: DataContext, plan: ActionPlan) {
|
||||
val modifiers = if (charTyped == ' ' && VimKeyListener.isSpaceShift) KeyEvent.SHIFT_DOWN_MASK else 0
|
||||
val keyStroke = KeyStroke.getKeyStroke(charTyped, modifiers)
|
||||
handler.beforeHandleKey(editor, keyStroke, context, plan)
|
||||
}
|
||||
|
||||
override fun execute(editor: Editor, charTyped: Char, context: DataContext) {
|
||||
try {
|
||||
val modifiers = if (charTyped == ' ' && VimKeyListener.isSpaceShift) KeyEvent.SHIFT_DOWN_MASK else 0
|
||||
val keyStroke = KeyStroke.getKeyStroke(charTyped, modifiers)
|
||||
handler.handleKey(editor, keyStroke, EditorDataContext(editor))
|
||||
} catch (e: Throwable) {
|
||||
logger.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val logger = logger<VimTypedActionHandler>()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A nasty workaround to handle `<S-Space>` events. Probably all the key events should go trough this listener.
|
||||
*/
|
||||
object VimKeyListener : KeyAdapter() {
|
||||
|
||||
var isSpaceShift = false
|
||||
|
||||
override fun keyPressed(e: KeyEvent) {
|
||||
isSpaceShift = e.modifiersEx and KeyEvent.SHIFT_DOWN_MASK != 0 && e.keyChar == ' '
|
||||
}
|
||||
}
|
@@ -20,7 +20,7 @@ package com.maddyhome.idea.vim.action
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.project.DumbAwareToggleAction
|
||||
import com.maddyhome.idea.vim.VimActions
|
||||
import com.maddyhome.idea.vim.ui.VimActions
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
|
||||
/**
|
||||
|
@@ -86,27 +86,26 @@ class VimShortcutKeyAction : AnAction(), DumbAware {
|
||||
@Suppress("DEPRECATION")
|
||||
val SMART_STEP_INPLACE_DATA = Key.findKeyByName("SMART_STEP_INPLACE_DATA")
|
||||
if (SMART_STEP_INPLACE_DATA != null && editor.getUserData(SMART_STEP_INPLACE_DATA) != null) return false
|
||||
|
||||
if (aceJumpActive()) return false
|
||||
|
||||
val keyCode = keyStroke.keyCode
|
||||
if (LookupManager.getActiveLookup(editor) != null) {
|
||||
return LookupKeys.isEnabledForLookup(keyStroke)
|
||||
}
|
||||
if (keyCode == KeyEvent.VK_ESCAPE) {
|
||||
return isEnabledForEscape(editor)
|
||||
}
|
||||
|
||||
if (LookupManager.getActiveLookup(editor) != null && !LookupKeys.isEnabledForLookup(keyStroke)) return false
|
||||
|
||||
if (keyCode == KeyEvent.VK_ESCAPE) return isEnabledForEscape(editor)
|
||||
|
||||
if (editor.inInsertMode) { // XXX: <Tab> won't be recorded in macros
|
||||
if (keyCode == KeyEvent.VK_TAB) {
|
||||
VimPlugin.getChange().tabAction = true
|
||||
return false
|
||||
}
|
||||
// Debug watch, Python console, etc.
|
||||
if (NON_FILE_EDITOR_KEYS.contains(keyStroke) && !EditorHelper.isFileEditor(editor)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if (VIM_ONLY_EDITOR_KEYS.contains(keyStroke)) {
|
||||
return true
|
||||
if (keyStroke in NON_FILE_EDITOR_KEYS && !EditorHelper.isFileEditor(editor)) return false
|
||||
}
|
||||
|
||||
if (keyStroke in VIM_ONLY_EDITOR_KEYS) return true
|
||||
|
||||
val savedShortcutConflicts = VimPlugin.getKey().savedShortcutConflicts
|
||||
return when (savedShortcutConflicts[keyStroke]) {
|
||||
ShortcutOwner.VIM -> true
|
||||
@@ -191,15 +190,15 @@ class VimShortcutKeyAction : AnAction(), DumbAware {
|
||||
companion object {
|
||||
@JvmField
|
||||
val VIM_ONLY_EDITOR_KEYS: Set<KeyStroke> = ImmutableSet.builder<KeyStroke>().addAll(getKeyStrokes(KeyEvent.VK_ENTER, 0)).addAll(getKeyStrokes(KeyEvent.VK_ESCAPE, 0))
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_TAB, 0)).addAll(getKeyStrokes(KeyEvent.VK_BACK_SPACE, 0, InputEvent.CTRL_MASK))
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_INSERT, 0)).addAll(getKeyStrokes(KeyEvent.VK_DELETE, 0, InputEvent.CTRL_MASK))
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_UP, 0, InputEvent.CTRL_MASK, InputEvent.SHIFT_MASK)).addAll(getKeyStrokes(KeyEvent.VK_DOWN, 0, InputEvent.CTRL_MASK, InputEvent.SHIFT_MASK))
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_LEFT, 0, InputEvent.CTRL_MASK, InputEvent.SHIFT_MASK, InputEvent.CTRL_MASK or InputEvent.SHIFT_MASK))
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_RIGHT, 0, InputEvent.CTRL_MASK, InputEvent.SHIFT_MASK, InputEvent.CTRL_MASK or InputEvent.SHIFT_MASK))
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_HOME, 0, InputEvent.CTRL_MASK, InputEvent.SHIFT_MASK, InputEvent.CTRL_MASK or InputEvent.SHIFT_MASK))
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_END, 0, InputEvent.CTRL_MASK, InputEvent.SHIFT_MASK, InputEvent.CTRL_MASK or InputEvent.SHIFT_MASK))
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_PAGE_UP, 0, InputEvent.SHIFT_MASK, InputEvent.CTRL_MASK or InputEvent.SHIFT_MASK))
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_PAGE_DOWN, 0, InputEvent.SHIFT_MASK, InputEvent.CTRL_MASK or InputEvent.SHIFT_MASK)).build()
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_TAB, 0)).addAll(getKeyStrokes(KeyEvent.VK_BACK_SPACE, 0, InputEvent.CTRL_DOWN_MASK))
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_INSERT, 0)).addAll(getKeyStrokes(KeyEvent.VK_DELETE, 0, InputEvent.CTRL_DOWN_MASK))
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_UP, 0, InputEvent.CTRL_DOWN_MASK, InputEvent.SHIFT_DOWN_MASK)).addAll(getKeyStrokes(KeyEvent.VK_DOWN, 0, InputEvent.CTRL_DOWN_MASK, InputEvent.SHIFT_DOWN_MASK))
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_LEFT, 0, InputEvent.CTRL_DOWN_MASK, InputEvent.SHIFT_DOWN_MASK, InputEvent.CTRL_DOWN_MASK or InputEvent.SHIFT_DOWN_MASK))
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_RIGHT, 0, InputEvent.CTRL_DOWN_MASK, InputEvent.SHIFT_DOWN_MASK, InputEvent.CTRL_DOWN_MASK or InputEvent.SHIFT_DOWN_MASK))
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_HOME, 0, InputEvent.CTRL_DOWN_MASK, InputEvent.SHIFT_DOWN_MASK, InputEvent.CTRL_DOWN_MASK or InputEvent.SHIFT_DOWN_MASK))
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_END, 0, InputEvent.CTRL_DOWN_MASK, InputEvent.SHIFT_DOWN_MASK, InputEvent.CTRL_DOWN_MASK or InputEvent.SHIFT_DOWN_MASK))
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_PAGE_UP, 0, InputEvent.SHIFT_DOWN_MASK, InputEvent.CTRL_DOWN_MASK or InputEvent.SHIFT_DOWN_MASK))
|
||||
.addAll(getKeyStrokes(KeyEvent.VK_PAGE_DOWN, 0, InputEvent.SHIFT_DOWN_MASK, InputEvent.CTRL_DOWN_MASK or InputEvent.SHIFT_DOWN_MASK)).build()
|
||||
|
||||
private const val ACTION_ID = "VimShortcutKeyAction"
|
||||
|
||||
|
@@ -45,6 +45,7 @@ class OperatorAction : VimActionHandler.SingleExecution() {
|
||||
if (!editor.commandState.isDotRepeatInProgress) {
|
||||
VimRepeater.Extension.argumentCaptured = argument
|
||||
}
|
||||
val saveRepeatHandler = VimRepeater.repeatHandler
|
||||
val motion = argument.motion
|
||||
val range = MotionGroup
|
||||
.getMotionRange(editor, editor.caretModel.primaryCaret, context, cmd.count, cmd.rawCount, argument)
|
||||
@@ -52,7 +53,9 @@ class OperatorAction : VimActionHandler.SingleExecution() {
|
||||
VimPlugin.getMark().setChangeMarks(editor, range)
|
||||
val selectionType = SelectionType.fromCommandFlags(motion.flags)
|
||||
KeyHandler.getInstance().reset(editor)
|
||||
return operatorFunction.apply(editor, context, selectionType)
|
||||
val result = operatorFunction.apply(editor, context, selectionType)
|
||||
VimRepeater.repeatHandler = saveRepeatHandler
|
||||
return result
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
@@ -64,7 +64,7 @@ class RepeatChangeAction : VimActionHandler.SingleExecution() {
|
||||
}
|
||||
state.setExecutingCommand(lastCommand)
|
||||
|
||||
KeyHandler.executeVimAction(editor, lastCommand.action, context)
|
||||
KeyHandler.executeVimAction(editor, lastCommand.action!!, context)
|
||||
|
||||
VimRepeater.saveLastChange(lastCommand)
|
||||
}
|
||||
|
@@ -23,14 +23,12 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.command.CommandState.SubMode
|
||||
import com.maddyhome.idea.vim.command.SelectionType
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.group.visual.VimSelection
|
||||
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import com.maddyhome.idea.vim.helper.subMode
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@@ -46,15 +44,18 @@ class DeleteVisualLinesAction : VisualOperatorActionHandler.ForEachCaret() {
|
||||
context: DataContext,
|
||||
cmd: Command,
|
||||
range: VimSelection): Boolean {
|
||||
val mode = editor.subMode
|
||||
val textRange = range.toVimTextRange(false)
|
||||
return if (mode == SubMode.VISUAL_BLOCK) {
|
||||
VimPlugin.getChange()
|
||||
.deleteRange(editor, editor.caretModel.primaryCaret, textRange, SelectionType.fromSubMode(mode), false)
|
||||
} else {
|
||||
val lineRange = TextRange(EditorHelper.getLineStartForOffset(editor, textRange.startOffset),
|
||||
EditorHelper.getLineEndForOffset(editor, textRange.endOffset) + 1)
|
||||
VimPlugin.getChange().deleteRange(editor, caret, lineRange, SelectionType.LINE_WISE, false)
|
||||
val (usedCaret, usedRange, usedType) = when (range.type) {
|
||||
SelectionType.BLOCK_WISE -> Triple(editor.caretModel.primaryCaret, textRange, range.type)
|
||||
SelectionType.LINE_WISE -> Triple(caret, textRange, SelectionType.LINE_WISE)
|
||||
SelectionType.CHARACTER_WISE -> {
|
||||
val lineRange = TextRange(
|
||||
EditorHelper.getLineStartForOffset(editor, textRange.startOffset),
|
||||
EditorHelper.getLineEndForOffset(editor, textRange.endOffset) + 1
|
||||
)
|
||||
Triple(caret, lineRange, SelectionType.LINE_WISE)
|
||||
}
|
||||
}
|
||||
return VimPlugin.getChange().deleteRange(editor, usedCaret, usedRange, usedType, false)
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,21 @@
|
||||
package com.maddyhome.idea.vim.action.change.insert
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
class InsertCompletedDigraphAction : VimActionHandler.SingleExecution() {
|
||||
override val type: Command.Type = Command.Type.INSERT
|
||||
override val argumentType: Argument.Type? = Argument.Type.DIGRAPH
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean {
|
||||
// The converted digraph character has been captured as an argument, push it back through key handler
|
||||
val keyStroke = KeyStroke.getKeyStroke(cmd.argument!!.character)
|
||||
KeyHandler.getInstance().handleKey(editor, keyStroke, context)
|
||||
return true
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package com.maddyhome.idea.vim.action.change.insert
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
class InsertCompletedLiteralAction : VimActionHandler.SingleExecution() {
|
||||
override val type: Command.Type = Command.Type.INSERT
|
||||
override val argumentType: Argument.Type? = Argument.Type.DIGRAPH
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean {
|
||||
// The converted literal character has been captured as an argument, push it back through key handler
|
||||
val keyStroke = KeyStroke.getKeyStroke(cmd.argument!!.character)
|
||||
KeyHandler.getInstance().handleKey(editor, keyStroke, context)
|
||||
return true
|
||||
}
|
||||
}
|
@@ -29,9 +29,9 @@ import javax.swing.KeyStroke
|
||||
|
||||
class InsertPreviousInsertExitAction : ChangeEditorActionHandler.SingleExecution(), ComplicatedKeysAction {
|
||||
override val keyStrokesSet: Set<List<KeyStroke>> = setOf(
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_2, KeyEvent.CTRL_MASK or KeyEvent.SHIFT_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_2, KeyEvent.CTRL_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_AT, KeyEvent.CTRL_MASK))
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_2, KeyEvent.CTRL_DOWN_MASK or KeyEvent.SHIFT_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_2, KeyEvent.CTRL_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_AT, KeyEvent.CTRL_DOWN_MASK))
|
||||
)
|
||||
|
||||
override val type: Command.Type = Command.Type.INSERT
|
||||
|
@@ -1,16 +0,0 @@
|
||||
package com.maddyhome.idea.vim.action.change.insert
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
|
||||
class StartInsertDigraphAction : VimActionHandler.SingleExecution() {
|
||||
override val type: Command.Type = Command.Type.INSERT
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean {
|
||||
KeyHandler.getInstance().startDigraphSequence(editor)
|
||||
return true
|
||||
}
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
package com.maddyhome.idea.vim.action.change.insert
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
|
||||
class StartInsertLiteralAction : VimActionHandler.SingleExecution() {
|
||||
override val type: Command.Type = Command.Type.INSERT
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean {
|
||||
KeyHandler.getInstance().startLiteralSequence(editor)
|
||||
return true
|
||||
}
|
||||
}
|
@@ -26,17 +26,27 @@ import com.maddyhome.idea.vim.group.copy.PutData
|
||||
import com.maddyhome.idea.vim.group.copy.PutData.TextData
|
||||
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
|
||||
|
||||
class PutTextAfterCursorAction : ChangeEditorActionHandler.SingleExecution() {
|
||||
sealed class PutTextBaseAction(
|
||||
private val insertTextBeforeCaret: Boolean,
|
||||
private val indent: Boolean,
|
||||
private val caretAfterInsertedText: Boolean
|
||||
) : ChangeEditorActionHandler.SingleExecution() {
|
||||
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
||||
|
||||
override fun execute(editor: Editor,
|
||||
context: DataContext,
|
||||
count: Int,
|
||||
rawCount: Int,
|
||||
argument: Argument?): Boolean {
|
||||
override fun execute(editor: Editor, context: DataContext, count: Int, rawCount: Int, argument: Argument?): Boolean {
|
||||
val lastRegister = VimPlugin.getRegister().lastRegister
|
||||
val textData = if (lastRegister != null) TextData(lastRegister.text, lastRegister.type, lastRegister.transferableData) else null
|
||||
val putData = PutData(textData, null, count, insertTextBeforeCaret = false, _indent = true, caretAfterInsertedText = false, putToLine = -1)
|
||||
val putData = PutData(textData, null, count, insertTextBeforeCaret, indent, caretAfterInsertedText, -1)
|
||||
return VimPlugin.getPut().putText(editor, context, putData)
|
||||
}
|
||||
}
|
||||
|
||||
class PutTextAfterCursorAction : PutTextBaseAction(insertTextBeforeCaret = false, indent = true, caretAfterInsertedText = false)
|
||||
class PutTextAfterCursorActionMoveCursor : PutTextBaseAction(insertTextBeforeCaret = false, indent = true, caretAfterInsertedText = true)
|
||||
|
||||
class PutTextAfterCursorNoIndentAction : PutTextBaseAction(insertTextBeforeCaret = false, indent = false, caretAfterInsertedText = false)
|
||||
class PutTextBeforeCursorNoIndentAction : PutTextBaseAction(insertTextBeforeCaret = true, indent = false, caretAfterInsertedText = false)
|
||||
|
||||
class PutTextBeforeCursorAction : PutTextBaseAction(insertTextBeforeCaret = true, indent = true, caretAfterInsertedText = false)
|
||||
class PutTextBeforeCursorActionMoveCursor : PutTextBaseAction(insertTextBeforeCaret = true, indent = true, caretAfterInsertedText = true)
|
||||
|
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.maddyhome.idea.vim.action.copy
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.group.copy.PutData
|
||||
import com.maddyhome.idea.vim.group.copy.PutData.TextData
|
||||
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
|
||||
|
||||
class PutTextAfterCursorActionMoveCursor : ChangeEditorActionHandler.SingleExecution() {
|
||||
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
||||
|
||||
override fun execute(editor: Editor,
|
||||
context: DataContext,
|
||||
count: Int,
|
||||
rawCount: Int,
|
||||
argument: Argument?): Boolean {
|
||||
val lastRegister = VimPlugin.getRegister().lastRegister
|
||||
val textData = if (lastRegister != null) TextData(lastRegister.text, lastRegister.type, lastRegister.transferableData) else null
|
||||
val putData = PutData(textData, null, count, false, _indent = true, caretAfterInsertedText = true, putToLine = -1)
|
||||
return VimPlugin.getPut().putText(editor, context, putData)
|
||||
}
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.maddyhome.idea.vim.action.copy
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.group.copy.PutData
|
||||
import com.maddyhome.idea.vim.group.copy.PutData.TextData
|
||||
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
|
||||
|
||||
class PutTextAfterCursorNoIndentAction : ChangeEditorActionHandler.SingleExecution() {
|
||||
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
||||
|
||||
override fun execute(editor: Editor,
|
||||
context: DataContext,
|
||||
count: Int,
|
||||
rawCount: Int,
|
||||
argument: Argument?): Boolean {
|
||||
val lastRegister = VimPlugin.getRegister().lastRegister
|
||||
val textData = if (lastRegister != null) TextData(lastRegister.text, lastRegister.type, lastRegister.transferableData) else null
|
||||
val putData = PutData(textData, null, count, insertTextBeforeCaret = false, _indent = false, caretAfterInsertedText = false, putToLine = -1)
|
||||
return VimPlugin.getPut().putText(editor, context, putData)
|
||||
}
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.maddyhome.idea.vim.action.copy
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.group.copy.PutData
|
||||
import com.maddyhome.idea.vim.group.copy.PutData.TextData
|
||||
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
|
||||
|
||||
class PutTextBeforeCursorAction : ChangeEditorActionHandler.SingleExecution() {
|
||||
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
||||
|
||||
override fun execute(editor: Editor,
|
||||
context: DataContext,
|
||||
count: Int,
|
||||
rawCount: Int,
|
||||
argument: Argument?): Boolean {
|
||||
val lastRegister = VimPlugin.getRegister().lastRegister
|
||||
val textData = if (lastRegister != null) TextData(lastRegister.text, lastRegister.type, lastRegister.transferableData) else null
|
||||
val putData = PutData(textData, null, count, insertTextBeforeCaret = true, _indent = true, caretAfterInsertedText = false, putToLine = -1)
|
||||
return VimPlugin.getPut().putText(editor, context, putData)
|
||||
}
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.maddyhome.idea.vim.action.copy
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.group.copy.PutData
|
||||
import com.maddyhome.idea.vim.group.copy.PutData.TextData
|
||||
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
|
||||
|
||||
class PutTextBeforeCursorActionMoveCursor : ChangeEditorActionHandler.SingleExecution() {
|
||||
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
||||
|
||||
override fun execute(editor: Editor,
|
||||
context: DataContext,
|
||||
count: Int,
|
||||
rawCount: Int,
|
||||
argument: Argument?): Boolean {
|
||||
val lastRegister = VimPlugin.getRegister().lastRegister
|
||||
val textData = if (lastRegister != null) TextData(lastRegister.text, lastRegister.type, lastRegister.transferableData) else null
|
||||
val putData = PutData(textData, null, count, insertTextBeforeCaret = true, _indent = true, caretAfterInsertedText = true, putToLine = -1)
|
||||
return VimPlugin.getPut().putText(editor, context, putData)
|
||||
}
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.maddyhome.idea.vim.action.copy
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.group.copy.PutData
|
||||
import com.maddyhome.idea.vim.group.copy.PutData.TextData
|
||||
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
|
||||
|
||||
class PutTextBeforeCursorNoIndentAction : ChangeEditorActionHandler.SingleExecution() {
|
||||
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
||||
|
||||
override fun execute(editor: Editor,
|
||||
context: DataContext,
|
||||
count: Int,
|
||||
rawCount: Int,
|
||||
argument: Argument?): Boolean {
|
||||
val lastRegister = VimPlugin.getRegister().lastRegister
|
||||
val textData = if (lastRegister != null) TextData(lastRegister.text, lastRegister.type, lastRegister.transferableData) else null
|
||||
val putData = PutData(textData, null, count, insertTextBeforeCaret = true, _indent = false, caretAfterInsertedText = false, putToLine = -1)
|
||||
return VimPlugin.getPut().putText(editor, context, putData)
|
||||
}
|
||||
}
|
@@ -33,23 +33,33 @@ import java.util.*
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
class PutVisualTextAction : VisualOperatorActionHandler.SingleExecution() {
|
||||
sealed class PutVisualTextBaseAction(
|
||||
private val insertTextBeforeCaret: Boolean,
|
||||
private val indent: Boolean,
|
||||
private val caretAfterInsertedText: Boolean
|
||||
) : VisualOperatorActionHandler.SingleExecution() {
|
||||
|
||||
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_EXIT_VISUAL)
|
||||
override fun executeForAllCarets(editor: Editor,
|
||||
context: DataContext,
|
||||
cmd: Command,
|
||||
caretsAndSelections: Map<Caret, VimSelection>): Boolean {
|
||||
|
||||
override fun executeForAllCarets(editor: Editor, context: DataContext, cmd: Command, caretsAndSelections: Map<Caret, VimSelection>): Boolean {
|
||||
if (caretsAndSelections.isEmpty()) return false
|
||||
val textData = VimPlugin.getRegister().lastRegister?.let { PutData.TextData(it.text, it.type, it.transferableData) }
|
||||
VimPlugin.getRegister().resetRegister()
|
||||
|
||||
val insertTextBeforeCaret = cmd.keys[0].keyChar == 'P'
|
||||
val selection = PutData.VisualSelection(caretsAndSelections, caretsAndSelections.values.first().type)
|
||||
val putData = PutData(textData, selection, cmd.count, insertTextBeforeCaret, _indent = true, caretAfterInsertedText = false)
|
||||
val putData = PutData(textData, selection, cmd.count, insertTextBeforeCaret, indent, caretAfterInsertedText)
|
||||
|
||||
return VimPlugin.getPut().putText(editor, context, putData)
|
||||
}
|
||||
}
|
||||
|
||||
class PutVisualTextBeforeCursorAction: PutVisualTextBaseAction(insertTextBeforeCaret = true, indent = true, caretAfterInsertedText = false)
|
||||
class PutVisualTextAfterCursorAction: PutVisualTextBaseAction(insertTextBeforeCaret = false, indent = true, caretAfterInsertedText = false)
|
||||
|
||||
class PutVisualTextBeforeCursorNoIndentAction: PutVisualTextBaseAction(insertTextBeforeCaret = true, indent = false, caretAfterInsertedText = false)
|
||||
class PutVisualTextAfterCursorNoIndentAction: PutVisualTextBaseAction(insertTextBeforeCaret = false, indent = false, caretAfterInsertedText = false)
|
||||
|
||||
class PutVisualTextBeforeCursorMoveCursorAction: PutVisualTextBaseAction(insertTextBeforeCaret = true, indent = true, caretAfterInsertedText = true)
|
||||
class PutVisualTextAfterCursorMoveCursorAction: PutVisualTextBaseAction(insertTextBeforeCaret = false, indent = true, caretAfterInsertedText = true)
|
||||
|
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim.action.copy
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.group.copy.PutData
|
||||
import com.maddyhome.idea.vim.group.visual.VimSelection
|
||||
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
class PutVisualTextMoveCursorAction : VisualOperatorActionHandler.SingleExecution() {
|
||||
|
||||
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_EXIT_VISUAL)
|
||||
|
||||
override fun executeForAllCarets(editor: Editor, context: DataContext, cmd: Command, caretsAndSelections: Map<Caret, VimSelection>): Boolean {
|
||||
if (caretsAndSelections.isEmpty()) return false
|
||||
val textData = VimPlugin.getRegister().lastRegister?.let { PutData.TextData(it.text, it.type, it.transferableData) }
|
||||
VimPlugin.getRegister().resetRegister()
|
||||
|
||||
val insertTextBeforeCaret = cmd.keys[1].keyChar == 'P'
|
||||
val selection = PutData.VisualSelection(caretsAndSelections, caretsAndSelections.values.first().type)
|
||||
val putData = PutData(textData, selection, cmd.count, insertTextBeforeCaret, _indent = true, caretAfterInsertedText = true)
|
||||
|
||||
return VimPlugin.getPut().putText(editor, context, putData)
|
||||
}
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim.action.copy
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.group.copy.PutData
|
||||
import com.maddyhome.idea.vim.group.visual.VimSelection
|
||||
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
class PutVisualTextNoIndentAction : VisualOperatorActionHandler.SingleExecution() {
|
||||
|
||||
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_EXIT_VISUAL)
|
||||
|
||||
override fun executeForAllCarets(editor: Editor, context: DataContext, cmd: Command, caretsAndSelections: Map<Caret, VimSelection>): Boolean {
|
||||
if (caretsAndSelections.isEmpty()) return false
|
||||
val textData = VimPlugin.getRegister().lastRegister?.let { PutData.TextData(it.text, it.type, it.transferableData) }
|
||||
VimPlugin.getRegister().resetRegister()
|
||||
|
||||
val insertBeforeCaret = cmd.keys[1].keyChar == 'P'
|
||||
val selection = PutData.VisualSelection(caretsAndSelections, caretsAndSelections.values.first().type)
|
||||
val putData = PutData(textData, selection, cmd.count, insertBeforeCaret, _indent = false, caretAfterInsertedText = false)
|
||||
|
||||
return VimPlugin.getPut().putText(editor, context, putData)
|
||||
}
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.maddyhome.idea.vim.action.copy
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import java.util.*
|
||||
|
||||
class SelectRegisterAction : VimActionHandler.SingleExecution() {
|
||||
override val type: Command.Type = Command.Type.SELECT_REGISTER
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_EXPECT_MORE)
|
||||
|
||||
override val argumentType: Argument.Type = Argument.Type.CHARACTER
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean {
|
||||
val argument = cmd.argument
|
||||
return argument != null && VimPlugin.getRegister().selectRegister(argument.character)
|
||||
}
|
||||
}
|
@@ -34,7 +34,7 @@ class VimEditorBackSpace : VimActionHandler.SingleExecution(), ComplicatedKeysAc
|
||||
private val actionName: String = "EditorBackSpace"
|
||||
|
||||
override val keyStrokesSet: Set<List<KeyStroke>> = setOf(
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.CTRL_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.CTRL_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0))
|
||||
)
|
||||
|
||||
@@ -85,7 +85,7 @@ class VimEditorTab : VimActionHandler.SingleExecution(), ComplicatedKeysAction {
|
||||
private val actionName: String = "EditorTab"
|
||||
|
||||
override val keyStrokesSet: Set<List<KeyStroke>> = setOf(
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.CTRL_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.CTRL_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0))
|
||||
)
|
||||
|
||||
|
@@ -28,8 +28,8 @@ import javax.swing.KeyStroke
|
||||
|
||||
class FilePreviousAction : VimActionHandler.SingleExecution(), ComplicatedKeysAction {
|
||||
override val keyStrokesSet: Set<List<KeyStroke>> = setOf(
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_6, KeyEvent.CTRL_MASK or KeyEvent.SHIFT_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_CIRCUMFLEX, KeyEvent.CTRL_MASK))
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_6, KeyEvent.CTRL_DOWN_MASK or KeyEvent.SHIFT_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_CIRCUMFLEX, KeyEvent.CTRL_DOWN_MASK))
|
||||
)
|
||||
|
||||
override val type: Command.Type = Command.Type.OTHER_READONLY
|
||||
|
@@ -44,10 +44,10 @@ class MotionScrollPageDownInsertModeAction : VimActionHandler.SingleExecution(),
|
||||
|
||||
override val keyStrokesSet: Set<List<KeyStroke>> = setOf(
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.CTRL_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_DOWN, KeyEvent.CTRL_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.SHIFT_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_DOWN, KeyEvent.SHIFT_MASK))
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.CTRL_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_DOWN, KeyEvent.CTRL_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_DOWN, KeyEvent.SHIFT_DOWN_MASK))
|
||||
)
|
||||
|
||||
override val type: Command.Type = Command.Type.OTHER_READONLY
|
||||
|
@@ -44,10 +44,10 @@ class MotionScrollPageUpInsertModeAction : VimActionHandler.SingleExecution(), C
|
||||
|
||||
override val keyStrokesSet: Set<List<KeyStroke>> = setOf(
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.CTRL_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_UP, KeyEvent.CTRL_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.SHIFT_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_UP, KeyEvent.SHIFT_MASK))
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.CTRL_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_UP, KeyEvent.CTRL_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.SHIFT_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_UP, KeyEvent.SHIFT_DOWN_MASK))
|
||||
)
|
||||
|
||||
override val type: Command.Type = Command.Type.OTHER_READONLY
|
||||
|
@@ -50,10 +50,10 @@ class MotionWordLeftInsertAction : MotionActionHandler.ForEachCaret(), Complicat
|
||||
override val motionType: MotionType = MotionType.EXCLUSIVE
|
||||
|
||||
override val keyStrokesSet: Set<List<KeyStroke>> = setOf(
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.CTRL_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_LEFT, KeyEvent.CTRL_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.SHIFT_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_LEFT, KeyEvent.SHIFT_MASK))
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.CTRL_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_LEFT, KeyEvent.CTRL_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.SHIFT_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_LEFT, KeyEvent.SHIFT_DOWN_MASK))
|
||||
)
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_SAVE_STROKE)
|
||||
|
@@ -50,10 +50,10 @@ class MotionWordRightInsertAction : MotionActionHandler.ForEachCaret(), Complica
|
||||
override val motionType: MotionType = MotionType.EXCLUSIVE
|
||||
|
||||
override val keyStrokesSet: Set<List<KeyStroke>> = setOf(
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.CTRL_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_RIGHT, KeyEvent.CTRL_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.SHIFT_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_RIGHT, KeyEvent.SHIFT_MASK))
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.CTRL_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_RIGHT, KeyEvent.CTRL_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.SHIFT_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_RIGHT, KeyEvent.SHIFT_DOWN_MASK))
|
||||
)
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_SAVE_STROKE)
|
||||
|
@@ -50,6 +50,6 @@ class Argument private constructor(
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean = true
|
||||
|
||||
override val type: Command.Type = Command.Type.UNDEFINED
|
||||
}, Command.Type.UNDEFINED, EnumSet.noneOf(CommandFlags::class.java), emptyList())
|
||||
}, Command.Type.UNDEFINED, EnumSet.noneOf(CommandFlags::class.java))
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,6 @@ package com.maddyhome.idea.vim.command
|
||||
|
||||
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase
|
||||
import java.util.*
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
/**
|
||||
* This represents a single Vim command to be executed (operator, motion, text object, etc.). It may optionally include
|
||||
@@ -28,14 +27,17 @@ import javax.swing.KeyStroke
|
||||
*/
|
||||
data class Command(
|
||||
var rawCount: Int,
|
||||
var action: EditorActionHandlerBase,
|
||||
var action: EditorActionHandlerBase?,
|
||||
val type: Type,
|
||||
var flags: EnumSet<CommandFlags>,
|
||||
var keys: List<KeyStroke>
|
||||
var flags: EnumSet<CommandFlags>
|
||||
) {
|
||||
|
||||
constructor(rawCount: Int, register: Char): this(rawCount, null, Type.SELECT_REGISTER, EnumSet.of(CommandFlags.FLAG_EXPECT_MORE)) {
|
||||
this.register = register
|
||||
}
|
||||
|
||||
init {
|
||||
action.process(this)
|
||||
action?.process(this)
|
||||
}
|
||||
|
||||
var count: Int
|
||||
@@ -45,6 +47,7 @@ data class Command(
|
||||
}
|
||||
|
||||
var argument: Argument? = null
|
||||
var register: Char? = null
|
||||
|
||||
enum class Type {
|
||||
/**
|
||||
@@ -72,12 +75,12 @@ data class Command(
|
||||
*/
|
||||
COPY,
|
||||
PASTE,
|
||||
// TODO REMOVE?
|
||||
RESET,
|
||||
/**
|
||||
* Represents commands that select the register.
|
||||
*/
|
||||
SELECT_REGISTER,
|
||||
// TODO REMOVE?
|
||||
RESET,
|
||||
OTHER_READONLY,
|
||||
OTHER_WRITABLE,
|
||||
/**
|
||||
@@ -88,7 +91,7 @@ data class Command(
|
||||
|
||||
val isRead: Boolean
|
||||
get() = when (this) {
|
||||
MOTION, COPY, SELECT_REGISTER, OTHER_READONLY, COMPLETION -> true
|
||||
MOTION, COPY, OTHER_READONLY, COMPLETION -> true
|
||||
else -> false
|
||||
}
|
||||
|
||||
|
@@ -9,12 +9,13 @@ import java.util.*
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
class CommandBuilder(private var currentCommandPartNode: CommandPartNode) {
|
||||
private val commandParts = Stack<Command>()
|
||||
private var keys = mutableListOf<KeyStroke>()
|
||||
private val commandParts = ArrayDeque<Command>()
|
||||
private var keyList = mutableListOf<KeyStroke>()
|
||||
|
||||
var commandState = CurrentCommandState.NEW_COMMAND
|
||||
var count = 0
|
||||
private set
|
||||
val keys: Iterable<KeyStroke> get() = keyList
|
||||
|
||||
// The argument type for the current command part's action. Kept separate to handle digraphs and characters. We first
|
||||
// try to accept a digraph. If we get it, set expected argument type to character and handle the converted key. If we
|
||||
@@ -24,7 +25,7 @@ class CommandBuilder(private var currentCommandPartNode: CommandPartNode) {
|
||||
|
||||
val isReady get() = commandState == CurrentCommandState.READY
|
||||
val isBad get() = commandState == CurrentCommandState.BAD_COMMAND
|
||||
val isEmpty get() = commandParts.empty()
|
||||
val isEmpty get() = commandParts.isEmpty()
|
||||
val isAtDefaultState get() = isEmpty && count == 0 && expectedArgumentType == null
|
||||
|
||||
val isExpectingCount: Boolean
|
||||
@@ -35,14 +36,23 @@ class CommandBuilder(private var currentCommandPartNode: CommandPartNode) {
|
||||
}
|
||||
|
||||
fun pushCommandPart(action: EditorActionHandlerBase) {
|
||||
commandParts.push(Command(count, action, action.type, action.flags, keys))
|
||||
commandParts.add(Command(count, action, action.type, action.flags))
|
||||
expectedArgumentType = action.argumentType
|
||||
keys = mutableListOf()
|
||||
count = 0
|
||||
}
|
||||
|
||||
fun popCommandPart() {
|
||||
commandParts.pop()
|
||||
expectedArgumentType = if (commandParts.size > 0) commandParts.peek().action.argumentType else null
|
||||
fun pushCommandPart(register: Char) {
|
||||
// We will never execute this command, but we need to push something to correctly handle counts on either side of a
|
||||
// select register command part. e.g. 2"a2d2w or even crazier 2"a2"a2"a2"a2"a2d2w
|
||||
commandParts.add(Command(count, register))
|
||||
expectedArgumentType = null
|
||||
count = 0
|
||||
}
|
||||
|
||||
fun popCommandPart(): Command {
|
||||
val command = commandParts.removeLast()
|
||||
expectedArgumentType = if (commandParts.size > 0) commandParts.peekLast().action?.argumentType else null
|
||||
return command
|
||||
}
|
||||
|
||||
fun fallbackToCharacterArgument() {
|
||||
@@ -52,16 +62,24 @@ class CommandBuilder(private var currentCommandPartNode: CommandPartNode) {
|
||||
expectedArgumentType = Argument.Type.CHARACTER
|
||||
}
|
||||
|
||||
fun addKey(keyStroke: KeyStroke) {
|
||||
keys.add(keyStroke)
|
||||
fun addKey(key: KeyStroke) {
|
||||
keyList.add(key)
|
||||
}
|
||||
|
||||
fun addCountCharacter(chKey: Char) {
|
||||
count = (count * 10) + (chKey - '0')
|
||||
fun addCountCharacter(key: KeyStroke) {
|
||||
count = (count * 10) + (key.keyChar - '0')
|
||||
// If count overflows and flips negative, reset to 999999999L. In Vim, count is a long, which is *usually* 32 bits,
|
||||
// so will flip at 2147483648. We store count as an Int, which is also 32 bit.
|
||||
// See https://github.com/vim/vim/blob/b376ace1aeaa7614debc725487d75c8f756dd773/src/normal.c#L631
|
||||
if (count < 0) {
|
||||
count = 999999999
|
||||
}
|
||||
addKey(key)
|
||||
}
|
||||
|
||||
fun deleteCountCharacter() {
|
||||
count /= 10
|
||||
keyList.removeAt(keyList.size - 1)
|
||||
}
|
||||
|
||||
fun setCurrentCommandPartNode(newNode: CommandPartNode) {
|
||||
@@ -74,7 +92,7 @@ class CommandBuilder(private var currentCommandPartNode: CommandPartNode) {
|
||||
|
||||
fun isAwaitingCharOrDigraphArgument(): Boolean {
|
||||
if (commandParts.size == 0) return false
|
||||
val argumentType = commandParts.peek().action.argumentType
|
||||
val argumentType = commandParts.peekLast().action?.argumentType
|
||||
return argumentType == Argument.Type.CHARACTER || argumentType == Argument.Type.DIGRAPH
|
||||
}
|
||||
|
||||
@@ -88,12 +106,12 @@ class CommandBuilder(private var currentCommandPartNode: CommandPartNode) {
|
||||
}
|
||||
|
||||
fun completeCommandPart(argument: Argument) {
|
||||
commandParts.peek().argument = argument
|
||||
commandParts.peekLast().argument = argument
|
||||
commandState = CurrentCommandState.READY
|
||||
}
|
||||
|
||||
fun isDuplicateOperatorKeyStroke(key: KeyStroke): Boolean {
|
||||
val action = commandParts.peek()?.action as? DuplicableOperatorAction
|
||||
val action = commandParts.peekLast()?.action as? DuplicableOperatorAction
|
||||
return action?.duplicateWith == key.keyChar
|
||||
}
|
||||
|
||||
@@ -102,27 +120,23 @@ class CommandBuilder(private var currentCommandPartNode: CommandPartNode) {
|
||||
}
|
||||
|
||||
fun buildCommand(): Command {
|
||||
/* Let's go through the command stack and merge it all into one command. At this time there should never
|
||||
be more than two commands on the stack - one is the actual command, and the other would be a motion
|
||||
command argument needed by the first command */
|
||||
var command: Command = commandParts.pop()
|
||||
while (commandParts.size > 0) {
|
||||
val top: Command = commandParts.pop()
|
||||
top.argument = Argument(command)
|
||||
command = top
|
||||
}
|
||||
return fixCommandCounts(command)
|
||||
}
|
||||
|
||||
private fun fixCommandCounts(command: Command): Command {
|
||||
// If we have a command with a motion command argument, both could have their own counts. We need to adjust the
|
||||
// counts, so the motion gets the product of both counts, and the count associated with the command gets reset.
|
||||
// E.g. 3c2w (change 2 words, three times) becomes c6w (change 6 words)
|
||||
if (command.argument?.type === Argument.Type.MOTION) {
|
||||
val motion = command.argument!!.motion
|
||||
motion.count = if (command.rawCount == 0 && motion.rawCount == 0) 0 else command.count * motion.count
|
||||
var command: Command = commandParts.removeFirst()
|
||||
while (commandParts.size > 0) {
|
||||
val next = commandParts.removeFirst()
|
||||
next.count = if (command.rawCount == 0 && next.rawCount == 0) 0 else command.count * next.count
|
||||
command.count = 0
|
||||
if (command.type == Command.Type.SELECT_REGISTER) {
|
||||
next.register = command.register
|
||||
command.register = null
|
||||
command = next
|
||||
}
|
||||
else {
|
||||
command.argument = Argument(next)
|
||||
assert(commandParts.size == 0)
|
||||
}
|
||||
}
|
||||
expectedArgumentType = null
|
||||
return command
|
||||
}
|
||||
|
||||
@@ -130,11 +144,11 @@ class CommandBuilder(private var currentCommandPartNode: CommandPartNode) {
|
||||
resetInProgressCommandPart(commandPartNode)
|
||||
commandState = CurrentCommandState.NEW_COMMAND
|
||||
commandParts.clear()
|
||||
keyList.clear()
|
||||
expectedArgumentType = null
|
||||
}
|
||||
|
||||
fun resetInProgressCommandPart(commandPartNode: CommandPartNode) {
|
||||
keys.clear()
|
||||
count = 0
|
||||
setCurrentCommandPartNode(commandPartNode)
|
||||
}
|
||||
|
@@ -60,15 +60,14 @@ public class CommandState {
|
||||
*
|
||||
* This field is reset after the command has been executed.
|
||||
*/
|
||||
@Nullable private Command executingCommand;
|
||||
private @Nullable Command executingCommand;
|
||||
|
||||
private CommandState() {
|
||||
pushModes(defaultModeState.getMode(), defaultModeState.getSubMode());
|
||||
}
|
||||
|
||||
@Contract("null -> new")
|
||||
@NotNull
|
||||
public static CommandState getInstance(@Nullable Editor editor) {
|
||||
public static @NotNull CommandState getInstance(@Nullable Editor editor) {
|
||||
if (editor == null) {
|
||||
return new CommandState();
|
||||
}
|
||||
@@ -82,13 +81,12 @@ public class CommandState {
|
||||
return res;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static CommandPartNode getKeyRootNode(MappingMode mappingMode) {
|
||||
private static @NotNull CommandPartNode getKeyRootNode(MappingMode mappingMode) {
|
||||
return VimPlugin.getKey().getKeyRoot(mappingMode);
|
||||
}
|
||||
|
||||
// Keep the compatibility with the IdeaVim-EasyMotion plugin before the stable release
|
||||
@ApiStatus.ScheduledForRemoval(inVersion = "0.56")
|
||||
@ApiStatus.ScheduledForRemoval(inVersion = "0.58")
|
||||
@Deprecated
|
||||
public MappingMode getMappingMode() {
|
||||
return mappingState.getMappingMode();
|
||||
@@ -106,13 +104,11 @@ public class CommandState {
|
||||
return commandBuilder;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public MappingState getMappingState() {
|
||||
public @NotNull MappingState getMappingState() {
|
||||
return mappingState;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Command getExecutingCommand() {
|
||||
public @Nullable Command getExecutingCommand() {
|
||||
return executingCommand;
|
||||
}
|
||||
|
||||
@@ -168,6 +164,12 @@ public class CommandState {
|
||||
}
|
||||
}
|
||||
|
||||
public void resetRegisterPending() {
|
||||
if (getSubMode() == SubMode.REGISTER_PENDING) {
|
||||
popModes();
|
||||
}
|
||||
}
|
||||
|
||||
private void resetModes() {
|
||||
modeStates.clear();
|
||||
setMappingMode();
|
||||
@@ -202,13 +204,11 @@ public class CommandState {
|
||||
throw new IllegalArgumentException("Unexpected mode: " + mode);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Mode getMode() {
|
||||
public @NotNull Mode getMode() {
|
||||
return currentModeState().getMode();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public SubMode getSubMode() {
|
||||
public @NotNull SubMode getSubMode() {
|
||||
return currentModeState().getSubMode();
|
||||
}
|
||||
|
||||
@@ -294,8 +294,7 @@ public class CommandState {
|
||||
VimPlugin.showMode(msg.toString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getStatusString(int pos) {
|
||||
private @NotNull String getStatusString(int pos) {
|
||||
ModeState modeState;
|
||||
if (pos >= 0 && pos < modeStates.size()) {
|
||||
modeState = modeStates.get(pos);
|
||||
@@ -350,12 +349,12 @@ public class CommandState {
|
||||
}
|
||||
|
||||
public enum SubMode {
|
||||
NONE, SINGLE_COMMAND, OP_PENDING, VISUAL_CHARACTER, VISUAL_LINE, VISUAL_BLOCK
|
||||
NONE, SINGLE_COMMAND, OP_PENDING, REGISTER_PENDING, VISUAL_CHARACTER, VISUAL_LINE, VISUAL_BLOCK
|
||||
}
|
||||
|
||||
private static class ModeState {
|
||||
@NotNull private final Mode myMode;
|
||||
@NotNull private final SubMode mySubMode;
|
||||
private final @NotNull Mode myMode;
|
||||
private final @NotNull SubMode mySubMode;
|
||||
|
||||
@Contract(pure = true)
|
||||
public ModeState(@NotNull Mode mode, @NotNull SubMode subMode) {
|
||||
@@ -363,13 +362,11 @@ public class CommandState {
|
||||
this.mySubMode = subMode;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Mode getMode() {
|
||||
public @NotNull Mode getMode() {
|
||||
return myMode;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public SubMode getSubMode() {
|
||||
public @NotNull SubMode getSubMode() {
|
||||
return mySubMode;
|
||||
}
|
||||
|
||||
|
@@ -61,3 +61,7 @@ enum class SelectionType(val value: Int) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val SelectionType.isLine get() = this == SelectionType.LINE_WISE
|
||||
val SelectionType.isChar get() = this == SelectionType.CHARACTER_WISE
|
||||
val SelectionType.isBlock get() = this == SelectionType.BLOCK_WISE
|
||||
|
@@ -59,9 +59,7 @@ class IndentConfig private constructor(indentOptions: IndentOptions) {
|
||||
val indentOptions = if (project != null) {
|
||||
CodeStyle.getIndentOptions(project, editor.document)
|
||||
} else {
|
||||
// [VERSION UPDATE] 191+
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
CodeStyle.getDefaultSettings().indentOptions!!
|
||||
CodeStyle.getDefaultSettings().indentOptions
|
||||
}
|
||||
return IndentConfig(indentOptions)
|
||||
}
|
||||
|
@@ -29,12 +29,14 @@ class Register {
|
||||
val type: SelectionType
|
||||
val keys: MutableList<KeyStroke>
|
||||
val transferableData: MutableList<out TextBlockTransferableData>
|
||||
val rawText: String?
|
||||
|
||||
constructor(name: Char, type: SelectionType, keys: MutableList<KeyStroke>) {
|
||||
this.name = name
|
||||
this.type = type
|
||||
this.keys = keys
|
||||
this.transferableData = mutableListOf()
|
||||
this.rawText = text
|
||||
}
|
||||
|
||||
constructor(name: Char, type: SelectionType, text: String, transferableData: MutableList<out TextBlockTransferableData>) {
|
||||
@@ -42,6 +44,15 @@ class Register {
|
||||
this.type = type
|
||||
this.keys = StringHelper.stringToKeys(text)
|
||||
this.transferableData = transferableData
|
||||
this.rawText = text
|
||||
}
|
||||
|
||||
constructor(name: Char, type: SelectionType, text: String, transferableData: MutableList<out TextBlockTransferableData>, rawText: String) {
|
||||
this.name = name
|
||||
this.type = type
|
||||
this.keys = StringHelper.stringToKeys(text)
|
||||
this.transferableData = transferableData
|
||||
this.rawText = rawText
|
||||
}
|
||||
|
||||
val text: String?
|
||||
|
@@ -59,7 +59,7 @@ public class CommandParser {
|
||||
*
|
||||
* @return The singleton instance
|
||||
*/
|
||||
public synchronized static CommandParser getInstance() {
|
||||
public static synchronized CommandParser getInstance() {
|
||||
return CommandParserHolder.INSTANCE;
|
||||
}
|
||||
|
||||
@@ -67,34 +67,8 @@ public class CommandParser {
|
||||
* Don't let anyone create one of these.
|
||||
*/
|
||||
private CommandParser() {
|
||||
// IdeaVim doesn't support contribution to ex_command_ep extension point, so technically we can skip this update,
|
||||
// but let's support dynamic plugins in a more classic way and reload handlers on every EP change.
|
||||
// TODO: [VERSION UPDATE] since 191 use
|
||||
// ExtensionPoint.addExtensionPointListener(ExtensionPointListener<T>, boolean, Disposable)
|
||||
// TODO: [VERSION UPDATE] since 201 use
|
||||
// ExtensionPoint.addExtensionPointListener(ExtensionPointChangeListener, boolean, Disposable)
|
||||
//noinspection deprecation
|
||||
EX_COMMAND_EP.getPoint(null).addExtensionPointListener(new ExtensionPointListener<ExBeanClass>() {
|
||||
@Override
|
||||
public void extensionAdded(@NotNull ExBeanClass extension, @NotNull PluginDescriptor pluginDescriptor) {
|
||||
// Suppress listener before the `VimPlugin.turnOn()` function execution. This logic should be rewritten after
|
||||
// version update (or earlier).
|
||||
if (!initialRegistration) return;
|
||||
unregisterHandlers();
|
||||
registerHandlers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extensionRemoved(@NotNull ExBeanClass extension, @NotNull PluginDescriptor pluginDescriptor) {
|
||||
if (!initialRegistration) return;
|
||||
unregisterHandlers();
|
||||
registerHandlers();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean initialRegistration = false;
|
||||
|
||||
public void unregisterHandlers() {
|
||||
root.clear();
|
||||
}
|
||||
@@ -104,7 +78,16 @@ public class CommandParser {
|
||||
*/
|
||||
public void registerHandlers() {
|
||||
EX_COMMAND_EP.extensions().forEach(ExBeanClass::register);
|
||||
initialRegistration = true;
|
||||
registerEpListener();
|
||||
}
|
||||
|
||||
private void registerEpListener() {
|
||||
// IdeaVim doesn't support contribution to ex_command_ep extension point, so technically we can skip this update,
|
||||
// but let's support dynamic plugins in a more classic way and reload handlers on every EP change.
|
||||
EX_COMMAND_EP.getPoint(null).addExtensionPointListener(() -> {
|
||||
unregisterHandlers();
|
||||
registerHandlers();
|
||||
}, false, VimPlugin.getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,8 +198,7 @@ public class CommandParser {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CommandHandler getCommandHandler(@NotNull ExCommand command) {
|
||||
public @Nullable CommandHandler getCommandHandler(@NotNull ExCommand command) {
|
||||
final String cmd = command.getCommand();
|
||||
// If there is no command, just a range, use the 'goto line' handler
|
||||
if (cmd.length() == 0) {
|
||||
@@ -241,8 +223,7 @@ public class CommandParser {
|
||||
* @return The parse result
|
||||
* @throws ExException if the text is syntactically incorrect
|
||||
*/
|
||||
@NotNull
|
||||
public ExCommand parse(@NotNull String cmd) throws ExException {
|
||||
public @NotNull ExCommand parse(@NotNull String cmd) throws ExException {
|
||||
// This is a complicated state machine that should probably be rewritten
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("processing `" + cmd + "'");
|
||||
@@ -622,7 +603,7 @@ public class CommandParser {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull private final CommandNode root = new CommandNode();
|
||||
private final @NotNull CommandNode root = new CommandNode();
|
||||
|
||||
private enum State {
|
||||
START,
|
||||
|
@@ -32,9 +32,7 @@ class ExBeanClass : AbstractExtensionPointBean() {
|
||||
var names: String? = null
|
||||
|
||||
val handler: CommandHandler by lazy {
|
||||
// FIXME. [VERSION UPDATE] change to instantiateClass for 193+
|
||||
@Suppress("DEPRECATION")
|
||||
this.instantiate<CommandHandler>(
|
||||
this.instantiateClass<CommandHandler>(
|
||||
implementation ?: "", ApplicationManager.getApplication().picoContainer)
|
||||
}
|
||||
|
||||
|
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
package com.maddyhome.idea.vim.ex
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
@@ -28,33 +27,33 @@ class ExCommand(val ranges: Ranges, val command: String, var argument: String) {
|
||||
|
||||
fun getLine(editor: Editor): Int = ranges.getLine(editor)
|
||||
|
||||
fun getLine(editor: Editor, caret: Caret, context: DataContext): Int = ranges.getLine(editor, caret, context)
|
||||
fun getLine(editor: Editor, caret: Caret): Int = ranges.getLine(editor, caret)
|
||||
|
||||
fun getCount(editor: Editor, context: DataContext?, defaultCount: Int, checkCount: Boolean): Int {
|
||||
fun getCount(editor: Editor, defaultCount: Int, checkCount: Boolean): Int {
|
||||
val count = if (checkCount) countArgument else -1
|
||||
|
||||
val res = ranges.getCount(editor, count)
|
||||
return if (res == -1) defaultCount else res
|
||||
}
|
||||
|
||||
fun getCount(editor: Editor, caret: Caret, context: DataContext, defaultCount: Int, checkCount: Boolean): Int {
|
||||
val count = ranges.getCount(editor, caret, context, if (checkCount) countArgument else -1)
|
||||
fun getCount(editor: Editor, caret: Caret, defaultCount: Int, checkCount: Boolean): Int {
|
||||
val count = ranges.getCount(editor, caret, if (checkCount) countArgument else -1)
|
||||
return if (count == -1) defaultCount else count
|
||||
}
|
||||
|
||||
fun getLineRange(editor: Editor): LineRange = ranges.getLineRange(editor, -1)
|
||||
|
||||
fun getLineRange(editor: Editor, caret: Caret, context: DataContext): LineRange {
|
||||
return ranges.getLineRange(editor, caret, context, -1)
|
||||
fun getLineRange(editor: Editor, caret: Caret): LineRange {
|
||||
return ranges.getLineRange(editor, caret, -1)
|
||||
}
|
||||
|
||||
fun getTextRange(editor: Editor, context: DataContext?, checkCount: Boolean): TextRange {
|
||||
fun getTextRange(editor: Editor, checkCount: Boolean): TextRange {
|
||||
val count = if (checkCount) countArgument else -1
|
||||
return ranges.getTextRange(editor, context, count)
|
||||
return ranges.getTextRange(editor, count)
|
||||
}
|
||||
|
||||
fun getTextRange(editor: Editor, caret: Caret, context: DataContext, checkCount: Boolean): TextRange {
|
||||
return ranges.getTextRange(editor, caret, context, if (checkCount) countArgument else -1)
|
||||
fun getTextRange(editor: Editor, caret: Caret, checkCount: Boolean): TextRange {
|
||||
return ranges.getTextRange(editor, caret, if (checkCount) countArgument else -1)
|
||||
}
|
||||
|
||||
private val countArgument: Int
|
||||
|
95
src/com/maddyhome/idea/vim/ex/handler/BufferHandler.kt
Normal file
95
src/com/maddyhome/idea/vim/ex/handler/BufferHandler.kt
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim.ex.handler
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
|
||||
/**
|
||||
* Handles buffer, buf, bu, b.
|
||||
*
|
||||
* @author John Weigel
|
||||
*/
|
||||
class BufferHandler : CommandHandler.SingleExecution() {
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val arg = cmd.argument.trim()
|
||||
val overrideModified = arg.startsWith('!')
|
||||
val buffer = if (overrideModified) arg.replace(Regex("^!\\s*"), "") else arg
|
||||
var result = true
|
||||
|
||||
if (buffer.isNotEmpty()) {
|
||||
if (buffer.matches(Regex("^\\d+$"))) {
|
||||
val bufNum = buffer.toInt() - 1
|
||||
|
||||
if (!VimPlugin.getFile().selectFile(bufNum, context)) {
|
||||
VimPlugin.showMessage("Buffer $bufNum does not exist")
|
||||
result = false
|
||||
}
|
||||
} else {
|
||||
val editors = findPartialMatch(context, buffer)
|
||||
|
||||
when(editors.size) {
|
||||
0 -> {
|
||||
VimPlugin.showMessage("No matching buffer for $buffer")
|
||||
result = false
|
||||
}
|
||||
1 -> {
|
||||
if (EditorHelper.hasUnsavedChanges(editor) && !overrideModified) {
|
||||
VimPlugin.showMessage("No write since last change (add ! to override)")
|
||||
result = false
|
||||
}
|
||||
else {
|
||||
VimPlugin.getFile().openFile(EditorHelper.getVirtualFile(editors[0])!!.name, context)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
VimPlugin.showMessage("More than one match for $buffer")
|
||||
result = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
private fun findPartialMatch(context: DataContext, fileName: String): List<Editor> {
|
||||
val matchedFiles = mutableListOf<Editor>()
|
||||
val project = PlatformDataKeys.PROJECT.getData(context) ?: return matchedFiles
|
||||
|
||||
for (file in FileEditorManager.getInstance(project).openFiles) {
|
||||
if (file.name.contains(fileName)) {
|
||||
val editor = EditorHelper.getEditor(file) ?: continue
|
||||
matchedFiles.add(editor)
|
||||
}
|
||||
}
|
||||
|
||||
return matchedFiles
|
||||
}
|
||||
}
|
||||
|
148
src/com/maddyhome/idea/vim/ex/handler/BufferListHandler.kt
Normal file
148
src/com/maddyhome/idea/vim/ex/handler/BufferListHandler.kt
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim.ex.handler
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys
|
||||
import com.intellij.openapi.editor.Document
|
||||
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.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Handles buffers, files, ls command. Supports +, =, a, %, # filters.
|
||||
*
|
||||
* @author John Weigel
|
||||
*/
|
||||
class BufferListHandler : CommandHandler.SingleExecution() {
|
||||
override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
companion object {
|
||||
const val FILE_NAME_PAD = 30
|
||||
val SUPPORTED_FILTERS = setOf('+', '=', 'a', '%', '#')
|
||||
}
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val arg = cmd.argument.trim()
|
||||
val filter = pruneUnsupportedFilters(arg)
|
||||
val bufferList = getBufferList(context, filter)
|
||||
|
||||
ExOutputModel.getInstance(editor).output(bufferList.joinToString(separator = "\n"))
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private fun pruneUnsupportedFilters(filter: String) = filter.filter { it in SUPPORTED_FILTERS }
|
||||
|
||||
private fun getBufferList(context: DataContext, filter: String): List<String> {
|
||||
val bufferList = mutableListOf<String>()
|
||||
val project = PlatformDataKeys.PROJECT.getData(context) ?: return emptyList()
|
||||
|
||||
val fem = FileEditorManager.getInstance(project)
|
||||
val openFiles = fem.openFiles
|
||||
val bufNumPad = openFiles.size.toString().length
|
||||
val currentFile = fem.selectedFiles[0]
|
||||
val previousFile = VimPlugin.getFile().getPreviousTab(context)
|
||||
val virtualFileDisplayMap = buildVirtualFileDisplayMap(project)
|
||||
|
||||
var index = 1
|
||||
for ((file, displayFileName) in virtualFileDisplayMap) {
|
||||
val editor = EditorHelper.getEditor(file) ?: continue
|
||||
|
||||
val bufStatus = getBufferStatus(editor, file, currentFile, previousFile)
|
||||
|
||||
if (bufStatusMatchesFilter(filter, bufStatus)) {
|
||||
val lineNum = editor.caretModel.currentCaret.logicalPosition.line + 1
|
||||
val lineNumPad = if (displayFileName.length < FILE_NAME_PAD) (FILE_NAME_PAD - displayFileName.length).toString() else ""
|
||||
|
||||
bufferList.add(String.format(
|
||||
" %${bufNumPad}s %s %s%${lineNumPad}s line: %d", index, bufStatus, displayFileName, "", lineNum)
|
||||
)
|
||||
}
|
||||
index++
|
||||
}
|
||||
|
||||
return bufferList
|
||||
}
|
||||
|
||||
private fun buildVirtualFileDisplayMap(project: Project): Map<VirtualFile, String> {
|
||||
val openFiles = FileEditorManager.getInstance(project).openFiles
|
||||
val basePath = if (project.basePath != null) project.basePath + File.separator else ""
|
||||
val filePaths = mutableMapOf<VirtualFile, String>()
|
||||
|
||||
for (file in openFiles) {
|
||||
val filePath = file.path
|
||||
|
||||
// If the file is under the project path, then remove the project base path from the file.
|
||||
val displayFilePath = if (basePath.isNotEmpty() && filePath.startsWith(basePath)) {
|
||||
filePath.replace(basePath, "")
|
||||
} else {
|
||||
// File is not under the project base path so add the full path.
|
||||
filePath
|
||||
}
|
||||
|
||||
filePaths[file] = '"' + displayFilePath + '"'
|
||||
}
|
||||
|
||||
return filePaths
|
||||
}
|
||||
|
||||
private fun bufStatusMatchesFilter(filter: String, bufStatus: String) = filter.all { it in bufStatus }
|
||||
}
|
||||
|
||||
private fun getBufferStatus(editor: Editor, file: VirtualFile, currentFile: VirtualFile, previousFile: VirtualFile?): String {
|
||||
val bufStatus = StringBuilder()
|
||||
|
||||
when(file) {
|
||||
currentFile -> bufStatus.append("%a ")
|
||||
previousFile -> bufStatus.append("# ")
|
||||
else -> bufStatus.append(" ")
|
||||
}
|
||||
|
||||
if (!file.isWritable) {
|
||||
bufStatus.setCharAt(2, '=')
|
||||
}
|
||||
|
||||
if (isDocumentDirty(editor.document)) {
|
||||
bufStatus.setCharAt(3, '+')
|
||||
}
|
||||
|
||||
return bufStatus.toString()
|
||||
}
|
||||
|
||||
private fun isDocumentDirty(document: Document): Boolean {
|
||||
var line = 0
|
||||
|
||||
while (line < document.lineCount) {
|
||||
if (document.isLineModified(line)) {
|
||||
return true
|
||||
}
|
||||
line++
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
@@ -22,7 +22,11 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
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.flags
|
||||
import com.maddyhome.idea.vim.helper.MessageHelper
|
||||
import com.maddyhome.idea.vim.helper.Msg
|
||||
import java.io.IOException
|
||||
@@ -54,7 +58,7 @@ class CmdFilterHandler : CommandHandler.SingleExecution() {
|
||||
true
|
||||
} else {
|
||||
// Filter
|
||||
val range = cmd.getTextRange(editor, context, false)
|
||||
val range = cmd.getTextRange(editor, false)
|
||||
VimPlugin.getProcess().executeFilter(editor, range, command)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
|
@@ -22,7 +22,10 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.SelectionType
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
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.flags
|
||||
import com.maddyhome.idea.vim.group.copy.PutData
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
|
||||
@@ -31,11 +34,11 @@ class CopyTextHandler : CommandHandler.SingleExecution() {
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val carets = EditorHelper.getOrderedCaretsList(editor)
|
||||
for (caret in carets) {
|
||||
val range = cmd.getTextRange(editor, caret, context, false)
|
||||
val range = cmd.getTextRange(editor, caret, false)
|
||||
val text = EditorHelper.getText(editor, range.startOffset, range.endOffset)
|
||||
|
||||
val arg = CommandParser.getInstance().parse(cmd.argument)
|
||||
val line = arg.ranges.getFirstLine(editor, caret, context)
|
||||
val line = arg.ranges.getFirstLine(editor, caret)
|
||||
|
||||
val transferableData = VimPlugin.getRegister().getTransferableData(editor, range, text)
|
||||
val textData = PutData.TextData(text, SelectionType.LINE_WISE, transferableData)
|
||||
|
@@ -40,7 +40,7 @@ class DeleteLinesHandler : CommandHandler.ForEachCaret() {
|
||||
|
||||
if (!VimPlugin.getRegister().selectRegister(register)) return false
|
||||
|
||||
val textRange = cmd.getTextRange(editor, caret, context, true)
|
||||
val textRange = cmd.getTextRange(editor, caret, true)
|
||||
return VimPlugin.getChange().deleteRange(editor, caret, textRange, SelectionType.LINE_WISE, false)
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
class FileHandler : CommandHandler.SingleExecution() {
|
||||
override val argFlags = flags(RangeFlag.RANGE_IS_COUNT, ARGUMENT_FORBIDDEN, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val count = cmd.getCount(editor, context, 0, false)
|
||||
val count = cmd.getCount(editor, 0, false)
|
||||
VimPlugin.getFile().displayFileInfo(editor, count > 0)
|
||||
return true
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ class GotoCharacterHandler : CommandHandler.ForEachCaret() {
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_IS_COUNT, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
override fun execute(editor: Editor, caret: Caret, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val count = cmd.getCount(editor, caret, context, 1, true)
|
||||
val count = cmd.getCount(editor, caret, 1, true)
|
||||
if (count <= 0) return false
|
||||
|
||||
val offset = VimPlugin.getMotion().moveCaretToNthCharacter(editor, count - 1)
|
||||
|
@@ -47,7 +47,7 @@ class GotoLineHandler : CommandHandler.ForEachCaret() {
|
||||
* @return True if able to perform the command, false if not
|
||||
*/
|
||||
override fun execute(editor: Editor, caret: Caret, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val line = min(cmd.getLine(editor, caret, context), EditorHelper.getLineCount(editor) - 1)
|
||||
val line = min(cmd.getLine(editor, caret), EditorHelper.getLineCount(editor) - 1)
|
||||
|
||||
if (line >= 0) {
|
||||
MotionGroup.moveCaret(editor, caret, VimPlugin.getMotion().moveCaretToLineStartSkipLeading(editor, line))
|
||||
|
@@ -23,7 +23,10 @@ import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandHandlerFlags
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
|
||||
class JoinLinesHandler : CommandHandler.ForEachCaret() {
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.WRITABLE)
|
||||
@@ -32,7 +35,7 @@ class JoinLinesHandler : CommandHandler.ForEachCaret() {
|
||||
val arg = cmd.argument
|
||||
val spaces = arg.isEmpty() || arg[0] != '!'
|
||||
|
||||
val textRange = cmd.getTextRange(editor, caret, context, true) ?: return false
|
||||
val textRange = cmd.getTextRange(editor, caret, true)
|
||||
|
||||
return VimPlugin.getChange().deleteJoinRange(editor, caret, TextRange(textRange.startOffset,
|
||||
textRange.endOffset - 1), spaces)
|
||||
|
@@ -34,6 +34,7 @@ import com.maddyhome.idea.vim.ex.handler.MapHandler.SpecialArgument.EXPR
|
||||
import com.maddyhome.idea.vim.ex.handler.MapHandler.SpecialArgument.SCRIPT
|
||||
import com.maddyhome.idea.vim.ex.vimscript.VimScriptCommandHandler
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import com.maddyhome.idea.vim.key.MappingOwner
|
||||
import java.util.*
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
@@ -75,8 +76,7 @@ class MapHandler : CommandHandler.SingleExecution(), VimScriptCommandHandler, Co
|
||||
throw ExException("Unsupported map argument: $unsupportedArgument")
|
||||
}
|
||||
}
|
||||
VimPlugin.getKey().putKeyMapping(modes, arguments.fromKeys, arguments.toKeys, null,
|
||||
commandInfo.isRecursive)
|
||||
VimPlugin.getKey().putKeyMapping(modes, arguments.fromKeys, MappingOwner.IdeaVim, arguments.toKeys, commandInfo.isRecursive)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@@ -24,7 +24,12 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.SelectionType
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
import com.maddyhome.idea.vim.ex.CommandHandler
|
||||
import com.maddyhome.idea.vim.ex.CommandParser
|
||||
import com.maddyhome.idea.vim.ex.ExCommand
|
||||
import com.maddyhome.idea.vim.ex.ExException
|
||||
import com.maddyhome.idea.vim.ex.InvalidRangeException
|
||||
import com.maddyhome.idea.vim.ex.flags
|
||||
import com.maddyhome.idea.vim.ex.ranges.LineRange
|
||||
import com.maddyhome.idea.vim.group.copy.PutData
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
@@ -48,10 +53,10 @@ class MoveTextHandler : CommandHandler.SingleExecution() {
|
||||
|
||||
var lastRange: TextRange? = null
|
||||
for (caret in carets) {
|
||||
val range = cmd.getTextRange(editor, caret, context, false)
|
||||
val lineRange = cmd.getLineRange(editor, caret, context)
|
||||
val range = cmd.getTextRange(editor, caret, false)
|
||||
val lineRange = cmd.getLineRange(editor, caret)
|
||||
|
||||
line = min(line, normalizeLine(editor, caret, context, command, lineRange))
|
||||
line = min(line, normalizeLine(editor, caret, command, lineRange))
|
||||
texts.add(EditorHelper.getText(editor, range.startOffset, range.endOffset))
|
||||
|
||||
if (lastRange == null || lastRange.startOffset != range.startOffset && lastRange.endOffset != range.endOffset) {
|
||||
@@ -75,9 +80,9 @@ class MoveTextHandler : CommandHandler.SingleExecution() {
|
||||
}
|
||||
|
||||
@Throws
|
||||
private fun normalizeLine(editor: Editor, caret: Caret, context: DataContext,
|
||||
command: ExCommand, lineRange: LineRange): Int {
|
||||
var line = command.ranges.getFirstLine(editor, caret, context)
|
||||
private fun normalizeLine(editor: Editor, caret: Caret, command: ExCommand,
|
||||
lineRange: LineRange): Int {
|
||||
var line = command.ranges.getFirstLine(editor, caret)
|
||||
val adj = lineRange.endLine - lineRange.startLine + 1
|
||||
if (line >= lineRange.endLine)
|
||||
line -= adj
|
||||
|
@@ -29,7 +29,7 @@ class NextFileHandler : CommandHandler.SingleExecution() {
|
||||
override val argFlags = flags(RangeFlag.RANGE_IS_COUNT, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val count = cmd.getCount(editor, context, 1, true)
|
||||
val count = cmd.getCount(editor, 1, true)
|
||||
VimPlugin.getMark().saveJumpLocation(editor)
|
||||
VimPlugin.getFile().selectNextFile(count, context)
|
||||
return true
|
||||
|
@@ -28,7 +28,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
class PreviousFileHandler : CommandHandler.SingleExecution() {
|
||||
override val argFlags = flags(RangeFlag.RANGE_IS_COUNT, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val count = cmd.getCount(editor, context, 1, true)
|
||||
val count = cmd.getCount(editor, 1, true)
|
||||
|
||||
VimPlugin.getMark().saveJumpLocation(editor)
|
||||
VimPlugin.getFile().selectNextFile(-count, context)
|
||||
|
@@ -37,7 +37,7 @@ class RepeatHandler : CommandHandler.ForEachCaret() {
|
||||
if (arg == '@') arg = lastArg
|
||||
lastArg = arg
|
||||
|
||||
val line = cmd.getLine(editor, caret, context)
|
||||
val line = cmd.getLine(editor, caret)
|
||||
MotionGroup.moveCaret(editor, caret, VimPlugin.getMotion().moveCaretToLine(editor, line, editor.caretModel.primaryCaret))
|
||||
|
||||
if (arg == ':') {
|
||||
|
@@ -29,7 +29,7 @@ class SelectFileHandler : CommandHandler.SingleExecution() {
|
||||
override val argFlags = flags(RangeFlag.RANGE_IS_COUNT, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val count = cmd.getCount(editor, context, 0, true)
|
||||
val count = cmd.getCount(editor, 0, true)
|
||||
|
||||
if (count > 0) {
|
||||
val res = VimPlugin.getFile().selectFile(count - 1, context)
|
||||
|
@@ -36,7 +36,7 @@ class ShiftLeftHandler : CommandHandler.ForEachCaret(), ComplicatedNameExCommand
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.WRITABLE)
|
||||
|
||||
override fun execute(editor: Editor, caret: Caret, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val range = cmd.getTextRange(editor, caret, context, true)
|
||||
val range = cmd.getTextRange(editor, caret, true)
|
||||
val endOffsets = range.endOffsets.map { it - 1 }.toIntArray()
|
||||
VimPlugin.getChange().indentRange(editor, caret, context,
|
||||
TextRange(range.startOffsets, endOffsets),
|
||||
|
@@ -36,7 +36,7 @@ class ShiftRightHandler : CommandHandler.ForEachCaret(), ComplicatedNameExComman
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.WRITABLE)
|
||||
|
||||
override fun execute(editor: Editor, caret: Caret, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val range = cmd.getTextRange(editor, caret, context, true)
|
||||
val range = cmd.getTextRange(editor, caret, true)
|
||||
val endOffsets = range.endOffsets.map { it - 1 }.toIntArray()
|
||||
VimPlugin.getChange().indentRange(editor, caret, context,
|
||||
TextRange(range.startOffsets, endOffsets),
|
||||
|
@@ -23,7 +23,10 @@ import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.*
|
||||
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.flags
|
||||
import com.maddyhome.idea.vim.ex.ranges.LineRange
|
||||
import com.maddyhome.idea.vim.helper.inBlockSubMode
|
||||
import java.util.*
|
||||
@@ -46,7 +49,7 @@ class SortHandler : CommandHandler.SingleExecution() {
|
||||
val lineComparator = LineComparator(ignoreCase, number, reverse)
|
||||
if (editor.inBlockSubMode) {
|
||||
val primaryCaret = editor.caretModel.primaryCaret
|
||||
val range = getLineRange(editor, primaryCaret, context, cmd)
|
||||
val range = getLineRange(editor, primaryCaret, cmd)
|
||||
val worked = VimPlugin.getChange().sortRange(editor, range, lineComparator)
|
||||
primaryCaret.moveToOffset(VimPlugin.getMotion().moveCaretToLineStartSkipLeading(editor, range.startLine))
|
||||
return worked
|
||||
@@ -54,7 +57,7 @@ class SortHandler : CommandHandler.SingleExecution() {
|
||||
|
||||
var worked = true
|
||||
for (caret in editor.caretModel.allCarets) {
|
||||
val range = getLineRange(editor, caret, context, cmd)
|
||||
val range = getLineRange(editor, caret, cmd)
|
||||
if (!VimPlugin.getChange().sortRange(editor, range, lineComparator)) {
|
||||
worked = false
|
||||
}
|
||||
@@ -64,8 +67,8 @@ class SortHandler : CommandHandler.SingleExecution() {
|
||||
return worked
|
||||
}
|
||||
|
||||
private fun getLineRange(editor: Editor, caret: Caret, context: DataContext, cmd: ExCommand): LineRange {
|
||||
val range = cmd.getLineRange(editor, caret, context)
|
||||
private fun getLineRange(editor: Editor, caret: Caret, cmd: ExCommand): LineRange {
|
||||
val range = cmd.getLineRange(editor, caret)
|
||||
|
||||
// Something like "30,20sort" gets converted to "20,30sort"
|
||||
val normalizedRange = if (range.endLine < range.startLine) LineRange(range.endLine, range.startLine) else range
|
||||
|
@@ -30,7 +30,7 @@ class SubstituteHandler : CommandHandler.SingleExecution() {
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
var result = true
|
||||
for (caret in editor.caretModel.allCarets) {
|
||||
val lineRange = cmd.getLineRange(editor, caret, context)
|
||||
val lineRange = cmd.getLineRange(editor, caret)
|
||||
if (!VimPlugin.getSearch().searchAndReplace(editor, caret, lineRange, cmd.command, cmd.argument)) {
|
||||
result = false
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
class WriteNextFileHandler : CommandHandler.SingleExecution() {
|
||||
override val argFlags = flags(RangeFlag.RANGE_IS_COUNT, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val count = cmd.getCount(editor, context, 1, true)
|
||||
val count = cmd.getCount(editor, 1, true)
|
||||
|
||||
VimPlugin.getFile().saveFile(context)
|
||||
VimPlugin.getMark().saveJumpLocation(editor)
|
||||
|
@@ -28,7 +28,7 @@ import com.maddyhome.idea.vim.ex.flags
|
||||
class WritePreviousFileHandler : CommandHandler.SingleExecution() {
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
|
||||
val count = cmd.getCount(editor, context, 1, true)
|
||||
val count = cmd.getCount(editor, 1, true)
|
||||
|
||||
VimPlugin.getFile().saveFile(context)
|
||||
VimPlugin.getMark().saveJumpLocation(editor)
|
||||
|
@@ -45,7 +45,7 @@ class YankLinesHandler : CommandHandler.SingleExecution() {
|
||||
val starts = ArrayList<Int>(caretModel.caretCount)
|
||||
val ends = ArrayList<Int>(caretModel.caretCount)
|
||||
for (caret in caretModel.allCarets) {
|
||||
val range = cmd.getTextRange(editor, caret, context, true)
|
||||
val range = cmd.getTextRange(editor, caret, true)
|
||||
starts.add(range.startOffset)
|
||||
ends.add(range.endOffset)
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
package com.maddyhome.idea.vim.ex.ranges
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
@@ -59,13 +58,13 @@ class Ranges {
|
||||
return endLine
|
||||
}
|
||||
|
||||
fun getLine(editor: Editor, caret: Caret, context: DataContext): Int {
|
||||
processRange(editor, caret, context)
|
||||
fun getLine(editor: Editor, caret: Caret): Int {
|
||||
processRange(editor, caret)
|
||||
return endLine
|
||||
}
|
||||
|
||||
fun getFirstLine(editor: Editor, caret: Caret, context: DataContext): Int {
|
||||
processRange(editor, caret, context)
|
||||
fun getFirstLine(editor: Editor, caret: Caret): Int {
|
||||
processRange(editor, caret)
|
||||
return startLine
|
||||
}
|
||||
|
||||
@@ -79,8 +78,8 @@ class Ranges {
|
||||
*/
|
||||
fun getCount(editor: Editor, count: Int): Int = if (count == -1) getLine(editor) else count
|
||||
|
||||
fun getCount(editor: Editor, caret: Caret, context: DataContext, count: Int): Int {
|
||||
return if (count == -1) getLine(editor, caret, context) else count
|
||||
fun getCount(editor: Editor, caret: Caret, count: Int): Int {
|
||||
return if (count == -1) getLine(editor, caret) else count
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,8 +104,8 @@ class Ranges {
|
||||
return LineRange(start, end)
|
||||
}
|
||||
|
||||
fun getLineRange(editor: Editor, caret: Caret, context: DataContext, count: Int): LineRange {
|
||||
processRange(editor, caret, context)
|
||||
fun getLineRange(editor: Editor, caret: Caret, count: Int): LineRange {
|
||||
processRange(editor, caret)
|
||||
return if (count == -1) LineRange(startLine, endLine) else LineRange(endLine, endLine + count - 1)
|
||||
}
|
||||
|
||||
@@ -120,15 +119,15 @@ class Ranges {
|
||||
* @param count The count given at the end of the command or -1 if no such count
|
||||
* @return The text range
|
||||
*/
|
||||
fun getTextRange(editor: Editor, context: DataContext?, count: Int): TextRange {
|
||||
fun getTextRange(editor: Editor, count: Int): TextRange {
|
||||
val lr = getLineRange(editor, count)
|
||||
val start = EditorHelper.getLineStartOffset(editor, lr.startLine)
|
||||
val end = EditorHelper.getLineEndOffset(editor, lr.endLine, true) + 1
|
||||
return TextRange(start, min(end, EditorHelper.getFileSize(editor)))
|
||||
}
|
||||
|
||||
fun getTextRange(editor: Editor, caret: Caret, context: DataContext, count: Int): TextRange {
|
||||
val lineRange = getLineRange(editor, caret, context, count)
|
||||
fun getTextRange(editor: Editor, caret: Caret, count: Int): TextRange {
|
||||
val lineRange = getLineRange(editor, caret, count)
|
||||
val start = EditorHelper.getLineStartOffset(editor, lineRange.startLine)
|
||||
val end = EditorHelper.getLineEndOffset(editor, lineRange.endLine, true) + 1
|
||||
return TextRange(start, min(end, EditorHelper.getFileSize(editor)))
|
||||
@@ -165,7 +164,7 @@ class Ranges {
|
||||
done = true
|
||||
}
|
||||
|
||||
private fun processRange(editor: Editor, caret: Caret, context: DataContext) {
|
||||
private fun processRange(editor: Editor, caret: Caret) {
|
||||
startLine = if (defaultLine == -1) caret.logicalPosition.line else defaultLine
|
||||
endLine = startLine
|
||||
var lastZero = false
|
||||
|
@@ -33,13 +33,11 @@ public class VimScriptGlobalEnvironment {
|
||||
|
||||
private VimScriptGlobalEnvironment() {}
|
||||
|
||||
@NotNull
|
||||
public static VimScriptGlobalEnvironment getInstance() {
|
||||
public static @NotNull VimScriptGlobalEnvironment getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<String, Object> getVariables() {
|
||||
public @NotNull Map<String, Object> getVariables() {
|
||||
return myVariables;
|
||||
}
|
||||
}
|
||||
|
@@ -1,193 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
public class VimScriptParser {
|
||||
public static final String VIMRC_FILE_NAME = "ideavimrc";
|
||||
public static final String[] HOME_VIMRC_PATHS = {"." + VIMRC_FILE_NAME, "_" + VIMRC_FILE_NAME};
|
||||
public static final String XDG_VIMRC_PATH = "ideavim" + File.separator + VIMRC_FILE_NAME;
|
||||
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 static final Pattern DEC_NUMBER = Pattern.compile("(\\d+)");
|
||||
|
||||
private VimScriptParser() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File findIdeaVimRc() {
|
||||
final String homeDirName = System.getProperty("user.home");
|
||||
// Check whether file exists in home dir
|
||||
if (homeDirName != null) {
|
||||
for (String fileName : HOME_VIMRC_PATHS) {
|
||||
final File file = new File(homeDirName, fileName);
|
||||
if (file.exists()) {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check in XDG config directory
|
||||
final String xdgConfigHomeProperty = System.getenv("XDG_CONFIG_HOME");
|
||||
File xdgConfig = null;
|
||||
if (xdgConfigHomeProperty == null || Objects.equals(xdgConfigHomeProperty, "")) {
|
||||
if (homeDirName != null) {
|
||||
xdgConfig = Paths.get(homeDirName, ".config", XDG_VIMRC_PATH).toFile();
|
||||
}
|
||||
} else {
|
||||
xdgConfig = new File(xdgConfigHomeProperty, XDG_VIMRC_PATH);
|
||||
}
|
||||
if (xdgConfig != null && xdgConfig.exists()) {
|
||||
return xdgConfig;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File findOrCreateIdeaVimRc() {
|
||||
final File found = findIdeaVimRc();
|
||||
if (found != null) return found;
|
||||
|
||||
final String homeDirName = System.getProperty("user.home");
|
||||
if (homeDirName != null) {
|
||||
for (String fileName : HOME_VIMRC_PATHS) {
|
||||
try {
|
||||
final File file = new File(homeDirName, fileName);
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.createNewFile();
|
||||
return file;
|
||||
} catch (IOException ignored) {
|
||||
// Try to create one of two files
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void executeFile(@NotNull File file) {
|
||||
final String data;
|
||||
try {
|
||||
data = readFile(file);
|
||||
}
|
||||
catch (IOException ignored) {
|
||||
return;
|
||||
}
|
||||
executeText(data);
|
||||
}
|
||||
|
||||
public static void executeText(@NotNull String text) {
|
||||
for (String line : EOL_SPLIT_PATTERN.split(text)) {
|
||||
// TODO: Build a proper parse tree for a VimL file instead of ignoring potentially nested lines (VIM-669)
|
||||
if (line.startsWith(" ") || line.startsWith("\t")) {
|
||||
continue;
|
||||
}
|
||||
if (line.startsWith(":")) {
|
||||
line = line.substring(1);
|
||||
}
|
||||
final CommandParser commandParser = CommandParser.getInstance();
|
||||
try {
|
||||
final ExCommand command = commandParser.parse(line);
|
||||
final CommandHandler commandHandler = commandParser.getCommandHandler(command);
|
||||
if (commandHandler instanceof VimScriptCommandHandler) {
|
||||
final VimScriptCommandHandler handler = (VimScriptCommandHandler)commandHandler;
|
||||
handler.execute(command);
|
||||
}
|
||||
}
|
||||
catch (ExException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
}
|
||||
m = DEC_NUMBER.matcher(expression);
|
||||
if (m.matches()) {
|
||||
return Integer.parseInt(m.group(1));
|
||||
}
|
||||
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;
|
||||
} else if (value instanceof Integer) {
|
||||
return value.toString();
|
||||
}
|
||||
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));
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
final char[] buffer = new char[BUFSIZE];
|
||||
int n;
|
||||
while ((n = reader.read(buffer)) > 0) {
|
||||
builder.append(buffer, 0, n);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
167
src/com/maddyhome/idea/vim/ex/vimscript/VimScriptParser.kt
Normal file
167
src/com/maddyhome/idea/vim/ex/vimscript/VimScriptParser.kt
Normal file
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.maddyhome.idea.vim.ex.vimscript
|
||||
|
||||
import com.maddyhome.idea.vim.ex.CommandParser
|
||||
import com.maddyhome.idea.vim.ex.ExException
|
||||
import com.maddyhome.idea.vim.ui.VimRcFileState
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.nio.file.Paths
|
||||
import java.util.regex.Matcher
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
object VimScriptParser {
|
||||
const val VIMRC_FILE_NAME = "ideavimrc"
|
||||
val HOME_VIMRC_PATHS = arrayOf(".$VIMRC_FILE_NAME", "_$VIMRC_FILE_NAME")
|
||||
val XDG_VIMRC_PATH = "ideavim" + File.separator + VIMRC_FILE_NAME
|
||||
private val DOUBLE_QUOTED_STRING = Pattern.compile("\"([^\"]*)\"")
|
||||
private val SINGLE_QUOTED_STRING = Pattern.compile("'([^']*)'")
|
||||
private val REFERENCE_EXPR = Pattern.compile("([A-Za-z_][A-Za-z_0-9]*)")
|
||||
private val DEC_NUMBER = Pattern.compile("(\\d+)")
|
||||
|
||||
// This is a pattern used in ideavimrc parsing for a long time. It removes all trailing/leading spaced and blank lines
|
||||
private val EOL_SPLIT_PATTERN = Pattern.compile(" *(\r\n|\n)+ *")
|
||||
|
||||
@JvmStatic
|
||||
fun findIdeaVimRc(): File? {
|
||||
val homeDirName = System.getProperty("user.home")
|
||||
// Check whether file exists in home dir
|
||||
if (homeDirName != null) {
|
||||
for (fileName in HOME_VIMRC_PATHS) {
|
||||
val file = File(homeDirName, fileName)
|
||||
if (file.exists()) {
|
||||
return file
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check in XDG config directory
|
||||
val xdgConfigHomeProperty = System.getenv("XDG_CONFIG_HOME")
|
||||
val xdgConfig = if (xdgConfigHomeProperty == null || xdgConfigHomeProperty == "") {
|
||||
if (homeDirName != null) Paths.get(homeDirName, ".config", XDG_VIMRC_PATH).toFile() else null
|
||||
} else {
|
||||
File(xdgConfigHomeProperty, XDG_VIMRC_PATH)
|
||||
}
|
||||
return if (xdgConfig != null && xdgConfig.exists()) xdgConfig else null
|
||||
}
|
||||
|
||||
fun findOrCreateIdeaVimRc(): File? {
|
||||
val found = findIdeaVimRc()
|
||||
if (found != null) return found
|
||||
|
||||
val homeDirName = System.getProperty("user.home")
|
||||
if (homeDirName != null) {
|
||||
for (fileName in HOME_VIMRC_PATHS) {
|
||||
try {
|
||||
val file = File(homeDirName, fileName)
|
||||
file.createNewFile()
|
||||
VimRcFileState.filePath = file.absolutePath
|
||||
return file
|
||||
} catch (ignored: IOException) {
|
||||
// Try to create one of two files
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun executeFile(file: File): List<String> {
|
||||
val data = try {
|
||||
readFile(file)
|
||||
} catch (ignored: IOException) {
|
||||
return emptyList()
|
||||
}
|
||||
executeText(data)
|
||||
return data
|
||||
}
|
||||
|
||||
fun executeText(text: List<String>) {
|
||||
for (line in text) {
|
||||
// TODO: Build a proper parse tree for a VimL file instead of ignoring potentially nested lines (VIM-669)
|
||||
if (line.startsWith(" ") || line.startsWith("\t")) continue
|
||||
|
||||
val lineToExecute = if (line.startsWith(":")) line.substring(1) else line
|
||||
val commandParser = CommandParser.getInstance()
|
||||
try {
|
||||
val command = commandParser.parse(lineToExecute)
|
||||
val commandHandler = commandParser.getCommandHandler(command)
|
||||
if (commandHandler is VimScriptCommandHandler) {
|
||||
commandHandler.execute(command)
|
||||
}
|
||||
} catch (ignored: ExException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(ExException::class)
|
||||
fun evaluate(expression: String, globals: Map<String?, Any?>): Any {
|
||||
// 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.
|
||||
var m: Matcher = 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()) {
|
||||
val name = m.group(1)
|
||||
val value = globals[name]
|
||||
return value ?: throw ExException("Undefined variable: $name")
|
||||
}
|
||||
|
||||
m = DEC_NUMBER.matcher(expression)
|
||||
if (m.matches()) return m.group(1).toInt()
|
||||
|
||||
throw ExException("Invalid expression: $expression")
|
||||
}
|
||||
|
||||
@Throws(ExException::class)
|
||||
fun expressionToString(value: Any): String {
|
||||
// TODO: Return meaningful value representations
|
||||
return when (value) {
|
||||
is String -> value
|
||||
is Int -> value.toString()
|
||||
else -> throw ExException("Cannot convert '$value' to string")
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun readFile(file: File): List<String> {
|
||||
val lines = ArrayList<String>()
|
||||
file.forEachLine { line -> lineProcessor(line, lines) }
|
||||
return lines
|
||||
}
|
||||
|
||||
fun readText(data: CharSequence): List<String> {
|
||||
val lines = ArrayList<String>()
|
||||
EOL_SPLIT_PATTERN.split(data).forEach { line -> lineProcessor(line, lines) }
|
||||
return lines
|
||||
}
|
||||
|
||||
fun lineProcessor(line: String, lines: ArrayList<String>) {
|
||||
val trimmedLine = line.trim()
|
||||
if (trimmedLine.isBlank()) return
|
||||
lines += trimmedLine
|
||||
}
|
||||
}
|
@@ -19,6 +19,8 @@
|
||||
package com.maddyhome.idea.vim.extension;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.key.MappingOwner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -30,7 +32,13 @@ public interface VimExtension {
|
||||
@NotNull
|
||||
String getName();
|
||||
|
||||
default MappingOwner getOwner() {
|
||||
return MappingOwner.Plugin.Companion.get(getName());
|
||||
}
|
||||
|
||||
void init();
|
||||
|
||||
void dispose();
|
||||
default void dispose() {
|
||||
VimPlugin.getKey().removeKeyMapping(getOwner());
|
||||
};
|
||||
}
|
||||
|
@@ -23,13 +23,16 @@ import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.action.change.VimRepeater
|
||||
import com.maddyhome.idea.vim.command.MappingMode
|
||||
import com.maddyhome.idea.vim.command.SelectionType
|
||||
import com.maddyhome.idea.vim.helper.EditorDataContext
|
||||
import com.maddyhome.idea.vim.helper.StringHelper
|
||||
import com.maddyhome.idea.vim.helper.TestInputModel
|
||||
import com.maddyhome.idea.vim.helper.commandState
|
||||
import com.maddyhome.idea.vim.key.MappingOwner
|
||||
import com.maddyhome.idea.vim.key.OperatorFunction
|
||||
import com.maddyhome.idea.vim.ui.ExEntryPanel
|
||||
import com.maddyhome.idea.vim.ui.ModalEntry
|
||||
import org.jetbrains.annotations.ApiStatus.ScheduledForRemoval
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
@@ -41,18 +44,34 @@ import javax.swing.KeyStroke
|
||||
* @author vlan
|
||||
*/
|
||||
object VimExtensionFacade {
|
||||
/** The 'map' command for mapping keys to handlers defined in extensions. */
|
||||
@JvmStatic
|
||||
@ScheduledForRemoval(inVersion = "0.58")
|
||||
@Deprecated("Only for EasyMotion support")
|
||||
fun putExtensionHandlerMapping(modes: Set<MappingMode>, fromKeys: List<KeyStroke>, extensionHandler: VimExtensionHandler, recursive: Boolean) {
|
||||
VimPlugin.getKey().putKeyMapping(modes, fromKeys, MappingOwner.Plugin.get("easymotion"), extensionHandler, recursive)
|
||||
}
|
||||
|
||||
@ScheduledForRemoval(inVersion = "0.58")
|
||||
@Deprecated("Only for EasyMotion support")
|
||||
@JvmStatic
|
||||
fun putKeyMapping(modes: Set<MappingMode>, fromKeys: List<KeyStroke>,
|
||||
toKeys: List<KeyStroke>, recursive: Boolean) {
|
||||
VimPlugin.getKey().putKeyMapping(modes, fromKeys, MappingOwner.Plugin.get("easymotion"), toKeys, recursive)
|
||||
}
|
||||
|
||||
/** The 'map' command for mapping keys to handlers defined in extensions. */
|
||||
@JvmStatic
|
||||
fun putExtensionHandlerMapping(modes: Set<MappingMode>, fromKeys: List<KeyStroke>,
|
||||
extensionHandler: VimExtensionHandler, recursive: Boolean) {
|
||||
VimPlugin.getKey().putKeyMapping(modes, fromKeys, null, extensionHandler, recursive)
|
||||
pluginOwner: MappingOwner, extensionHandler: VimExtensionHandler, recursive: Boolean) {
|
||||
VimPlugin.getKey().putKeyMapping(modes, fromKeys, pluginOwner, extensionHandler, recursive)
|
||||
}
|
||||
|
||||
/** The 'map' command for mapping keys to other keys. */
|
||||
@JvmStatic
|
||||
fun putKeyMapping(modes: Set<MappingMode>, fromKeys: List<KeyStroke>,
|
||||
toKeys: List<KeyStroke>, recursive: Boolean) {
|
||||
VimPlugin.getKey().putKeyMapping(modes, fromKeys, toKeys, null, recursive)
|
||||
pluginOwner: MappingOwner, toKeys: List<KeyStroke>, recursive: Boolean) {
|
||||
VimPlugin.getKey().putKeyMapping(modes, fromKeys, pluginOwner, toKeys, recursive)
|
||||
}
|
||||
|
||||
/** Sets the value of 'operatorfunc' to be used as the operator function in 'g@'. */
|
||||
@@ -78,7 +97,8 @@ object VimExtensionFacade {
|
||||
fun inputKeyStroke(editor: Editor): KeyStroke {
|
||||
if (editor.commandState.isDotRepeatInProgress) {
|
||||
val input = VimRepeater.Extension.consumeKeystroke()
|
||||
return input ?: throw RuntimeException("Not enough keystrokes saved: ${VimRepeater.Extension.lastExtensionHandler}")
|
||||
return input
|
||||
?: throw RuntimeException("Not enough keystrokes saved: ${VimRepeater.Extension.lastExtensionHandler}")
|
||||
}
|
||||
|
||||
val key: KeyStroke? = if (ApplicationManager.getApplication().isUnitTestMode) {
|
||||
@@ -167,4 +187,10 @@ object VimExtensionFacade {
|
||||
fun setRegister(register: Char, keys: List<KeyStroke?>?) {
|
||||
VimPlugin.getRegister().setKeys(register, keys ?: emptyList())
|
||||
}
|
||||
|
||||
/** Set the current contents of the given register */
|
||||
@JvmStatic
|
||||
fun setRegister(register: Char, keys: List<KeyStroke?>?, type: SelectionType) {
|
||||
VimPlugin.getRegister().setKeys(register, keys ?: emptyList(), type)
|
||||
}
|
||||
}
|
||||
|
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim.extension;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.ExtensionPointListener;
|
||||
import com.intellij.openapi.extensions.PluginDescriptor;
|
||||
import com.maddyhome.idea.vim.option.OptionsManager;
|
||||
import com.maddyhome.idea.vim.option.ToggleOption;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* TODO [VERSION UPDATE] this file cannot be converted to kt before 192 because of nullabilities problems in
|
||||
* [ExtensionPointListener]. (In previous versions of IJ pluginDescriptor was nullable)
|
||||
*/
|
||||
public class VimExtensionRegistrar {
|
||||
|
||||
private static Set<String> registeredExtensions = new HashSet<>();
|
||||
private static boolean extensionRegistered = false;
|
||||
|
||||
public static void registerExtensions() {
|
||||
if (extensionRegistered) return;
|
||||
extensionRegistered = true;
|
||||
|
||||
// TODO: [VERSION UPDATE] since 191 use
|
||||
// ExtensionPoint.addExtensionPointListener(ExtensionPointListener<T>, boolean, Disposable)
|
||||
VimExtension.EP_NAME.getPoint(null).addExtensionPointListener(new ExtensionPointListener<VimExtension>() {
|
||||
@Override
|
||||
public void extensionAdded(@NotNull VimExtension extension, @NotNull PluginDescriptor pluginDescriptor) {
|
||||
registerExtension(extension);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
synchronized private static void registerExtension(@NotNull VimExtension extension) {
|
||||
String name = extension.getName();
|
||||
|
||||
if (registeredExtensions.contains(name)) return;
|
||||
|
||||
registeredExtensions.add(name);
|
||||
ToggleOption option = new ToggleOption(name, name, false);
|
||||
option.addOptionChangeListener((oldValue, newValue) -> {
|
||||
for (VimExtension extensionInListener : VimExtension.EP_NAME.getExtensionList()) {
|
||||
if (name.equals(extensionInListener.getName())) {
|
||||
if (OptionsManager.INSTANCE.isSet(name)) {
|
||||
extensionInListener.init();
|
||||
logger.info("IdeaVim extension '" + name + "' initialized");
|
||||
}
|
||||
else {
|
||||
extensionInListener.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
OptionsManager.INSTANCE.addOption(option);
|
||||
}
|
||||
|
||||
private static Logger logger = Logger.getInstance(VimExtensionRegistrar.class);
|
||||
}
|
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
|
||||
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.maddyhome.idea.vim.extension
|
||||
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.extensions.ExtensionPointListener
|
||||
import com.intellij.openapi.extensions.PluginDescriptor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.key.MappingOwner.Plugin.Companion.remove
|
||||
import com.maddyhome.idea.vim.option.OptionsManager.addOption
|
||||
import com.maddyhome.idea.vim.option.OptionsManager.isSet
|
||||
import com.maddyhome.idea.vim.option.OptionsManager.removeOption
|
||||
import com.maddyhome.idea.vim.option.ToggleOption
|
||||
import java.util.*
|
||||
|
||||
object VimExtensionRegistrar {
|
||||
private val registeredExtensions: MutableSet<String> = HashSet()
|
||||
private var extensionRegistered = false
|
||||
private val logger = logger<VimExtensionRegistrar>()
|
||||
|
||||
@JvmStatic
|
||||
fun registerExtensions() {
|
||||
if (extensionRegistered) return
|
||||
extensionRegistered = true
|
||||
VimExtension.EP_NAME.getPoint(null).addExtensionPointListener(object : ExtensionPointListener<VimExtension> {
|
||||
override fun extensionAdded(extension: VimExtension, pluginDescriptor: PluginDescriptor) {
|
||||
registerExtension(extension)
|
||||
}
|
||||
|
||||
override fun extensionRemoved(extension: VimExtension, pluginDescriptor: PluginDescriptor) {
|
||||
unregisterExtension(extension)
|
||||
}
|
||||
}, true, VimPlugin.getInstance())
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun registerExtension(extension: VimExtension) {
|
||||
val name = extension.name
|
||||
if (name in registeredExtensions) return
|
||||
|
||||
registeredExtensions.add(name)
|
||||
val option = ToggleOption(name, name, false)
|
||||
option.addOptionChangeListener { _, _ ->
|
||||
for (extensionInListener in VimExtension.EP_NAME.extensionList) {
|
||||
if (name != extensionInListener.name) continue
|
||||
if (isSet(name)) {
|
||||
extensionInListener.init()
|
||||
logger.info("IdeaVim extension '$name' initialized")
|
||||
} else {
|
||||
extensionInListener.dispose()
|
||||
}
|
||||
}
|
||||
}
|
||||
addOption(option)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun unregisterExtension(extension: VimExtension) {
|
||||
val name = extension.name
|
||||
if (name !in registeredExtensions) return
|
||||
registeredExtensions.remove(name)
|
||||
extension.dispose()
|
||||
removeOption(name)
|
||||
remove(name)
|
||||
logger.info("IdeaVim extension '$name' disposed")
|
||||
}
|
||||
}
|
@@ -18,30 +18,19 @@
|
||||
|
||||
package com.maddyhome.idea.vim.extension;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
public abstract class VimNonDisposableExtension implements VimExtension {
|
||||
private boolean myInitialized = false;
|
||||
|
||||
@ApiStatus.ScheduledForRemoval(inVersion = "0.58")
|
||||
@Deprecated
|
||||
public abstract class VimNonDisposableExtension implements VimExtension {
|
||||
@Override
|
||||
public final void init() {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
initOnce();
|
||||
}
|
||||
else {
|
||||
if (!myInitialized) {
|
||||
myInitialized = true;
|
||||
initOnce();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void dispose() {
|
||||
}
|
||||
|
||||
protected abstract void initOnce();
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user