mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-17 16:31:45 +02:00
Compare commits
398 Commits
customized
...
customized
Author | SHA1 | Date | |
---|---|---|---|
57ddf2083e
|
|||
aad2287433
|
|||
a348428422
|
|||
c4c66c194a
|
|||
e065783486
|
|||
dae5e3a8fd
|
|||
bb3b67f611
|
|||
bf69c8b4a6
|
|||
49d1d2d270
|
|||
96cdf1c26d
|
|||
365bbce9a0
|
|||
1f8a580b7f
|
|||
fa9529eaa5
|
|||
0b29a4704b
|
|||
92b9046d6c
|
|||
f5b120ac01
|
|||
70ea63c0ba
|
|||
![]() |
d00bd8bb25 | ||
![]() |
a66e44d835 | ||
![]() |
ce05317634 | ||
![]() |
33d88d55c9 | ||
![]() |
a31a4a8ca7 | ||
![]() |
c34d000b91 | ||
![]() |
a2bfe950fa | ||
![]() |
b44f40acd6 | ||
![]() |
5169093bbf | ||
![]() |
b15b1cd3f8 | ||
![]() |
f7b6a97435 | ||
![]() |
f64c99c406 | ||
![]() |
f552e43c5b | ||
![]() |
4798198e41 | ||
![]() |
a59de4ce05 | ||
![]() |
2dea525665 | ||
![]() |
8ecb1f7296 | ||
![]() |
9ca9530061 | ||
![]() |
54e27afc3f | ||
![]() |
5e67032655 | ||
![]() |
cb37f6df63 | ||
![]() |
ca3a18cf37 | ||
![]() |
cac36627aa | ||
![]() |
6404e1127e | ||
![]() |
e762a3093b | ||
![]() |
739ac2ae5e | ||
![]() |
77c364a2d0 | ||
![]() |
103cd9f5ce | ||
![]() |
99859fe857 | ||
![]() |
4778995f3b | ||
![]() |
0a14150840 | ||
![]() |
e8ffc0313f | ||
![]() |
7dbd3886b1 | ||
![]() |
8c83164d76 | ||
![]() |
076aab1ccf | ||
![]() |
751f51c88f | ||
![]() |
ab7359ffd3 | ||
![]() |
d795d70041 | ||
![]() |
1320034e7e | ||
![]() |
79a216043f | ||
![]() |
c508a3cc32 | ||
![]() |
d40d8f34c5 | ||
![]() |
b561a13e7c | ||
![]() |
71bcee2a07 | ||
![]() |
6c490b1baa | ||
![]() |
4ab6a36aca | ||
![]() |
c4355841ad | ||
![]() |
f163946e38 | ||
![]() |
7abb1fd630 | ||
![]() |
f78d3387a5 | ||
![]() |
69e2e3c047 | ||
![]() |
52832cbe22 | ||
![]() |
82ca2be51c | ||
![]() |
8552bb8a17 | ||
![]() |
b49a38b6d0 | ||
![]() |
ad0751677a | ||
![]() |
dd8bb20ba9 | ||
![]() |
03f5f27901 | ||
![]() |
9e3ca56afd | ||
![]() |
5379528e3e | ||
![]() |
12201359bc | ||
![]() |
ba50fcf85e | ||
![]() |
24c0db563c | ||
![]() |
33c4905dcb | ||
![]() |
9296c3f9a0 | ||
![]() |
7ecc566169 | ||
![]() |
a918da36d3 | ||
![]() |
91ff5fdb02 | ||
![]() |
4481631547 | ||
![]() |
7865388086 | ||
![]() |
26297bc5a9 | ||
![]() |
9db5cdd8e3 | ||
![]() |
2b17534a08 | ||
![]() |
4e2db68acf | ||
![]() |
ddabf8df5e | ||
![]() |
3f28e197ca | ||
![]() |
3a67524e8a | ||
![]() |
33312d95b0 | ||
![]() |
f554b21cd9 | ||
![]() |
d9fa4e4648 | ||
![]() |
e98a284d40 | ||
![]() |
38ef8c1053 | ||
![]() |
d3f560a31c | ||
![]() |
e2cb3ff284 | ||
![]() |
0f5a3953e1 | ||
![]() |
633667ed7f | ||
![]() |
656e975562 | ||
![]() |
f7fbe89de4 | ||
![]() |
509829b052 | ||
![]() |
efd61e17f2 | ||
![]() |
cf2b021d02 | ||
![]() |
67f10aece5 | ||
![]() |
9b5c777fcf | ||
![]() |
c65e5f8341 | ||
![]() |
053bb603cd | ||
![]() |
93b07bbb90 | ||
![]() |
764a115601 | ||
![]() |
1adfe53f29 | ||
![]() |
bfe0f51cb1 | ||
![]() |
ffce61906a | ||
![]() |
3843a193cb | ||
![]() |
b2410dab0b | ||
![]() |
f382544101 | ||
![]() |
a81d54eb90 | ||
![]() |
23519bbdae | ||
![]() |
73fd25773a | ||
![]() |
746d483179 | ||
![]() |
1a7e90c7d7 | ||
![]() |
8e2fd44f55 | ||
![]() |
1c84917b29 | ||
![]() |
c5522ed19d | ||
![]() |
33a5480456 | ||
![]() |
16cd05fc76 | ||
![]() |
4788dacc86 | ||
![]() |
91e54c8b0d | ||
![]() |
15ccebfe11 | ||
![]() |
5c849c9105 | ||
![]() |
9e99506223 | ||
![]() |
53ea90379f | ||
![]() |
2619d7ebb4 | ||
![]() |
8c8a7aceca | ||
![]() |
726b885b60 | ||
![]() |
a6994a09c3 | ||
![]() |
1616aff5a1 | ||
![]() |
5a82f05be8 | ||
![]() |
3020504cdc | ||
![]() |
d00e802674 | ||
![]() |
c46008dddc | ||
![]() |
755000c376 | ||
![]() |
1e4a60bfe6 | ||
![]() |
c9ee685956 | ||
![]() |
c2b1083836 | ||
![]() |
3518528f22 | ||
![]() |
9bed8fec79 | ||
![]() |
3ffbea7d42 | ||
![]() |
39b42193cb | ||
![]() |
c69e080b05 | ||
![]() |
50b42036d1 | ||
![]() |
340c40ceff | ||
![]() |
6aeffe71de | ||
![]() |
04c33d719e | ||
![]() |
07f1d1e8e6 | ||
![]() |
6c61254c50 | ||
![]() |
c6efea8c34 | ||
![]() |
80f43a7c66 | ||
![]() |
9f5d3a9a28 | ||
![]() |
8800a4f70b | ||
![]() |
990254dcac | ||
![]() |
73a1118e78 | ||
![]() |
d3bedf26cf | ||
![]() |
25b29f429a | ||
![]() |
363f821962 | ||
![]() |
8d873c0bf1 | ||
![]() |
955676ed9e | ||
![]() |
a2439a37e4 | ||
![]() |
7b6daa8e4e | ||
![]() |
fcf782296a | ||
![]() |
44889b635c | ||
![]() |
bc12ba11cd | ||
![]() |
9b08db75e3 | ||
4c3ad3f263 | |||
![]() |
598bcc7edd | ||
![]() |
b86ec03dc4 | ||
![]() |
ae75498f8a | ||
![]() |
9d0b68b0f8 | ||
![]() |
eeb5939e59 | ||
![]() |
ef235a47bf | ||
![]() |
b66da76880 | ||
![]() |
54d6119784 | ||
![]() |
0b8c081425 | ||
![]() |
209052ffa6 | ||
![]() |
fe9a6b5cfb | ||
![]() |
9c0f74369f | ||
![]() |
cd27e5229b | ||
![]() |
472732905c | ||
![]() |
485d9f81cd | ||
![]() |
8cf136ce4c | ||
![]() |
116a8ac9d2 | ||
![]() |
fda310bda6 | ||
![]() |
e55619ea33 | ||
![]() |
b952b20128 | ||
![]() |
62d1f85648 | ||
![]() |
5e3c8c0e92 | ||
![]() |
b58dddf2ff | ||
![]() |
78d351a0b0 | ||
![]() |
61dbc948cc | ||
![]() |
c4d92ebe73 | ||
![]() |
d0cf827638 | ||
![]() |
6a6a92b6b9 | ||
![]() |
9869b8a34e | ||
![]() |
60fbf88322 | ||
![]() |
fae3924062 | ||
![]() |
dc2ce64823 | ||
![]() |
d0d86d9178 | ||
![]() |
f417af6148 | ||
![]() |
2fe2860a09 | ||
![]() |
cb40426976 | ||
![]() |
423ed390a2 | ||
![]() |
7652b16ca6 | ||
![]() |
618a010c15 | ||
![]() |
d44a34ed9b | ||
![]() |
c84fc996db | ||
![]() |
43f232543b | ||
![]() |
3f65d1d99a | ||
![]() |
bfcf706ca7 | ||
![]() |
8c1103c461 | ||
![]() |
ab75ace8db | ||
![]() |
4a58e6a282 | ||
![]() |
ac9e4f69b4 | ||
![]() |
581edba7fd | ||
![]() |
58a8b96c3c | ||
![]() |
0e057ca9ae | ||
![]() |
36bf2639bb | ||
![]() |
0c1326e689 | ||
![]() |
dd74438f68 | ||
![]() |
a9ddfac782 | ||
![]() |
79437df894 | ||
![]() |
b5a04af089 | ||
![]() |
52372ae3d3 | ||
![]() |
65d755d9b2 | ||
![]() |
1f1a8f3395 | ||
![]() |
629e4e7053 | ||
![]() |
c50a299cfd | ||
![]() |
4bad129caf | ||
![]() |
1ffb28e21b | ||
![]() |
c126243367 | ||
![]() |
6da6e461a8 | ||
![]() |
103101bbcb | ||
![]() |
f737fcba1a | ||
![]() |
c5fa0678b8 | ||
![]() |
00ccddf8cf | ||
![]() |
00cbf188fb | ||
![]() |
988ea74461 | ||
![]() |
0914cda7e5 | ||
![]() |
5959e9aaa1 | ||
![]() |
434df565ae | ||
![]() |
c8f36504d8 | ||
![]() |
06e1af371e | ||
![]() |
d744987ac8 | ||
![]() |
b4eef17aaa | ||
![]() |
5c50e8607c | ||
![]() |
9a324ab448 | ||
![]() |
c3978335f5 | ||
![]() |
051296c2aa | ||
![]() |
90f2d2ff29 | ||
![]() |
4c2edab406 | ||
![]() |
76e8fd69bf | ||
![]() |
5dd458bcf7 | ||
![]() |
a94a8b8539 | ||
![]() |
261230b23a | ||
![]() |
b90317e00e | ||
![]() |
21c9dc8785 | ||
![]() |
31bbc60325 | ||
![]() |
fec6e5c189 | ||
![]() |
23c1493f17 | ||
![]() |
00808af569 | ||
![]() |
3c94091d30 | ||
![]() |
b737362aba | ||
![]() |
db722fc4e5 | ||
![]() |
7d679e68dc | ||
![]() |
bc808403fb | ||
![]() |
9d6dc317a4 | ||
![]() |
cf29c50f31 | ||
![]() |
2a3c4cc441 | ||
![]() |
bd192561ae | ||
![]() |
66ff56a05e | ||
![]() |
def86d179e | ||
![]() |
3c9a343f8b | ||
![]() |
10b6b05fab | ||
![]() |
caa4ef736a | ||
![]() |
23702345a9 | ||
![]() |
ba89babd10 | ||
![]() |
2ce3fbd677 | ||
![]() |
d8de73a06d | ||
![]() |
8094e6711a | ||
![]() |
10edccc1d6 | ||
![]() |
247aaed188 | ||
![]() |
1a4333fa1b | ||
![]() |
8eaa6df318 | ||
![]() |
7523db186f | ||
![]() |
4aac113522 | ||
![]() |
795abd77a7 | ||
![]() |
38bc914504 | ||
![]() |
c8113eea83 | ||
![]() |
924b7418e8 | ||
![]() |
a7dfef61e9 | ||
![]() |
db35c979b4 | ||
![]() |
2de933c723 | ||
![]() |
d3704d602f | ||
![]() |
ea62f227bf | ||
![]() |
23fdadc32e | ||
![]() |
e9bf06686f | ||
![]() |
7842b155c1 | ||
![]() |
74a8277e10 | ||
![]() |
ddb1b80463 | ||
![]() |
eea3336934 | ||
![]() |
f801145712 | ||
![]() |
e033b08535 | ||
![]() |
1d9514a205 | ||
![]() |
6741120f19 | ||
![]() |
c501457322 | ||
![]() |
46425a24c3 | ||
![]() |
9826f0a7f0 | ||
![]() |
43175061e0 | ||
![]() |
0ab32cac34 | ||
![]() |
e3ec9c614b | ||
![]() |
f454d60234 | ||
![]() |
19fa00837c | ||
![]() |
275c5d28e1 | ||
![]() |
15ae069f6f | ||
![]() |
00f5541dc6 | ||
![]() |
02540eb303 | ||
![]() |
282e581bdb | ||
![]() |
31e7c49608 | ||
![]() |
7966a6dc91 | ||
![]() |
5fc2f04224 | ||
![]() |
6edfd8ed22 | ||
![]() |
363db05db7 | ||
![]() |
3738012dd6 | ||
![]() |
355cfe035d | ||
![]() |
6d01b5be77 | ||
![]() |
4938957483 | ||
![]() |
46f4fa7cdd | ||
![]() |
f696135f31 | ||
![]() |
52e0fcdc7d | ||
![]() |
ac17518a23 | ||
6dd924b2b2 | |||
![]() |
f439474b73 | ||
![]() |
d6cd92e256 | ||
![]() |
3a294268d9 | ||
![]() |
9b81c7e650 | ||
![]() |
e229fb3ad7 | ||
![]() |
720eae63fa | ||
![]() |
0df96a24bd | ||
![]() |
21a1588ede | ||
![]() |
7970006e8c | ||
![]() |
418d0cff7f | ||
![]() |
7284360774 | ||
![]() |
9fc3fadee8 | ||
![]() |
3d2db56f63 | ||
![]() |
e9c7cb8670 | ||
![]() |
87d19274c5 | ||
![]() |
3161bf8ffd | ||
![]() |
b68865587e | ||
![]() |
7dc0dbe944 | ||
![]() |
f50a363525 | ||
![]() |
57ad4c70d1 | ||
![]() |
d3d93b898f | ||
![]() |
7d8973edb2 | ||
![]() |
2302b576b0 | ||
f4782630d4 | |||
![]() |
8c1a2a686f | ||
32d5e1e6fa | |||
![]() |
a381a1cacc | ||
![]() |
73c3c9f7fe | ||
![]() |
67ef0a75d5 | ||
![]() |
328bc5e95a | ||
![]() |
7f8021e37e | ||
![]() |
9701b7e79b | ||
![]() |
7a52c6fec9 | ||
![]() |
1503639d4b | ||
![]() |
e82f19c852 | ||
![]() |
edd69c9c25 | ||
![]() |
fc61e369fb | ||
![]() |
113586b59b | ||
![]() |
5dbd5e1c89 | ||
![]() |
04b7d9e2c3 | ||
![]() |
5f2743176a | ||
![]() |
3723488617 | ||
![]() |
0cc17a0791 | ||
![]() |
05a21e6091 | ||
![]() |
fc06bc7c6f | ||
![]() |
1bd005adc1 | ||
![]() |
4f208d1577 | ||
![]() |
eb6e0557a7 | ||
![]() |
cf09d66be6 | ||
![]() |
76cd127a8a | ||
![]() |
f6dd2a9968 | ||
![]() |
ae05a33e14 | ||
![]() |
b38fad323b | ||
![]() |
c6027fcf0f |
2
.github/workflows/mergePr.yml
vendored
2
.github/workflows/mergePr.yml
vendored
@@ -11,7 +11,7 @@ on:
|
||||
jobs:
|
||||
build:
|
||||
|
||||
if: github.event.pull_request.merged == true && github.repository == 'JetBrains/ideavim'
|
||||
if: false
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
|
12
.github/workflows/runUiOctopusTests.yml
vendored
12
.github/workflows/runUiOctopusTests.yml
vendored
@@ -9,20 +9,13 @@ jobs:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Apply Patch
|
||||
run: |
|
||||
git apply tests/ui-ij-tests/src/test/kotlin/ui/octopus.patch
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: zulu
|
||||
java-version: 17
|
||||
- name: Setup FFmpeg
|
||||
uses: FedericoCarboni/setup-ffmpeg@v3
|
||||
with:
|
||||
# Not strictly necessary, but it may prevent rate limit
|
||||
# errors especially on GitHub-hosted macos machines.
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: brew install ffmpeg
|
||||
- name: Setup Gradle
|
||||
uses: gradle/gradle-build-action@v2.4.2
|
||||
- name: Build Plugin
|
||||
@@ -30,7 +23,7 @@ jobs:
|
||||
- name: Run Idea
|
||||
run: |
|
||||
mkdir -p build/reports
|
||||
gradle runIdeForUiTests > build/reports/idea.log &
|
||||
gradle runIdeForUiTests -Doctopus.handler=false > build/reports/idea.log &
|
||||
- name: Wait for Idea started
|
||||
uses: jtalk/url-health-check-action@v3
|
||||
with:
|
||||
@@ -52,6 +45,7 @@ jobs:
|
||||
name: ui-test-fails-report-mac
|
||||
path: |
|
||||
build/reports
|
||||
tests/ui-ij-tests/build/reports
|
||||
sandbox-idea-log
|
||||
# build-for-ui-test-linux:
|
||||
# runs-on: ubuntu-latest
|
||||
|
7
.github/workflows/runUiPyTests.yml
vendored
7
.github/workflows/runUiPyTests.yml
vendored
@@ -18,11 +18,7 @@ jobs:
|
||||
with:
|
||||
python-version: '3.10'
|
||||
- name: Setup FFmpeg
|
||||
uses: FedericoCarboni/setup-ffmpeg@v3
|
||||
with:
|
||||
# Not strictly necessary, but it may prevent rate limit
|
||||
# errors especially on GitHub-hosted macos machines.
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: brew install ffmpeg
|
||||
- name: Setup Gradle
|
||||
uses: gradle/gradle-build-action@v2.4.2
|
||||
- name: Build Plugin
|
||||
@@ -52,4 +48,5 @@ jobs:
|
||||
name: ui-test-fails-report-mac
|
||||
path: |
|
||||
build/reports
|
||||
tests/ui-py-tests/build/reports
|
||||
sandbox-idea-log
|
7
.github/workflows/runUiTests.yml
vendored
7
.github/workflows/runUiTests.yml
vendored
@@ -15,11 +15,7 @@ jobs:
|
||||
distribution: zulu
|
||||
java-version: 17
|
||||
- name: Setup FFmpeg
|
||||
uses: FedericoCarboni/setup-ffmpeg@v3
|
||||
with:
|
||||
# Not strictly necessary, but it may prevent rate limit
|
||||
# errors especially on GitHub-hosted macos machines.
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: brew install ffmpeg
|
||||
- name: Setup Gradle
|
||||
uses: gradle/gradle-build-action@v2.4.2
|
||||
- name: Build Plugin
|
||||
@@ -49,6 +45,7 @@ jobs:
|
||||
name: ui-test-fails-report-mac
|
||||
path: |
|
||||
build/reports
|
||||
tests/ui-ij-tests/build/reports
|
||||
sandbox-idea-log
|
||||
# build-for-ui-test-linux:
|
||||
# runs-on: ubuntu-latest
|
||||
|
34
.github/workflows/updateAffectedRate.yml
vendored
34
.github/workflows/updateAffectedRate.yml
vendored
@@ -1,34 +0,0 @@
|
||||
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
|
||||
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle
|
||||
|
||||
# This workflow syncs changes from the docs folder of IdeaVim to the IdeaVim.wiki repository
|
||||
|
||||
name: Update Affected Rate field on YouTrack
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 8 * * *'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'JetBrains/ideavim'
|
||||
|
||||
steps:
|
||||
- name: Fetch origin repo
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'adopt'
|
||||
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
settings-path: ${{ github.workspace }} # location for the settings.xml file
|
||||
|
||||
- name: Update YouTrack
|
||||
run: ./gradlew scripts:updateAffectedRates
|
||||
env:
|
||||
YOUTRACK_TOKEN: ${{ secrets.YOUTRACK_TOKEN }}
|
5
.github/workflows/updateChangelog.yml
vendored
5
.github/workflows/updateChangelog.yml
vendored
@@ -7,15 +7,12 @@ on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 10 * * *'
|
||||
# Workflow run on push is disabled to avoid conflicts when merging PR
|
||||
# push:
|
||||
# branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'JetBrains/ideavim'
|
||||
if: false
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
2
.idea/vcs.xml
generated
2
.idea/vcs.xml
generated
@@ -11,6 +11,6 @@
|
||||
</option>
|
||||
</component>
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
16
.teamcity/_Self/Constants.kt
vendored
16
.teamcity/_Self/Constants.kt
vendored
@@ -5,13 +5,13 @@ object Constants {
|
||||
const val EAP_CHANNEL = "eap"
|
||||
const val DEV_CHANNEL = "Dev"
|
||||
|
||||
const val GITHUB_TESTS = "2023.3.2"
|
||||
const val NVIM_TESTS = "2023.3.2"
|
||||
const val PROPERTY_TESTS = "2023.3.2"
|
||||
const val LONG_RUNNING_TESTS = "2023.3.2"
|
||||
const val QODANA_TESTS = "2023.3.2"
|
||||
const val RELEASE = "2023.3.2"
|
||||
const val GITHUB_TESTS = "2024.1.1"
|
||||
const val NVIM_TESTS = "2024.1.1"
|
||||
const val PROPERTY_TESTS = "2024.1.1"
|
||||
const val LONG_RUNNING_TESTS = "2024.1.1"
|
||||
const val QODANA_TESTS = "2024.1.1"
|
||||
const val RELEASE = "2024.1.1"
|
||||
|
||||
const val RELEASE_DEV = "2023.3.2"
|
||||
const val RELEASE_EAP = "2023.3.2"
|
||||
const val RELEASE_DEV = "2024.1.1"
|
||||
const val RELEASE_EAP = "2024.1.1"
|
||||
}
|
||||
|
4
.teamcity/_Self/Project.kt
vendored
4
.teamcity/_Self/Project.kt
vendored
@@ -11,6 +11,7 @@ import _Self.subprojects.GitHub
|
||||
import _Self.subprojects.OldTests
|
||||
import _Self.subprojects.Releases
|
||||
import _Self.vcsRoots.GitHubPullRequest
|
||||
import _Self.vcsRoots.ReleasesVcsRoot
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.BuildType
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.Project
|
||||
|
||||
@@ -21,10 +22,11 @@ object Project : Project({
|
||||
|
||||
// VCS roots
|
||||
vcsRoot(GitHubPullRequest)
|
||||
vcsRoot(ReleasesVcsRoot)
|
||||
|
||||
// Active tests
|
||||
buildType(TestingBuildType("Latest EAP", "<default>", version = "LATEST-EAP-SNAPSHOT"))
|
||||
buildType(TestingBuildType("2023.3", "<default>", version = "2023.3"))
|
||||
buildType(TestingBuildType("2024.1.1", "<default>"))
|
||||
buildType(TestingBuildType("Latest EAP With Xorg", "<default>", version = "LATEST-EAP-SNAPSHOT"))
|
||||
|
||||
buildType(PropertyBased)
|
||||
|
72
.teamcity/_Self/buildTypes/CreateNewReleaseBranchFromMaster.kt
vendored
Normal file
72
.teamcity/_Self/buildTypes/CreateNewReleaseBranchFromMaster.kt
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2003-2024 The IdeaVim authors
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE.txt file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
package _Self.buildTypes
|
||||
|
||||
import _Self.IdeaVimBuildType
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.CheckoutMode
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.DslContext
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.buildFeatures.sshAgent
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.script
|
||||
|
||||
object CreateNewReleaseBranchFromMaster : IdeaVimBuildType({
|
||||
name = "EXP: Create new release branch from master"
|
||||
|
||||
vcs {
|
||||
root(DslContext.settingsRoot)
|
||||
branchFilter = "+:<default>"
|
||||
|
||||
checkoutMode = CheckoutMode.AUTO
|
||||
}
|
||||
|
||||
steps {
|
||||
script {
|
||||
name = "Calculate next potential release version"
|
||||
scriptContent = """
|
||||
#!/bin/bash
|
||||
|
||||
# Fetch all remote branches
|
||||
git fetch --all
|
||||
|
||||
# Get a list of all branches matching the pattern releases/x.y.z
|
||||
branches=${'$'}(git branch -r | grep -oE 'releases/[0-9]+\.[0-9]+\.x')
|
||||
|
||||
# If no matching branches are found, print a message and exit
|
||||
if [[ -z "${'$'}branches" ]]; then
|
||||
echo "No release branches found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Find the largest release version
|
||||
largest_release=${'$'}(echo "${'$'}branches" | sort -V | tail -n 1)
|
||||
|
||||
# Print the largest release
|
||||
echo "Largest release branch: ${'$'}largest_release"
|
||||
echo "##teamcity[setParameter name='env.POTENTIAL_VERSION' value='${'$'}largest_release']"
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
script {
|
||||
name = "Show potential release version"
|
||||
scriptContent = """
|
||||
#!/bin/bash
|
||||
echo "Calculated or user-provided parameter value is: %env.POTENTIAL_VERSION%"
|
||||
""".trimIndent()
|
||||
}
|
||||
}
|
||||
|
||||
params {
|
||||
param("env.POTENTIAL_VERSION", "")
|
||||
}
|
||||
|
||||
features {
|
||||
sshAgent {
|
||||
teamcitySshKey = "IdeaVim ssh keys"
|
||||
}
|
||||
}
|
||||
})
|
42
.teamcity/_Self/buildTypes/PrintReleaseBranch.kt
vendored
Normal file
42
.teamcity/_Self/buildTypes/PrintReleaseBranch.kt
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2003-2024 The IdeaVim authors
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE.txt file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
package _Self.buildTypes
|
||||
|
||||
import _Self.IdeaVimBuildType
|
||||
import _Self.vcsRoots.ReleasesVcsRoot
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.CheckoutMode
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.buildFeatures.sshAgent
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.script
|
||||
|
||||
object PrintReleaseBranch : IdeaVimBuildType({
|
||||
name = "EXP: Print release branch"
|
||||
|
||||
vcs {
|
||||
root(ReleasesVcsRoot)
|
||||
branchFilter = "+:heads/releases/*"
|
||||
|
||||
checkoutMode = CheckoutMode.AUTO
|
||||
}
|
||||
|
||||
steps {
|
||||
|
||||
script {
|
||||
name = "Print current branch"
|
||||
scriptContent = """
|
||||
echo "Current branch is: %teamcity.build.branch%"
|
||||
""".trimIndent()
|
||||
}
|
||||
}
|
||||
|
||||
features {
|
||||
sshAgent {
|
||||
teamcitySshKey = "IdeaVim ssh keys"
|
||||
}
|
||||
}
|
||||
})
|
@@ -26,7 +26,7 @@ object PublishVimEngine : IdeaVimBuildType({
|
||||
|
||||
vcs {
|
||||
root(DslContext.settingsRoot)
|
||||
branchFilter = "+:<default>"
|
||||
branchFilter = "+:fleet"
|
||||
|
||||
checkoutMode = CheckoutMode.AUTO
|
||||
}
|
||||
|
3
.teamcity/_Self/buildTypes/Qodana.kt
vendored
3
.teamcity/_Self/buildTypes/Qodana.kt
vendored
@@ -46,8 +46,8 @@ object Qodana : IdeaVimBuildType({
|
||||
version = Qodana.JVMVersion.LATEST
|
||||
}
|
||||
reportAsTests = true
|
||||
additionalDockerArguments = "-e QODANA_TOKEN=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJvcmdhbml6YXRpb24iOiIzUFZrQSIsInByb2plY3QiOiIzN1FlQSIsInRva2VuIjoiM0t2bXoifQ.uohp81tM7iAfvvB6k8faarfpV-OjusAaEbWQ8iNrOgs"
|
||||
additionalQodanaArguments = "--baseline qodana.sarif.json"
|
||||
cloudToken = "credentialsJSON:6b79412e-9198-4862-9223-c5019488f903"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,6 @@ object Qodana : IdeaVimBuildType({
|
||||
timezone = "SERVER"
|
||||
}
|
||||
param("dayOfWeek", "Sunday")
|
||||
enabled = false
|
||||
}
|
||||
}
|
||||
|
||||
|
106
.teamcity/_Self/buildTypes/ReleaseEapFromBranch.kt
vendored
Normal file
106
.teamcity/_Self/buildTypes/ReleaseEapFromBranch.kt
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
package _Self.buildTypes
|
||||
|
||||
import _Self.Constants.EAP_CHANNEL
|
||||
import _Self.Constants.RELEASE_EAP
|
||||
import _Self.IdeaVimBuildType
|
||||
import _Self.vcsRoots.ReleasesVcsRoot
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.CheckoutMode
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.ParameterDisplay
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.buildFeatures.sshAgent
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.gradle
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.script
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.failureConditions.BuildFailureOnMetric
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.failureConditions.failOnMetricChange
|
||||
|
||||
object ReleaseEapFromBranch : IdeaVimBuildType({
|
||||
name = "EXP: Publish EAP Build from branch"
|
||||
description = "Build and publish EAP of IdeaVim plugin"
|
||||
|
||||
artifactRules = "build/distributions/*"
|
||||
|
||||
params {
|
||||
param("env.ORG_GRADLE_PROJECT_ideaVersion", RELEASE_EAP)
|
||||
password(
|
||||
"env.ORG_GRADLE_PROJECT_publishToken",
|
||||
"credentialsJSON:61a36031-4da1-4226-a876-b8148bf32bde",
|
||||
label = "Password"
|
||||
)
|
||||
param("env.ORG_GRADLE_PROJECT_publishChannels", EAP_CHANNEL)
|
||||
password(
|
||||
"env.ORG_GRADLE_PROJECT_slackUrl",
|
||||
"credentialsJSON:a8ab8150-e6f8-4eaf-987c-bcd65eac50b5",
|
||||
label = "Slack Token"
|
||||
)
|
||||
password(
|
||||
"env.YOUTRACK_TOKEN",
|
||||
"credentialsJSON:2479995b-7b60-4fbb-b095-f0bafae7f622",
|
||||
display = ParameterDisplay.HIDDEN
|
||||
)
|
||||
}
|
||||
|
||||
vcs {
|
||||
root(ReleasesVcsRoot)
|
||||
branchFilter = """
|
||||
+:heads/(releases/*)
|
||||
""".trimIndent()
|
||||
|
||||
checkoutMode = CheckoutMode.AUTO
|
||||
}
|
||||
|
||||
steps {
|
||||
script {
|
||||
name = "Pull git tags"
|
||||
scriptContent = "git fetch --tags origin"
|
||||
}
|
||||
script {
|
||||
name = "Pull git history"
|
||||
scriptContent = "git fetch --unshallow"
|
||||
}
|
||||
gradle {
|
||||
name = "Calculate new eap version from branch"
|
||||
tasks = "scripts:calculateNewEapVersionFromBranch"
|
||||
}
|
||||
gradle {
|
||||
name = "Set TeamCity build number"
|
||||
tasks = "scripts:setTeamCityBuildNumber"
|
||||
}
|
||||
gradle {
|
||||
name = "Add release tag"
|
||||
tasks = "scripts:addReleaseTag"
|
||||
}
|
||||
gradle {
|
||||
name = "Publish plugin"
|
||||
tasks = "publishPlugin"
|
||||
}
|
||||
script {
|
||||
name = "Push changes to the repo"
|
||||
scriptContent = """
|
||||
branch=$(git branch --show-current)
|
||||
echo current branch is ${'$'}branch
|
||||
git push origin %build.number%
|
||||
""".trimIndent()
|
||||
}
|
||||
gradle {
|
||||
name = "YouTrack post release actions"
|
||||
tasks = "scripts:eapReleaseActions"
|
||||
}
|
||||
}
|
||||
|
||||
features {
|
||||
sshAgent {
|
||||
teamcitySshKey = "IdeaVim ssh keys"
|
||||
}
|
||||
}
|
||||
|
||||
failureConditions {
|
||||
failOnMetricChange {
|
||||
metric = BuildFailureOnMetric.MetricType.ARTIFACT_SIZE
|
||||
threshold = 5
|
||||
units = BuildFailureOnMetric.MetricUnit.PERCENTS
|
||||
comparison = BuildFailureOnMetric.MetricComparison.DIFF
|
||||
compareTo = build {
|
||||
buildRule = lastSuccessful()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
63
.teamcity/_Self/buildTypes/ReleasePlugin.kt
vendored
63
.teamcity/_Self/buildTypes/ReleasePlugin.kt
vendored
@@ -97,14 +97,14 @@ sealed class ReleasePlugin(private val releaseType: String) : IdeaVimBuildType({
|
||||
name = "Set TeamCity build number"
|
||||
tasks = "scripts:setTeamCityBuildNumber"
|
||||
}
|
||||
gradle {
|
||||
name = "Update change log"
|
||||
tasks = "scripts:changelogUpdateUnreleased"
|
||||
}
|
||||
gradle {
|
||||
name = "Commit preparation changes"
|
||||
tasks = "scripts:commitChanges"
|
||||
}
|
||||
// gradle {
|
||||
// name = "Update change log"
|
||||
// tasks = "scripts:changelogUpdateUnreleased"
|
||||
// }
|
||||
// gradle {
|
||||
// name = "Commit preparation changes"
|
||||
// tasks = "scripts:commitChanges"
|
||||
// }
|
||||
gradle {
|
||||
name = "Add release tag"
|
||||
tasks = "scripts:addReleaseTag"
|
||||
@@ -117,33 +117,24 @@ sealed class ReleasePlugin(private val releaseType: String) : IdeaVimBuildType({
|
||||
name = "Publish release"
|
||||
tasks = "publishPlugin"
|
||||
}
|
||||
script {
|
||||
name = "Checkout master branch"
|
||||
scriptContent = """
|
||||
echo Checkout master
|
||||
git checkout master
|
||||
""".trimIndent()
|
||||
}
|
||||
gradle {
|
||||
name = "Update change log in master"
|
||||
tasks = "scripts:changelogUpdateUnreleased"
|
||||
}
|
||||
gradle {
|
||||
name = "Commit preparation changes in master"
|
||||
tasks = "scripts:commitChanges"
|
||||
}
|
||||
// script {
|
||||
// name = "Checkout master branch"
|
||||
// scriptContent = """
|
||||
// echo Checkout master
|
||||
// git checkout master
|
||||
// """.trimIndent()
|
||||
// }
|
||||
// gradle {
|
||||
// name = "Update change log in master"
|
||||
// tasks = "scripts:changelogUpdateUnreleased"
|
||||
// }
|
||||
// gradle {
|
||||
// name = "Commit preparation changes in master"
|
||||
// tasks = "scripts:commitChanges"
|
||||
// }
|
||||
script {
|
||||
name = "Push changes to the repo"
|
||||
scriptContent = """
|
||||
branch=$(git branch --show-current)
|
||||
echo Current branch is ${'$'}branch
|
||||
if [ "master" != "${'$'}branch" ];
|
||||
then
|
||||
git checkout master
|
||||
fi
|
||||
|
||||
git push origin
|
||||
|
||||
git checkout release
|
||||
echo checkout release branch
|
||||
git branch --set-upstream-to=origin/release release
|
||||
@@ -156,10 +147,10 @@ sealed class ReleasePlugin(private val releaseType: String) : IdeaVimBuildType({
|
||||
name = "Run Integrations"
|
||||
tasks = "releaseActions"
|
||||
}
|
||||
gradle {
|
||||
name = "Slack Notification"
|
||||
tasks = "slackNotification"
|
||||
}
|
||||
// gradle {
|
||||
// name = "Slack Notification"
|
||||
// tasks = "slackNotification"
|
||||
// }
|
||||
}
|
||||
|
||||
features {
|
||||
|
4
.teamcity/_Self/subprojects/GitHub.kt
vendored
4
.teamcity/_Self/subprojects/GitHub.kt
vendored
@@ -16,10 +16,10 @@ object GitHub : Project({
|
||||
name = "Pull Requests checks"
|
||||
description = "Automatic checking of GitHub Pull Requests"
|
||||
|
||||
buildType(Github("clean test", "Tests"))
|
||||
buildType(GithubBuildType("clean test", "Tests"))
|
||||
})
|
||||
|
||||
class Github(command: String, desc: String) : IdeaVimBuildType({
|
||||
class GithubBuildType(command: String, desc: String) : IdeaVimBuildType({
|
||||
name = "GitHub Pull Requests $desc"
|
||||
description = "Test GitHub pull requests $desc"
|
||||
|
||||
|
7
.teamcity/_Self/subprojects/Releases.kt
vendored
7
.teamcity/_Self/subprojects/Releases.kt
vendored
@@ -1,8 +1,11 @@
|
||||
package _Self.subprojects
|
||||
|
||||
import _Self.buildTypes.CreateNewReleaseBranchFromMaster
|
||||
import _Self.buildTypes.PrintReleaseBranch
|
||||
import _Self.buildTypes.PublishVimEngine
|
||||
import _Self.buildTypes.ReleaseDev
|
||||
import _Self.buildTypes.ReleaseEap
|
||||
import _Self.buildTypes.ReleaseEapFromBranch
|
||||
import _Self.buildTypes.ReleaseMajor
|
||||
import _Self.buildTypes.ReleaseMinor
|
||||
import _Self.buildTypes.ReleasePatch
|
||||
@@ -38,4 +41,8 @@ object Releases : Project({
|
||||
buildType(ReleaseEap)
|
||||
buildType(ReleaseDev)
|
||||
buildType(PublishVimEngine)
|
||||
|
||||
buildType(CreateNewReleaseBranchFromMaster)
|
||||
buildType(PrintReleaseBranch)
|
||||
buildType(ReleaseEapFromBranch)
|
||||
})
|
||||
|
13
.teamcity/_Self/vcsRoots/Releases.kt
vendored
Normal file
13
.teamcity/_Self/vcsRoots/Releases.kt
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
package _Self.vcsRoots
|
||||
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.vcs.GitVcsRoot
|
||||
|
||||
object ReleasesVcsRoot : GitVcsRoot({
|
||||
name = "IdeaVim Releases"
|
||||
url = "git@github.com:JetBrains/ideavim.git"
|
||||
branch = "refs/heads/master"
|
||||
branchSpec = "+:refs/(*)"
|
||||
authMethod = uploadedKey {
|
||||
uploadedKey = "IdeaVim ssh keys"
|
||||
}
|
||||
})
|
@@ -1,11 +1,9 @@
|
||||
package patches.buildTypes
|
||||
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.RelativeId
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.*
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.GradleBuildStep
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.gradle
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.ui.changeBuildType
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.ui.expectSteps
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.ui.update
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.ui.*
|
||||
|
||||
/*
|
||||
This patch script was generated by TeamCity on settings change in UI.
|
||||
@@ -13,6 +11,18 @@ To apply the patch, change the buildType with id = 'IdeaVimTests_Latest_EAP'
|
||||
accordingly, and delete the patch script.
|
||||
*/
|
||||
changeBuildType(RelativeId("IdeaVimTests_Latest_EAP")) {
|
||||
check(artifactRules == """
|
||||
+:build/reports => build/reports
|
||||
+:/mnt/agent/temp/buildTmp/ => /mnt/agent/temp/buildTmp/
|
||||
""".trimIndent()) {
|
||||
"Unexpected option value: artifactRules = $artifactRules"
|
||||
}
|
||||
artifactRules = """
|
||||
+:build/reports => build/reports
|
||||
+:/mnt/agent/temp/buildTmp/ => /mnt/agent/temp/buildTmp/
|
||||
+:tests/java-tests/build/reports => tests/java-tests/build/reports
|
||||
""".trimIndent()
|
||||
|
||||
expectSteps {
|
||||
gradle {
|
||||
tasks = "clean test"
|
||||
|
@@ -5,15 +5,15 @@ import jetbrains.buildServer.configs.kotlin.v2019_2.ui.*
|
||||
|
||||
/*
|
||||
This patch script was generated by TeamCity on settings change in UI.
|
||||
To apply the patch, change the buildType with id = 'PublishVimEngine'
|
||||
To apply the patch, change the buildType with id = 'ReleaseEapFromBranch'
|
||||
accordingly, and delete the patch script.
|
||||
*/
|
||||
changeBuildType(RelativeId("PublishVimEngine")) {
|
||||
changeBuildType(RelativeId("ReleaseEapFromBranch")) {
|
||||
vcs {
|
||||
|
||||
check(branchFilter == "+:<default>") {
|
||||
check(branchFilter == "+:heads/(releases/*)") {
|
||||
"Unexpected option value: branchFilter = $branchFilter"
|
||||
}
|
||||
branchFilter = "+:fleet"
|
||||
branchFilter = "heads/releases/*"
|
||||
}
|
||||
}
|
2
.teamcity/settings.kts
vendored
2
.teamcity/settings.kts
vendored
@@ -30,5 +30,5 @@ node (Plugins -> teamcity-configs -> teamcity-configs:generate),
|
||||
the 'Debug' option is available in the context menu for the task.
|
||||
*/
|
||||
|
||||
version = "2023.11"
|
||||
version = "2024.03"
|
||||
project(_Self.Project)
|
||||
|
16
AUTHORS.md
16
AUTHORS.md
@@ -495,6 +495,22 @@ Contributors:
|
||||
[![icon][github]](https://github.com/emanuelgestosa)
|
||||
|
||||
Emanuel Gestosa
|
||||
* [![icon][mail]](mailto:81118900+lippfi@users.noreply.github.com)
|
||||
[![icon][github]](https://github.com/lippfi)
|
||||
|
||||
lippfi,
|
||||
* [![icon][mail]](mailto:fillipser143@gmail.com)
|
||||
[![icon][github]](https://github.com/Parker7123)
|
||||
|
||||
FilipParker
|
||||
* [![icon][mail]](mailto:7138209+duhaesbaert@users.noreply.github.com)
|
||||
[![icon][github]](https://github.com/duhaesbaert)
|
||||
|
||||
Eduardo Haesbaert
|
||||
* [![icon][mail]](mailto:nikolaevsky.egor@gmail.com)
|
||||
[![icon][github]](https://github.com/Aisper)
|
||||
|
||||
Egor Nikolaevsky
|
||||
|
||||
Previous contributors:
|
||||
|
||||
|
12
CHANGES.md
12
CHANGES.md
@@ -23,15 +23,19 @@ It is important to distinguish EAP from traditional pre-release software.
|
||||
Please note that the quality of EAP versions may at times be way below even
|
||||
usual beta standards.
|
||||
|
||||
## To Be Released
|
||||
## End of changelog file maintenance
|
||||
|
||||
Since version 2.9.0, the changelog can be found on YouTrack
|
||||
|
||||
To Be Released: https://youtrack.jetbrains.com/issues/VIM?q=%23%7BReady%20To%20Release%7D%20
|
||||
Latest Fixes: https://youtrack.jetbrains.com/issues/VIM?q=State:%20Fixed%20sort%20by:%20updated%20
|
||||
|
||||
## 2.9.0, 2024-02-20
|
||||
|
||||
### Fixes:
|
||||
* [VIM-3055](https://youtrack.jetbrains.com/issue/VIM-3055) Fix the issue with double deleting after dot
|
||||
* [VIM-3291](https://youtrack.jetbrains.com/issue/VIM-3291) Remove sync of editor selection between different opened editors
|
||||
* [VIM-3234](https://youtrack.jetbrains.com/issue/VIM-3234) The space character won't mix in the tab chars after >> and << commands
|
||||
|
||||
### Merged PRs:
|
||||
* [725](https://github.com/JetBrains/ideavim/pull/725) by [Emanuel Gestosa](https://github.com/emanuelgestosa): Regex
|
||||
* [805](https://github.com/JetBrains/ideavim/pull/805) by [chylex](https://github.com/chylex): VIM-3238 Fix recording a macro that replays another macro
|
||||
|
||||
## 2.8.0, 2024-01-30
|
||||
|
@@ -21,7 +21,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.google.devtools.ksp:symbol-processing-api:1.9.22-1.0.17")
|
||||
compileOnly("com.google.devtools.ksp:symbol-processing-api:1.9.24-1.0.20")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:$kotlinxSerializationVersion") {
|
||||
// kotlin stdlib is provided by IJ, so there is no need to include it into the distribution
|
||||
exclude("org.jetbrains.kotlin", "kotlin-stdlib")
|
||||
|
@@ -32,7 +32,6 @@ import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.lib.RepositoryBuilder
|
||||
import org.intellij.markdown.ast.getTextInNode
|
||||
import org.jetbrains.changelog.Changelog
|
||||
import org.jetbrains.changelog.exceptions.MissingVersionException
|
||||
import org.kohsuke.github.GHUser
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
@@ -49,14 +48,14 @@ buildscript {
|
||||
classpath("org.eclipse.jgit:org.eclipse.jgit:6.6.0.202305301015-r")
|
||||
|
||||
// This is needed for jgit to connect to ssh
|
||||
classpath("org.eclipse.jgit:org.eclipse.jgit.ssh.apache:6.8.0.202311291450-r")
|
||||
classpath("org.eclipse.jgit:org.eclipse.jgit.ssh.apache:6.9.0.202403050737-r")
|
||||
classpath("org.kohsuke:github-api:1.305")
|
||||
|
||||
classpath("io.ktor:ktor-client-core:2.3.7")
|
||||
classpath("io.ktor:ktor-client-cio:2.3.7")
|
||||
classpath("io.ktor:ktor-client-auth:2.3.7")
|
||||
classpath("io.ktor:ktor-client-content-negotiation:2.3.7")
|
||||
classpath("io.ktor:ktor-serialization-kotlinx-json:2.3.7")
|
||||
classpath("io.ktor:ktor-client-core:2.3.11")
|
||||
classpath("io.ktor:ktor-client-cio:2.3.10")
|
||||
classpath("io.ktor:ktor-client-auth:2.3.11")
|
||||
classpath("io.ktor:ktor-client-content-negotiation:2.3.10")
|
||||
classpath("io.ktor:ktor-serialization-kotlinx-json:2.3.11")
|
||||
|
||||
// This comes from the changelog plugin
|
||||
// classpath("org.jetbrains:markdown:0.3.1")
|
||||
@@ -70,11 +69,11 @@ plugins {
|
||||
application
|
||||
id("java-test-fixtures")
|
||||
|
||||
id("org.jetbrains.intellij") version "1.17.1"
|
||||
id("org.jetbrains.intellij") version "1.17.3"
|
||||
id("org.jetbrains.changelog") version "2.2.0"
|
||||
|
||||
id("org.jetbrains.kotlinx.kover") version "0.6.1"
|
||||
id("com.dorongold.task-tree") version "2.1.1"
|
||||
id("com.dorongold.task-tree") version "3.0.0"
|
||||
|
||||
id("com.google.devtools.ksp") version "1.9.22-1.0.17"
|
||||
}
|
||||
@@ -142,14 +141,14 @@ dependencies {
|
||||
testFixturesImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion")
|
||||
|
||||
// https://mvnrepository.com/artifact/org.mockito.kotlin/mockito-kotlin
|
||||
testImplementation("org.mockito.kotlin:mockito-kotlin:5.2.1")
|
||||
testImplementation("org.mockito.kotlin:mockito-kotlin:5.3.1")
|
||||
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.1")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.1")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.1")
|
||||
testFixturesImplementation("org.junit.jupiter:junit-jupiter-api:5.10.1")
|
||||
testFixturesImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.1")
|
||||
testFixturesImplementation("org.junit.jupiter:junit-jupiter-params:5.10.1")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.2")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.2")
|
||||
testFixturesImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2")
|
||||
testFixturesImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.2")
|
||||
testFixturesImplementation("org.junit.jupiter:junit-jupiter-params:5.10.2")
|
||||
}
|
||||
|
||||
configurations {
|
||||
@@ -207,6 +206,11 @@ tasks {
|
||||
systemProperty("jb.privacy.policy.text", "<!--999.999-->")
|
||||
systemProperty("jb.consents.confirmation.enabled", "false")
|
||||
systemProperty("ide.show.tips.on.startup.default.value", "false")
|
||||
systemProperty("octopus.handler", System.getProperty("octopus.handler") ?: true)
|
||||
}
|
||||
|
||||
runIde {
|
||||
systemProperty("octopus.handler", System.getProperty("octopus.handler") ?: true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +264,6 @@ tasks {
|
||||
runPluginVerifier {
|
||||
downloadDir.set("${project.buildDir}/pluginVerifier/ides")
|
||||
teamCityOutputFormat.set(true)
|
||||
// ideVersions.set(listOf("IC-2021.3.4"))
|
||||
}
|
||||
|
||||
generateGrammarSource {
|
||||
@@ -305,26 +308,14 @@ tasks {
|
||||
from(createOpenApiSourceJar) { into("lib/src") }
|
||||
}
|
||||
|
||||
val pluginVersion = version
|
||||
patchPluginXml {
|
||||
// Don't forget to update plugin.xml
|
||||
patchPluginXml {
|
||||
// Get the latest available change notes from the changelog file
|
||||
changeNotes.set(
|
||||
provider {
|
||||
with(changelog) {
|
||||
val log = try {
|
||||
getUnreleased()
|
||||
} catch (e: MissingVersionException) {
|
||||
getOrNull(pluginVersion.toString()) ?: getLatest()
|
||||
}
|
||||
renderItem(
|
||||
log,
|
||||
org.jetbrains.changelog.Changelog.OutputType.HTML,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
sinceBuild.set("241.15989.150")
|
||||
|
||||
changeNotes.set(
|
||||
"""<a href="https://youtrack.jetbrains.com/issues/VIM?q=State:%20Fixed%20Fix%20versions:%20${version.get()}">Changelog</a>"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// --- Tests
|
||||
@@ -429,12 +420,14 @@ val prId: String by project
|
||||
|
||||
tasks.register("updateMergedPr") {
|
||||
doLast {
|
||||
if (project.hasProperty("prId")) {
|
||||
println("Got pr id: $prId")
|
||||
updateMergedPr(prId.toInt())
|
||||
} else {
|
||||
error("Cannot get prId")
|
||||
}
|
||||
val x = changelog.getUnreleased()
|
||||
println("x")
|
||||
// if (project.hasProperty("prId")) {
|
||||
// println("Got pr id: $prId")
|
||||
// updateMergedPr(prId.toInt())
|
||||
// } else {
|
||||
// error("Cannot get prId")
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -27,7 +27,7 @@ Plug 'nerdtree'
|
||||
### Preview
|
||||
|
||||
<details>
|
||||
<summary>Click to the the preview</summary>
|
||||
<summary>Click for the preview</summary>
|
||||
<img src="images/nerdtree.gif" alt="NERDTree example"/>
|
||||
</details>
|
||||
|
||||
|
@@ -1,140 +1,268 @@
|
||||
List of Supported Set Commands
|
||||
==============================
|
||||
List of Supported Options
|
||||
=========================
|
||||
|
||||
The following `:set` commands can appear in `~/.ideavimrc` or be set manually in the command mode:
|
||||
The following options can be set with the `:set`, `:setglobal` and `:setlocal` commands.
|
||||
They can be added to the `~/.ideavimrc` file, or set manually in Command-line mode.
|
||||
For more details of each option, please see the Vim documentation.
|
||||
Every effort is made to make these options compatible with Vim behaviour.
|
||||
However, some differences are inevitable.
|
||||
|
||||
'clipboard' 'cb' clipboard options
|
||||
Standard clipboard options plus
|
||||
```
|
||||
'clipboard' 'cb' Defines clipboard behavioue
|
||||
A comma-separated list of words to control clipboard behaviour:
|
||||
unnamed The clipboard register '*' is used instead of the
|
||||
unnamed register
|
||||
unnamedplus The clipboard register '+' is used instead of the
|
||||
unnamed register
|
||||
ideaput Uses the IDEs own paste implementation for put
|
||||
operations rather than simply inserting the text
|
||||
|
||||
'digraph' 'dg' Enable using <BS> to enter digraphs in Insert mode
|
||||
'gdefault' 'gd' The ":substitute" flag 'g' is by default
|
||||
'guicursor' 'gcr' Controls the shape of the cursor for different modes
|
||||
'history' 'hi' Number of command-lines that are remembered
|
||||
'hlsearch' 'hls' Highlight matches with the last search pattern
|
||||
'ignorecase' 'ic' Ignore case in search patterns
|
||||
'incsearch' 'is' Show where search pattern typed so far matches
|
||||
'iskeyword' 'isk' Defines keywords for commands like 'w', '*', etc.
|
||||
'keymodel' 'km' Controls selection behaviour with special keys
|
||||
List of comma separated words, which enable special things that keys
|
||||
can do. These values can be used:
|
||||
startsel Using a shifted special key starts selection (either
|
||||
Select mode or Visual mode, depending on "key" being
|
||||
present in 'selectmode')
|
||||
stopsel Using a NOT-shifted special key stops selection.
|
||||
Automatically enables `stopselect` and `stopvisual`
|
||||
stopselect Using a NOT-shifted special key stops select mode
|
||||
and removes selection - IdeaVim ONLY
|
||||
stopvisual Using a NOT-shifted special key stops visual mode
|
||||
and removes selection - IdeaVim ONLY
|
||||
continueselect Using a shifted arrow key doesn't start selection,
|
||||
but in select mode acts like startsel is enabled
|
||||
- IdeaVim ONLY
|
||||
continuevisual Using a shifted arrow key doesn't start selection,
|
||||
but in visual mode acts like startsel is enabled
|
||||
- IdeaVim ONLY
|
||||
|
||||
`ideaput` (default on) - IdeaVim ONLY
|
||||
enable native idea paste action for put operations
|
||||
|
||||
'digraph' 'dg' enable the entering of digraphs in Insert mode
|
||||
'gdefault' 'gd' the ":substitute" flag 'g' is by default
|
||||
'history' 'hi' number of command-lines that are remembered
|
||||
'hlsearch' 'hls' highlight matches with the last search pattern
|
||||
'ignorecase' 'ic' ignore case in search patterns
|
||||
'iskeyword' 'isk' defines keywords for commands like 'w', '*', etc.
|
||||
'incsearch' 'is' show where search pattern typed so far matches
|
||||
|
||||
`keymodel` `km` String (default "continueselect,stopselect")
|
||||
Special keys in this context are the cursor keys, <End>, <Home>,
|
||||
<PageUp> and <PageDown>.
|
||||
|
||||
List of comma separated words, which enable special things that keys
|
||||
can do. These values can be used:
|
||||
startsel Using a shifted special[1] key starts selection (either
|
||||
Select mode or Visual mode, depending on "key" being
|
||||
present in 'selectmode').
|
||||
stopsel Using a NOT-shifted special[1] key stops selection.
|
||||
Automatically enables `stopselect` and `stopvisual`
|
||||
stopselect Using a NOT-shifted special[1] key stops - IdeaVim ONLY
|
||||
select mode and removes selection.
|
||||
stopvisual Using a NOT-shifted special[1] key stops - IdeaVim ONLY
|
||||
visual mode and removes selection.
|
||||
continueselect Using a shifted arrow key doesn't - IdeaVim ONLY
|
||||
start selection, but in select mode
|
||||
acts like startsel is enabled
|
||||
continuevisual Using a shifted arrow key doesn't - IdeaVim ONLY
|
||||
start selection, but in visual mode
|
||||
acts like startsel is enabled
|
||||
|
||||
'matchpairs' 'mps' pairs of characters that "%" can match
|
||||
'maxmapdepth' 'mmd' Maximum depth of mappings
|
||||
'more' 'more' When on, listings pause when the whole screen is filled.
|
||||
'nrformats' 'nf' number formats recognized for CTRL-A command
|
||||
'number' 'nu' print the line number in front of each line
|
||||
'relativenumber' 'rnu' show the line number relative to the line with
|
||||
the cursor
|
||||
'scroll' 'scr' lines to scroll with CTRL-U and CTRL-D
|
||||
'scrolljump' 'sj' minimum number of lines to scroll
|
||||
'scrolloff' 'so' minimum number of lines above and below the cursor
|
||||
'selection' 'sel' what type of selection to use
|
||||
'matchpairs' 'mps' Pairs of characters that "%" can match
|
||||
'maxmapdepth' 'mmd' Maximum depth of mappings
|
||||
'more' 'more' When on, listings pause when the whole screen is filled
|
||||
'nrformats' 'nf' Number formats recognized for CTRL-A command
|
||||
'operatorfunc' 'opfunc' Name of a function to call with the g@ operator
|
||||
'scroll' 'scr' Number of lines to scroll with CTRL-U and CTRL-D
|
||||
'selection' 'sel' What type of selection to use
|
||||
'selectmode' 'slm' Controls when to start Select mode instead of Visual
|
||||
This is a comma-separated list of words:
|
||||
|
||||
mouse When using the mouse
|
||||
key When using shifted special[1] keys
|
||||
cmd When using "v", "V", or <C-V>
|
||||
ideaselection When IDE sets a selection - IdeaVim ONLY
|
||||
(e.g.: extend selection, wrap with while, etc.)
|
||||
|
||||
`selectmode` `slm` String (default "")
|
||||
'shell' 'sh' The shell to use to execute commands with ! and :!
|
||||
'shellcmdflag' 'shcf' The command flag passed to the shell
|
||||
'shellxescape' 'sxe' The characters to be escaped when calling a shell
|
||||
'shellxquote' 'sxq' The quote character to use in a shell command
|
||||
'showcmd' 'sc' Show (partial) command in the status bar
|
||||
'showmode' 'smd' Show the current mode in the status bar
|
||||
'smartcase' 'scs' Use case sensitive search if any character in the
|
||||
pattern is uppercase
|
||||
'startofline' 'sol' When on, some commands move the cursor to the first
|
||||
non-blank of the line
|
||||
When off, the cursor is kept in the same column
|
||||
(if possible)
|
||||
'timeout' 'to' Use timeout for mapped key sequences
|
||||
'timeoutlen' 'tm' Timeout duration for a mapped key sequence
|
||||
'viminfo' 'vi' Information to remember after restart
|
||||
'virtualedit' 've' Placement of the cursor where there is no actual text
|
||||
A comma-separated list of these words:
|
||||
block Allow virtual editing in Visual mode (not supported)
|
||||
insert Allow virtual editing in Insert mode (not supported)
|
||||
all Allow virtual editing in all modes (not supported)
|
||||
onemore Allow the cursor to move just past the end of the line
|
||||
|
||||
This is a comma-separated list of words, which specify when to start
|
||||
Select mode instead of Visual mode, when a selection is started.
|
||||
Possible values:
|
||||
mouse when using the mouse
|
||||
key when using shifted special[1] keys
|
||||
cmd when using "v", "V", or <C-V>
|
||||
ideaselection when IDE sets a selection - IdeaVim ONLY
|
||||
(examples: extend selection, wrap with while, etc.)
|
||||
'visualbell' 'vb' When on, prevents beeping on error
|
||||
'whichwrap' 'ww' Which keys that move the cursor left/right can wrap to
|
||||
other lines
|
||||
A comma-separated list of these flags:
|
||||
char key modes
|
||||
b <BS> Normal and Visual
|
||||
s <Space> Normal and Visual
|
||||
h "h" Normal and Visual
|
||||
l "l" Normal and Visual
|
||||
< <Left> Normal and Visual
|
||||
> <Right> Normal and Visual
|
||||
~ "~" Normal
|
||||
[ <Left> Insert and Replace
|
||||
] <Right> Insert and Replace
|
||||
|
||||
`startofline` `sol` When "on" some commands move the cursor to the first non-blank of the line.
|
||||
When off the cursor is kept in the same column (if possible).
|
||||
'wrapscan' 'ws' Search will wrap around the end of file
|
||||
```
|
||||
|
||||
'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
|
||||
'timeout' 'to' use timeout for mapped key sequences
|
||||
'timeoutlen' 'tm' timeout duration for a mapped key sequence
|
||||
'undolevels' 'ul' maximum number of changes that can be undone
|
||||
'viminfo' 'vi' information to remember after restart
|
||||
'visualbell' 'vb' use visual bell instead of beeping
|
||||
'wrapscan' 'ws' searches wrap around the end of file
|
||||
|
||||
|
||||
|
||||
IdeaVim only commands:
|
||||
## IdeaVim options mapped to IntelliJ-based IDE settings
|
||||
|
||||
`ideamarks` `ideamarks` Boolean (default true)
|
||||
|
||||
If true, creation of global mark will trigger creation of IDE's bookmark
|
||||
and vice versa.
|
||||
|
||||
`idearefactormode` `idearefactormode` String(default "select")
|
||||
|
||||
Define the mode that would be enabled during
|
||||
the refactoring (renaming, live template, introduce variable, etc)
|
||||
|
||||
Use one of the following values:
|
||||
- keep - keep the mode that was enabled before starting a refactoring
|
||||
- select - start refactoring in select mode
|
||||
- visual - start refactoring in visual mode
|
||||
|
||||
This option has effect if you are in normal, insert or replace mode before refactoring start.
|
||||
Visual or select mode are not changed.
|
||||
|
||||
|
||||
`ideajoin` `ideajoin` Boolean (default false)
|
||||
|
||||
If true, join command will be performed via IDE
|
||||
See wiki/`ideajoin` examples
|
||||
|
||||
`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
|
||||
IdeaVim provides its own implementation for handling scroll jump and offset, even though IntelliJ-based IDEs have similar functionality (there are differences in behaviour).
|
||||
When IdeaVim is hosted in an IntelliJ-based IDE (but not JetBrains Fleet), the following options map to the equivalent IDE settings:
|
||||
|
||||
`ideawrite` `ideawrite` String (default "all")
|
||||
"file" or "all". Defines the behaviour of ":w" command.
|
||||
Value "all" enables execution of ":wa" (save all) command on ":w" (save).
|
||||
This feature exists because some IJ options like "Prettier on save" or "ESlint on save"
|
||||
work only with "save all" action. If this option is set to "all", these actions work
|
||||
also with ":w" command.
|
||||
|
||||
`lookupkeys` `lookupkeys` List of strings
|
||||
|
||||
List of keys that should be processed by the IDE during the active lookup (autocompletion).
|
||||
For example, <Tab> and <Enter> are used by the IDE to finish the lookup,
|
||||
but <C-W> should be passed to IdeaVim.
|
||||
Default value:
|
||||
"<Tab>", "<Down>", "<Up>", "<Enter>", "<Left>", "<Right>",
|
||||
"<C-Down>", "<C-Up>", "<PageUp>", "<PageDown>",
|
||||
"<C-J>", "<C-Q>"
|
||||
|
||||
`ideavimsupport` `ideavimsupport` List of strings (default "dialog")
|
||||
|
||||
Define the list of additional buffers where IdeaVim is enabled.
|
||||
|
||||
- dialog - enable IdeaVim in dialogs
|
||||
- singleline - enable IdeaVim in single line editors (not suggested)
|
||||
```
|
||||
'scrolljump' 'sj' Minimal number of lines to scroll
|
||||
'scrolloff' 'so' Minimal number of lines above and below the cursor
|
||||
'sidescroll' 'ss' Minimal number of columns to scroll horizontally
|
||||
'sidescrolloff' 'siso' Minimal number of columns to left and right of cursor
|
||||
```
|
||||
|
||||
----------
|
||||
[1] - cursor keys, <End>, <Home>, <PageUp> and <PageDown>
|
||||
## IdeaVim options for IntelliJ-based IDE features
|
||||
|
||||
Some Vim features cannot be implemented by IdeaVim, and must be implemented by the host IDE, such as showing whitespace and line numbers, and enabling soft-wrap.
|
||||
The following options modify equivalent settings and features implemented by IntelliJ-based IDEs.
|
||||
|
||||
There is some mismatch when trying to map Vim options, most of which are local options, to IDE settings, which are mostly global-local.
|
||||
The Vim option will always reflect the effective value of the IDE setting for the current editor, and modifying the Vim option will update the local value of the IDE setting.
|
||||
The default value of the Vim option set during startup is not passed to the IDE setting.
|
||||
|
||||
If the IDE setting has a way to modify the local value, such as entries in the _View | Active Editor_ menu, then changing this will update the current editor and be reflected in the Vim option value.
|
||||
If the IDE setting can only modify its global setting in the main _Settings_ dialog, this change does not always update the current editor (because the local IDE setting has been modified and takes precedence).
|
||||
|
||||
IdeaVim tries to make this work more naturally by updating the editor and local Vim option when a global value changes unless the Vim option has been explicitly set in Command-line mode.
|
||||
|
||||
In other words, if the local Vim value is explicitly set for a window or buffer, interactively, then it should not be reset.
|
||||
If the Vim option was explicitly set in `~/.ideavimrc` however, then the value will be reset, because this can be viewed as a "global" value - set once and applied to subsequently opened windows.
|
||||
(This should not be confused with Vim's concept of global options, which are mainly used to initialise new windows.)
|
||||
|
||||
The local Vim option can always be reset to the global IDE setting value by resetting the Vim option to default with the `:set {option}&` syntax.
|
||||
|
||||
```
|
||||
'bomb' 'bomb' Add or remove a byte order mark (BOM) to the
|
||||
current file. Unlike Vim, the file is modified
|
||||
immediately, and not when saved
|
||||
'breakindent' 'bri' Indent soft wrapped lines to match the first
|
||||
line's indent
|
||||
'colorcolumn' 'cc' Maps to IntelliJ's visual guide columns
|
||||
'cursorline' 'cul' Highlight the line containing the cursor
|
||||
'fileencoding' 'fenc' Change the encoding of the current file. The file
|
||||
is modified and written immediately, rather than
|
||||
waiting to be saved
|
||||
Note that the names of the encoding might not
|
||||
match Vim's known names
|
||||
'fileformat' 'ff' Change the file format - dos, unix or mac
|
||||
The file is modified immediately, rather than
|
||||
when saved
|
||||
'list' 'list' Show whitespace. Maps to the editor's local
|
||||
setting in the View | Active Editor menu
|
||||
'number' 'nu' Show line numbers. Maps to the editor's local
|
||||
setting in the View | Active Editor menu
|
||||
'relativenumber' 'rnu' Show line numbers relative to the current line
|
||||
'textwidth' 'tw' Set the column at which text is automatically
|
||||
wrapped
|
||||
'wrap' 'wrap' Enable soft-wraps. Maps to the editor's local
|
||||
setting in the View | Active Editor menu
|
||||
```
|
||||
|
||||
## IdeaVim only options
|
||||
|
||||
These options are IdeaVim only, and not supported by Vim.
|
||||
They control integration with the host IDE.
|
||||
Unless otherwise stated, these options do not have abbreviations.
|
||||
|
||||
```
|
||||
'ideacopypreprocess' boolean (default off)
|
||||
global or local to buffer
|
||||
When enabled, the IDE will run custom copy pre-processors over text
|
||||
copied to registers. These pre-processors can perform transformations
|
||||
on the text, such as converting escape characters in a string literal
|
||||
into the actual control characters in a Java file.
|
||||
|
||||
This is not usually the expected behaviour, so this option's default
|
||||
value is off. The equivalent processing for paste is controlled by the
|
||||
"ideaput" value to the 'clipboard' option.
|
||||
|
||||
'ideaglobalmode' boolean (default off)
|
||||
global
|
||||
This option will cause IdeaVim to share a single mode across all open
|
||||
windows. In other words, entering Insert mode in one window will
|
||||
enable Insert mode in all windows.
|
||||
|
||||
'ideajoin' boolean (default off)
|
||||
global or local to buffer
|
||||
When enabled, join commands will be handled by the IDE's "smart join"
|
||||
feature. The IDE can change syntax when joining lines, such as merging
|
||||
string literals or if statements. See the wiki for more examples. Not
|
||||
all languages support smart join functionality.
|
||||
|
||||
'ideamarks' boolean (default on)
|
||||
global
|
||||
Maps Vim's global marks to IDE bookmarks.
|
||||
|
||||
'idearefactormode' string (default "select")
|
||||
global or local to buffer
|
||||
Specifies the mode to be used when a refactoring selects text to be
|
||||
edited (e.g. renaming, live template fields, introduce variable, etc):
|
||||
keep Keep the current mode
|
||||
select Switch to Select mode
|
||||
visual Switch to Visual mode
|
||||
|
||||
This option is only used when the refactoring is started in Normal,
|
||||
Insert or Replace mode. Visual or Select modes are not changed.
|
||||
|
||||
'ideastatusicon' string (default "enabled")
|
||||
global
|
||||
This option controls the behaviour and appearance of the IdeaVim icon
|
||||
in the status bar:
|
||||
enabled Show the icon in the status bar
|
||||
gray Show the gray version of the icon
|
||||
disabled Hide the icon
|
||||
|
||||
'ideavimsupport' string (default "dialog")
|
||||
global
|
||||
A comma-separated list of additional buffers or locations where
|
||||
IdeaVim should be enabled:
|
||||
dialog Enable IdeaVim in editors hosted in dialogs
|
||||
singleline Enable IdeaVim in single line editors (not recommended)
|
||||
|
||||
The IDE's editor component can be used in many places, such as VCS
|
||||
commit tool window, or inside dialogs, and even as single line fields.
|
||||
|
||||
'ideawrite' string (default "all")
|
||||
global
|
||||
This option defines the behaviour of the :w command:
|
||||
file Save the current file only
|
||||
all The :w command works like :wa and invokes the Save All
|
||||
IDE action. This allows options such as "Prettier on
|
||||
save" or "ESlint on save" to work with the :w command,
|
||||
but means all files are saved.
|
||||
|
||||
'lookupkeys' string (default "<Tab>,<Down>,<Up>,<Enter>,
|
||||
<Left>,<Right>,<C-Down>,<C-Up>,
|
||||
<PageUp>,<PageDown>, <C-J>,<C-Q>")
|
||||
global
|
||||
Comma-separated list of keys that should be processed by the IDE while
|
||||
a code completion lookup popup is active. For example, <Tab> and
|
||||
<Enter> are used by the IDE to complete the lookup and insert text,
|
||||
but <C-W> should be passed IdeaVim to continue editing the text.
|
||||
|
||||
'trackactionids' boolean (default off)
|
||||
global
|
||||
When on, IdeaVim will try to track the current IDE action and display
|
||||
the action name in a notification. This action ID can then be used in
|
||||
a mapping to the action in the form <Action>(...).
|
||||
|
||||
'visualdelay' number (default 100)
|
||||
global
|
||||
This option specifies the delay, in milliseconds before converting an
|
||||
IDE selection into Visual mode.
|
||||
|
||||
Some IDE features make a selection to help modify text (e.g. backspace
|
||||
in Python or Yaml selects an indent and invokes the "remove selection"
|
||||
action). IdeaVim listens for changes in selection to switch to Visual
|
||||
mode, and will return to Normal mode when the selection is removed,
|
||||
even if originally in Insert mode.
|
||||
|
||||
By waiting before converting to Visual mode, temporary selections can
|
||||
be ignored and the current Vim mode maintained.
|
||||
|
||||
It is not expected that this value will need to be changed.
|
||||
```
|
||||
|
@@ -8,12 +8,13 @@
|
||||
|
||||
# suppress inspection "UnusedProperty" for whole file
|
||||
|
||||
ideaVersion=2023.3.3
|
||||
#ideaVersion=LATEST-EAP-SNAPSHOT
|
||||
ideaVersion=2024.1.1
|
||||
# Values for type: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#intellij-extension-type
|
||||
ideaType=IC
|
||||
downloadIdeaSources=true
|
||||
instrumentPluginCode=true
|
||||
version=chylex-28
|
||||
version=chylex-35
|
||||
javaVersion=17
|
||||
remoteRobotVersion=0.11.22
|
||||
antlrVersion=4.10.1
|
||||
@@ -28,7 +29,7 @@ publishChannels=eap
|
||||
|
||||
# Kotlinx serialization also uses some version of kotlin stdlib under the hood. However,
|
||||
# we exclude this version from the dependency and use our own version of kotlin that is specified above
|
||||
kotlinxSerializationVersion=1.5.1
|
||||
kotlinxSerializationVersion=1.6.2
|
||||
|
||||
slackUrl=
|
||||
youtrackToken=
|
||||
|
99092
qodana.sarif.json
99092
qodana.sarif.json
File diff suppressed because one or more lines are too long
@@ -21,6 +21,9 @@ exclude:
|
||||
- src/test/java/org/jetbrains/plugins/ideavim/propertybased/samples/SimpleText.kt
|
||||
- src/main/java/com/maddyhome/idea/vim/vimscript/parser/generated
|
||||
- src/main/java/com/maddyhome/idea/vim/package-info.java
|
||||
- vim-engine/src/main/java/com/maddyhome/idea/vim/regexp/parser/generated
|
||||
- src/main/java/com/maddyhome/idea/vim/group/SearchGroup.java
|
||||
- tests/ui-fixtures
|
||||
dependencyIgnores:
|
||||
- name: "acejump"
|
||||
- name: "icu4j"
|
||||
|
@@ -20,17 +20,17 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.9.22")
|
||||
compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.9.24")
|
||||
|
||||
implementation("io.ktor:ktor-client-core:2.3.7")
|
||||
implementation("io.ktor:ktor-client-cio:2.3.7")
|
||||
implementation("io.ktor:ktor-client-content-negotiation:2.3.7")
|
||||
implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.7")
|
||||
implementation("io.ktor:ktor-client-auth:2.3.7")
|
||||
implementation("io.ktor:ktor-client-core:2.3.11")
|
||||
implementation("io.ktor:ktor-client-cio:2.3.10")
|
||||
implementation("io.ktor:ktor-client-content-negotiation:2.3.10")
|
||||
implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.11")
|
||||
implementation("io.ktor:ktor-client-auth:2.3.11")
|
||||
implementation("org.eclipse.jgit:org.eclipse.jgit:6.6.0.202305301015-r")
|
||||
|
||||
// This is needed for jgit to connect to ssh
|
||||
implementation("org.eclipse.jgit:org.eclipse.jgit.ssh.apache:6.8.0.202311291450-r")
|
||||
implementation("org.eclipse.jgit:org.eclipse.jgit.ssh.apache:6.9.0.202403050737-r")
|
||||
implementation("com.vdurmont:semver4j:3.1.0")
|
||||
}
|
||||
|
||||
@@ -58,13 +58,6 @@ tasks.register("checkNewPluginDependencies", JavaExec::class) {
|
||||
classpath = sourceSets["main"].runtimeClasspath
|
||||
}
|
||||
|
||||
tasks.register("updateAffectedRates", JavaExec::class) {
|
||||
group = "verification"
|
||||
description = "This job updates Affected Rate field on YouTrack"
|
||||
mainClass.set("scripts.YouTrackUsersAffectedKt")
|
||||
classpath = sourceSets["main"].runtimeClasspath
|
||||
}
|
||||
|
||||
tasks.register("calculateNewVersion", JavaExec::class) {
|
||||
group = "release"
|
||||
mainClass.set("scripts.release.CalculateNewVersionKt")
|
||||
@@ -114,6 +107,13 @@ tasks.register("calculateNewEapVersion", JavaExec::class) {
|
||||
args = listOf("${rootProject.rootDir}")
|
||||
}
|
||||
|
||||
tasks.register("calculateNewEapVersionFromBranch", JavaExec::class) {
|
||||
group = "release"
|
||||
mainClass.set("scripts.release.CalculateNewEapVersionFromBranchKt")
|
||||
classpath = sourceSets["main"].runtimeClasspath
|
||||
args = listOf("${rootProject.rootDir}")
|
||||
}
|
||||
|
||||
tasks.register("calculateNewDevVersion", JavaExec::class) {
|
||||
group = "release"
|
||||
mainClass.set("scripts.release.CalculateNewDevVersionKt")
|
||||
|
@@ -22,7 +22,7 @@ import kotlinx.serialization.json.jsonPrimitive
|
||||
*/
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
val knownPlugins = listOf(
|
||||
val knownPlugins = setOf(
|
||||
"IdeaVimExtension",
|
||||
"github.zgqq.intellij-enhance",
|
||||
"org.jetbrains.IdeaVim-EasyMotion",
|
||||
@@ -31,7 +31,12 @@ val knownPlugins = listOf(
|
||||
"com.github.copilot",
|
||||
"com.github.dankinsoid.multicursor",
|
||||
"com.joshestein.ideavim-quickscope",
|
||||
|
||||
"ca.alexgirard.HarpoonIJ",
|
||||
"me.kyren223.harpoonforjb", // https://plugins.jetbrains.com/plugin/23771-harpoonforjb
|
||||
"com.github.erotourtes.harpoon", // https://plugins.jetbrains.com/plugin/21796-harpooner
|
||||
"me.kyren223.trident", // https://plugins.jetbrains.com/plugin/23818-trident
|
||||
|
||||
"com.protoseo.input-source-auto-converter",
|
||||
|
||||
// "cc.implicated.intellij.plugins.bunny", // I don't want to include this plugin in the list of IdeaVim plugins as I don't understand what this is for
|
||||
@@ -42,19 +47,15 @@ suspend fun main() {
|
||||
parameter("dependency", "IdeaVIM")
|
||||
parameter("includeOptional", true)
|
||||
}
|
||||
val output = response.body<List<String>>()
|
||||
val output = response.body<List<String>>().toSet()
|
||||
println(output)
|
||||
if (knownPlugins != output) {
|
||||
val newPlugins = (output - knownPlugins).map { it to (getPluginLinkByXmlId(it) ?: "Can't find plugin link") }
|
||||
val removedPlugins = (knownPlugins - output.toSet()).map { it to (getPluginLinkByXmlId(it) ?: "Can't find plugin link") }
|
||||
val newPlugins = (output - knownPlugins).map { it to (getPluginLinkByXmlId(it) ?: "Can't find plugin link") }
|
||||
if (newPlugins.isNotEmpty()) {
|
||||
// val removedPlugins = (knownPlugins - output.toSet()).map { it to (getPluginLinkByXmlId(it) ?: "Can't find plugin link") }
|
||||
error(
|
||||
"""
|
||||
|
||||
Unregistered plugins:
|
||||
${if (newPlugins.isNotEmpty()) newPlugins.joinToString(separator = "\n") { it.first + "(" + it.second + ")" } else "No unregistered plugins"}
|
||||
|
||||
Removed plugins:
|
||||
${if (removedPlugins.isNotEmpty()) removedPlugins.joinToString(separator = "\n") { it.first + "(" + it.second + ")" } else "No removed plugins"}
|
||||
${newPlugins.joinToString(separator = "\n") { it.first + "(" + it.second + ")" }}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
@@ -8,6 +8,12 @@
|
||||
|
||||
package scripts.release
|
||||
|
||||
import org.eclipse.jgit.lib.ObjectId
|
||||
import org.eclipse.jgit.revwalk.RevCommit
|
||||
import org.eclipse.jgit.revwalk.RevWalk
|
||||
import org.eclipse.jgit.revwalk.filter.RevFilter
|
||||
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println("HI!")
|
||||
val projectDir = args[0]
|
||||
@@ -19,10 +25,12 @@ fun main(args: Array<String>) {
|
||||
check(branch == "master") {
|
||||
"We should be on master branch"
|
||||
}
|
||||
val mergeBaseCommit = getMergeBaseWithMaster(projectDir, objectId)
|
||||
println("Base commit $mergeBaseCommit")
|
||||
withGit(projectDir) { git ->
|
||||
val log = git.log().setMaxCount(500).call().toList()
|
||||
println("First commit hash in log: " + log.first().name + " log size: ${log.size}")
|
||||
val logDiff = log.takeWhile { it.id.name != objectId.name }
|
||||
val logDiff = log.takeWhile { it.id.name != mergeBaseCommit }
|
||||
val numCommits = logDiff.size
|
||||
println("Log diff size is $numCommits")
|
||||
check(numCommits < 450) {
|
||||
@@ -35,3 +43,18 @@ fun main(args: Array<String>) {
|
||||
println("##teamcity[setParameter name='env.ORG_GRADLE_PROJECT_version' value='$nextVersion']")
|
||||
}
|
||||
}
|
||||
|
||||
private fun getMergeBaseWithMaster(projectDir: String, tag: ObjectId): String {
|
||||
withRepo(projectDir) { repo ->
|
||||
val master = repo.resolve("master")
|
||||
RevWalk(repo).use { walk ->
|
||||
val tagRevCommit = walk.parseCommit(tag)
|
||||
val masterRevCommit = walk.parseCommit(master)
|
||||
walk.setRevFilter(RevFilter.MERGE_BASE)
|
||||
walk.markStart(tagRevCommit)
|
||||
walk.markStart(masterRevCommit)
|
||||
val mergeBase: RevCommit = walk.next()
|
||||
return mergeBase.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2003-2023 The IdeaVim authors
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE.txt file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
package scripts.release
|
||||
|
||||
fun main(args: Array<String> ) {
|
||||
val projectDir = args[0]
|
||||
println("Working directory: $projectDir")
|
||||
val branch = withRepo(projectDir) { it.branch }
|
||||
val (majorBranchVersion, minorBranchVersion) = versions(branch)
|
||||
val versions = getVersionsExistingVersionsFor(majorBranchVersion, minorBranchVersion, projectDir)
|
||||
val maxExistingVersion = versions.keys.maxOrNull()
|
||||
|
||||
val nextVersion = if (maxExistingVersion != null) {
|
||||
if (maxExistingVersion.suffixTokens.isEmpty()) {
|
||||
maxExistingVersion.nextPatch().withSuffix("eap.1").value
|
||||
}
|
||||
else {
|
||||
check(maxExistingVersion.suffixTokens.size == 2) {
|
||||
"We should have exactly two suffix tokens. Current tokens: ${maxExistingVersion.suffixTokens.toList()}"
|
||||
}
|
||||
check(maxExistingVersion.suffixTokens[0] == "eap") {
|
||||
"First suffix token must be eap. Current tokens: ${maxExistingVersion.suffixTokens.toList()}"
|
||||
}
|
||||
|
||||
val newEapNumber = maxExistingVersion.suffixTokens[1].toInt().inc()
|
||||
maxExistingVersion.withSuffix("eap.$newEapNumber").value
|
||||
}
|
||||
} else {
|
||||
"$majorBranchVersion.$minorBranchVersion.0-eap.1"
|
||||
}
|
||||
|
||||
|
||||
println("Next eap version: $nextVersion")
|
||||
println("##teamcity[setParameter name='env.ORG_GRADLE_PROJECT_version' value='$nextVersion']")
|
||||
}
|
||||
|
||||
private val regex = "releases/(\\d+)\\.(\\d+)\\.x".toRegex()
|
||||
private fun versions(branchName: String): Pair<Int, Int> {
|
||||
val match = regex.matchEntire(branchName) ?: error("Cannot match branch: $branchName")
|
||||
val major = match.groups[1]
|
||||
val minor = match.groups[2]
|
||||
return major!!.value.toInt() to minor!!.value.toInt()
|
||||
}
|
@@ -64,6 +64,31 @@ enum class ReleaseType {
|
||||
STABLE_NO_PATCH, // Version that ends on 0. Like 2.5.0
|
||||
}
|
||||
|
||||
internal fun getVersionsExistingVersionsFor(
|
||||
majorVersion: Int,
|
||||
minorVersion: Int,
|
||||
projectDir: String,
|
||||
): Map<Semver, ObjectId> {
|
||||
val repository = RepositoryBuilder().setGitDir(File("$projectDir/.git")).build()
|
||||
val git = Git(repository)
|
||||
println(git.log().call().first())
|
||||
println(git.tagList().call().first())
|
||||
|
||||
return git.tagList().call().mapNotNull { ref ->
|
||||
runCatching {
|
||||
// Git has two types of tags: light and annotated. This code detect hash of the commit for both types of tags
|
||||
val revWalk = RevWalk(repository)
|
||||
val tag = revWalk.parseAny(ref.objectId)
|
||||
val commitHash = revWalk.peel(tag).id
|
||||
val semver = Semver(ref.name.removePrefix("refs/tags/"))
|
||||
if (semver.major == majorVersion && semver.minor == minorVersion) {
|
||||
semver to commitHash
|
||||
} else null
|
||||
}.getOrNull()
|
||||
}
|
||||
.toMap()
|
||||
}
|
||||
|
||||
internal fun getVersion(projectDir: String, releaseType: ReleaseType): Pair<Semver, ObjectId> {
|
||||
val repository = RepositoryBuilder().setGitDir(File("$projectDir/.git")).build()
|
||||
val git = Git(repository)
|
||||
|
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2023 The IdeaVim authors
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE.txt file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
package scripts
|
||||
|
||||
import io.ktor.client.call.*
|
||||
import kotlinx.serialization.json.JsonArray
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import kotlinx.serialization.json.put
|
||||
|
||||
val areaWeights = setOf(
|
||||
Triple("118-53212", "Plugins", 50),
|
||||
Triple("118-53220", "Vim Script", 30),
|
||||
Triple("118-54084", "Esc", 100),
|
||||
)
|
||||
|
||||
suspend fun updateRates() {
|
||||
println("Updating rates of the issues")
|
||||
areaWeights.forEach { (id, name, weight) ->
|
||||
val unmappedIssues = unmappedIssues(name)
|
||||
println("Got ${unmappedIssues.size} for $name area")
|
||||
|
||||
unmappedIssues.forEach { issueId ->
|
||||
print("Trying to update issue $issueId: ")
|
||||
val response = updateCustomField(issueId) {
|
||||
put("name", "Affected Rate")
|
||||
put("\$type", "SimpleIssueCustomField")
|
||||
put("value", weight)
|
||||
}
|
||||
|
||||
println(response)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun unmappedIssues(area: String): List<String> {
|
||||
val areaProcessed = if (" " in area) "{$area}" else area
|
||||
val res = issuesQuery(
|
||||
query = "project: VIM Affected Rate: {No affected rate} Area: $areaProcessed #Unresolved",
|
||||
fields = "id,idReadable"
|
||||
)
|
||||
return res.body<JsonArray>().map { it.jsonObject }.map { it["idReadable"]!!.jsonPrimitive.content }
|
||||
}
|
||||
|
||||
suspend fun getAreasWithoutWeight(): Set<Pair<String, String>> {
|
||||
val allAreas = getAreaValues()
|
||||
return allAreas
|
||||
.filterNot { it.key in areaWeights.map { it.first }.toSet() }
|
||||
.entries
|
||||
.map { it.key to it.value }
|
||||
.toSet()
|
||||
}
|
||||
|
||||
suspend fun main() {
|
||||
updateRates()
|
||||
}
|
@@ -101,10 +101,14 @@ command:
|
||||
(WS | COLON)* range? (WS | COLON)* EXECUTE WS* (expr WS*)* (NEW_LINE | BAR)+
|
||||
#ExecuteCommand|
|
||||
|
||||
(WS | COLON)* range? (WS | COLON)* lShift (WS* commandArgument = ~(NEW_LINE | BAR)+)? ((inline_comment NEW_LINE+) | (NEW_LINE | BAR)+)
|
||||
(WS | COLON)* range? (WS | COLON)* lShift
|
||||
WS* ((commandArgumentWithoutBars? inline_comment NEW_LINE) | (commandArgumentWithoutBars? NEW_LINE) | (commandArgumentWithoutBars? BAR))
|
||||
(NEW_LINE | BAR)*
|
||||
#ShiftLeftCommand|
|
||||
|
||||
(WS | COLON)* range? (WS | COLON)* rShift (WS* commandArgument = ~(NEW_LINE | BAR)+)? ((inline_comment NEW_LINE+) | (NEW_LINE | BAR)+)
|
||||
(WS | COLON)* range? (WS | COLON)* rShift
|
||||
WS* ((commandArgumentWithoutBars? inline_comment NEW_LINE) | (commandArgumentWithoutBars? NEW_LINE) | (commandArgumentWithoutBars? BAR))
|
||||
(NEW_LINE | BAR)*
|
||||
#ShiftRightCommand|
|
||||
|
||||
(WS | COLON)* range? (WS | COLON)*
|
||||
@@ -824,4 +828,4 @@ AUGROUP_SKIP: NEW_LINE (WS|COLON)* AUGROUP .*? AUGROUP WS+ END -> skip
|
||||
|
||||
// All the other symbols
|
||||
UNICODE_CHAR: '\u0000'..'\uFFFE';
|
||||
EMOJI: [\p{Emoji}];
|
||||
EMOJI: [\p{Emoji}];
|
||||
|
@@ -11,7 +11,6 @@ package com.maddyhome.idea.vim;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.ShortcutSet;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.EditorFactory;
|
||||
import com.intellij.openapi.editor.actionSystem.TypedAction;
|
||||
@@ -80,14 +79,6 @@ public class EventFacade {
|
||||
action.unregisterCustomShortcutSet(component);
|
||||
}
|
||||
|
||||
public void addDocumentListener(@NotNull Document document, @NotNull DocumentListener listener) {
|
||||
document.addDocumentListener(listener);
|
||||
}
|
||||
|
||||
public void removeDocumentListener(@NotNull Document document, @NotNull DocumentListener listener) {
|
||||
document.removeDocumentListener(listener);
|
||||
}
|
||||
|
||||
public void addEditorFactoryListener(@NotNull EditorFactoryListener listener, @NotNull Disposable parentDisposable) {
|
||||
EditorFactory.getInstance().addEditorFactoryListener(listener, parentDisposable);
|
||||
}
|
||||
@@ -98,20 +89,12 @@ public class EventFacade {
|
||||
editor.getCaretModel().addCaretListener(listener, disposable);
|
||||
}
|
||||
|
||||
public void removeCaretListener(@NotNull Editor editor, @NotNull CaretListener listener) {
|
||||
editor.getCaretModel().removeCaretListener(listener);
|
||||
}
|
||||
|
||||
public void addEditorMouseListener(@NotNull Editor editor,
|
||||
@NotNull EditorMouseListener listener,
|
||||
@NotNull Disposable disposable) {
|
||||
editor.addEditorMouseListener(listener, disposable);
|
||||
}
|
||||
|
||||
public void removeEditorMouseListener(@NotNull Editor editor, @NotNull EditorMouseListener listener) {
|
||||
editor.removeEditorMouseListener(listener);
|
||||
}
|
||||
|
||||
public void addComponentMouseListener(@NotNull Component component,
|
||||
@NotNull MouseListener mouseListener,
|
||||
@NotNull Disposable disposable) {
|
||||
@@ -119,30 +102,18 @@ public class EventFacade {
|
||||
Disposer.register(disposable, () -> component.removeMouseListener(mouseListener));
|
||||
}
|
||||
|
||||
public void removeComponentMouseListener(@NotNull Component component, @NotNull MouseListener mouseListener) {
|
||||
component.removeMouseListener(mouseListener);
|
||||
}
|
||||
|
||||
public void addEditorMouseMotionListener(@NotNull Editor editor,
|
||||
@NotNull EditorMouseMotionListener listener,
|
||||
@NotNull Disposable disposable) {
|
||||
editor.addEditorMouseMotionListener(listener, disposable);
|
||||
}
|
||||
|
||||
public void removeEditorMouseMotionListener(@NotNull Editor editor, @NotNull EditorMouseMotionListener listener) {
|
||||
editor.removeEditorMouseMotionListener(listener);
|
||||
}
|
||||
|
||||
public void addEditorSelectionListener(@NotNull Editor editor,
|
||||
@NotNull SelectionListener listener,
|
||||
@NotNull Disposable disposable) {
|
||||
editor.getSelectionModel().addSelectionListener(listener, disposable);
|
||||
}
|
||||
|
||||
public void removeEditorSelectionListener(@NotNull Editor editor, @NotNull SelectionListener listener) {
|
||||
editor.getSelectionModel().removeSelectionListener(listener);
|
||||
}
|
||||
|
||||
private @NotNull TypedAction getTypedAction() {
|
||||
return TypedAction.getInstance();
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ import com.intellij.openapi.project.ProjectManagerListener
|
||||
import com.intellij.openapi.startup.ProjectActivity
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.localEditors
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
|
||||
import com.maddyhome.idea.vim.newapi.globalIjOptions
|
||||
|
||||
/**
|
||||
@@ -36,8 +36,10 @@ internal class PluginStartup : ProjectActivity/*, LightEditCompatible*/ {
|
||||
// This is a temporal workaround for VIM-2487
|
||||
internal class PyNotebooksCloseWorkaround : ProjectManagerListener {
|
||||
override fun projectClosingBeforeSave(project: Project) {
|
||||
// TODO: Confirm context in CWM scenario
|
||||
if (injector.globalIjOptions().closenotebooks) {
|
||||
localEditors().forEach { editor ->
|
||||
injector.editorGroup.getEditors().forEach { vimEditor ->
|
||||
val editor = (vimEditor as IjVimEditor).editor
|
||||
val virtualFile = EditorHelper.getVirtualFile(editor)
|
||||
if (virtualFile?.extension == "ipynb") {
|
||||
val fileEditorManager = FileEditorManagerEx.getInstanceEx(project)
|
||||
|
@@ -21,7 +21,7 @@ public object RegisterActions {
|
||||
@JvmStatic
|
||||
public fun registerActions() {
|
||||
registerVimCommandActions()
|
||||
registerEmptyShortcuts() // todo most likely it is not needed
|
||||
registerShortcutsWithoutActions()
|
||||
}
|
||||
|
||||
public fun findAction(id: String): EditorActionHandlerBase? {
|
||||
@@ -46,12 +46,11 @@ public object RegisterActions {
|
||||
IntellijCommandProvider.getCommands().forEach { parser.registerCommandAction(it) }
|
||||
}
|
||||
|
||||
private fun registerEmptyShortcuts() {
|
||||
private fun registerShortcutsWithoutActions() {
|
||||
val parser = VimPlugin.getKey()
|
||||
|
||||
// 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), MappingOwner.IdeaVim.System)
|
||||
parser.registerShortcutWithoutAction(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), MappingOwner.IdeaVim.System)
|
||||
}
|
||||
}
|
||||
|
@@ -211,22 +211,22 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
|
||||
public static void setEnabled(final boolean enabled) {
|
||||
if (isEnabled() == enabled) return;
|
||||
|
||||
if (!enabled) {
|
||||
getInstance().turnOffPlugin(true);
|
||||
}
|
||||
|
||||
getInstance().enabled = enabled;
|
||||
|
||||
if (enabled) {
|
||||
getInstance().turnOnPlugin();
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
VimInjectorKt.getInjector().getListenersNotifier().notifyPluginTurnedOn();
|
||||
} else {
|
||||
VimInjectorKt.getInjector().getListenersNotifier().notifyPluginTurnedOff();
|
||||
}
|
||||
|
||||
if (!enabled) {
|
||||
getInstance().turnOffPlugin(true);
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
getInstance().turnOnPlugin();
|
||||
}
|
||||
|
||||
StatusBarIconFactory.Util.INSTANCE.updateIcon();
|
||||
}
|
||||
|
||||
@@ -282,7 +282,13 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
|
||||
ideavimrcRegistered = true;
|
||||
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
executeIdeaVimRc(editor);
|
||||
try {
|
||||
VimInjectorKt.injector.getOptionGroup().startInitVimRc();
|
||||
executeIdeaVimRc(editor);
|
||||
}
|
||||
finally {
|
||||
VimInjectorKt.injector.getOptionGroup().endInitVimRc();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,6 +359,7 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
|
||||
|
||||
if (onOffDisposable != null) {
|
||||
Disposer.dispose(onOffDisposable);
|
||||
onOffDisposable = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -14,7 +14,7 @@ import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.maddyhome.idea.vim.group.EditorHolderService
|
||||
|
||||
@Service
|
||||
@Service(Service.Level.PROJECT)
|
||||
internal class VimProjectService(val project: Project) : Disposable {
|
||||
override fun dispose() {
|
||||
// Not sure if this is a best solution
|
||||
|
@@ -77,7 +77,7 @@ public class VimTypedActionHandler(origHandler: TypedActionHandler) : TypedActio
|
||||
val modifiers = if (charTyped == ' ' && VimKeyListener.isSpaceShift) KeyEvent.SHIFT_DOWN_MASK else 0
|
||||
val keyStroke = KeyStroke.getKeyStroke(charTyped, modifiers)
|
||||
val startTime = if (traceTime) System.currentTimeMillis() else null
|
||||
handler.handleKey(editor.vim, keyStroke, injector.executionContextManager.onEditor(editor.vim, context.vim))
|
||||
handler.handleKey(editor.vim, keyStroke, context.vim, handler.keyHandlerState)
|
||||
if (startTime != null) {
|
||||
val duration = System.currentTimeMillis() - startTime
|
||||
LOG.info("VimTypedAction '$charTyped': $duration ms")
|
||||
|
39
src/main/java/com/maddyhome/idea/vim/action/RedrawAction.kt
Normal file
39
src/main/java/com/maddyhome/idea/vim/action/RedrawAction.kt
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2003-2024 The IdeaVim authors
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE.txt file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim.action
|
||||
|
||||
import com.intellij.vim.annotations.CommandOrMotion
|
||||
import com.intellij.vim.annotations.Mode
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
|
||||
/**
|
||||
* Clear and redraw the screen
|
||||
*
|
||||
* Typically, an IDE does not need to redraw the screen - it's editor handles scrolling, etc. However, it can be
|
||||
* necessary to clear the status line.
|
||||
*/
|
||||
@CommandOrMotion(keys = ["<C-L>"], modes = [Mode.NORMAL])
|
||||
internal class RedrawAction : VimActionHandler.SingleExecution() {
|
||||
override val type: Command.Type = Command.Type.OTHER_READONLY
|
||||
|
||||
override fun execute(
|
||||
editor: VimEditor,
|
||||
context: ExecutionContext,
|
||||
cmd: Command,
|
||||
operatorArguments: OperatorArguments,
|
||||
): Boolean {
|
||||
injector.redrawService.redraw()
|
||||
return true
|
||||
}
|
||||
}
|
@@ -26,6 +26,7 @@ import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.globalOptions
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.group.EditorHolderService
|
||||
import com.maddyhome.idea.vim.group.IjOptionConstants
|
||||
import com.maddyhome.idea.vim.group.IjOptions
|
||||
import com.maddyhome.idea.vim.handler.enableOctopus
|
||||
@@ -44,7 +45,7 @@ import com.maddyhome.idea.vim.listener.AceJumpService
|
||||
import com.maddyhome.idea.vim.listener.AppCodeTemplates.appCodeTemplateCaptured
|
||||
import com.maddyhome.idea.vim.newapi.globalIjOptions
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.state.mode.mode
|
||||
import com.maddyhome.idea.vim.ui.ex.ExTextField
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString
|
||||
import java.awt.event.InputEvent
|
||||
import java.awt.event.KeyEvent
|
||||
@@ -79,11 +80,8 @@ public class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible
|
||||
// Should we use HelperKt.getTopLevelEditor(editor) here, as we did in former EditorKeyHandler?
|
||||
try {
|
||||
val start = if (traceTime) System.currentTimeMillis() else null
|
||||
KeyHandler.getInstance().handleKey(
|
||||
editor.vim,
|
||||
keyStroke,
|
||||
injector.executionContextManager.onEditor(editor.vim, e.dataContext.vim),
|
||||
)
|
||||
val keyHandler = KeyHandler.getInstance()
|
||||
keyHandler.handleKey(editor.vim, keyStroke, e.dataContext.vim, keyHandler.keyHandlerState)
|
||||
if (start != null) {
|
||||
val duration = System.currentTimeMillis() - start
|
||||
LOG.info("VimShortcut update '$keyStroke': $duration ms")
|
||||
@@ -256,7 +254,14 @@ public class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible
|
||||
return null
|
||||
}
|
||||
|
||||
private fun getEditor(e: AnActionEvent): Editor? = e.getData(PlatformDataKeys.EDITOR)
|
||||
private fun getEditor(e: AnActionEvent): Editor? {
|
||||
return e.getData(PlatformDataKeys.EDITOR)
|
||||
?: if (e.getData(PlatformDataKeys.CONTEXT_COMPONENT) is ExTextField) {
|
||||
EditorHolderService.getInstance().editor
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Every time the key pressed with an active lookup, there is a decision:
|
||||
@@ -380,6 +385,10 @@ private class ActionEnableStatus(
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "ActionEnableStatus(isEnabled=$isEnabled, message='$message', logLevel=$logLevel)"
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val LOG = logger<ActionEnableStatus>()
|
||||
|
||||
|
@@ -14,6 +14,7 @@ import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.VimCaret
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.globalOptions
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.api.setChangeMarks
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
@@ -21,6 +22,7 @@ import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.common.argumentCaptured
|
||||
import com.maddyhome.idea.vim.ex.ExException
|
||||
import com.maddyhome.idea.vim.group.MotionGroup
|
||||
import com.maddyhome.idea.vim.group.visual.VimSelection
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
@@ -29,21 +31,67 @@ import com.maddyhome.idea.vim.helper.MessageHelper
|
||||
import com.maddyhome.idea.vim.helper.vimStateMachine
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
import com.maddyhome.idea.vim.vimscript.model.CommandLineVimLContext
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimFuncref
|
||||
import com.maddyhome.idea.vim.vimscript.model.expressions.FunctionCallExpression
|
||||
import com.maddyhome.idea.vim.vimscript.model.expressions.SimpleExpression
|
||||
|
||||
// todo make it multicaret
|
||||
private fun doOperatorAction(editor: VimEditor, context: ExecutionContext, textRange: TextRange, selectionType: SelectionType): Boolean {
|
||||
val operatorFunction = injector.keyGroup.operatorFunction
|
||||
if (operatorFunction == null) {
|
||||
val func = injector.globalOptions().operatorfunc
|
||||
if (func.isEmpty()) {
|
||||
VimPlugin.showMessage(MessageHelper.message("E774"))
|
||||
return false
|
||||
}
|
||||
|
||||
val scriptContext = CommandLineVimLContext
|
||||
|
||||
// The option value is either a function name, which should have a handler, or it might be a lambda expression, or a
|
||||
// `function` or `funcref` call expression, all of which will return a funcref (with a handler)
|
||||
var handler = injector.functionService.getFunctionHandlerOrNull(null, func, scriptContext)
|
||||
if (handler == null) {
|
||||
val expression = injector.vimscriptParser.parseExpression(func)
|
||||
if (expression != null) {
|
||||
try {
|
||||
val value = expression.evaluate(editor, context, scriptContext)
|
||||
if (value is VimFuncref) {
|
||||
handler = value.handler
|
||||
}
|
||||
} catch (ex: ExException) {
|
||||
// Get the argument for function('...') or funcref('...') for the error message
|
||||
val functionName = if (expression is FunctionCallExpression && expression.arguments.size > 0) {
|
||||
expression.arguments[0].evaluate(editor, context, scriptContext).toString()
|
||||
}
|
||||
else {
|
||||
func
|
||||
}
|
||||
|
||||
VimPlugin.showMessage("E117: Unknown function: $functionName")
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (handler == null) {
|
||||
VimPlugin.showMessage("E117: Unknown function: $func")
|
||||
return false
|
||||
}
|
||||
|
||||
val arg = when (selectionType) {
|
||||
SelectionType.LINE_WISE -> "line"
|
||||
SelectionType.CHARACTER_WISE -> "char"
|
||||
SelectionType.BLOCK_WISE -> "block"
|
||||
}
|
||||
|
||||
val saveRepeatHandler = VimRepeater.repeatHandler
|
||||
injector.markService.setChangeMarks(editor.primaryCaret(), textRange)
|
||||
KeyHandler.getInstance().reset(editor)
|
||||
val result = operatorFunction.apply(editor, context, selectionType)
|
||||
|
||||
val arguments = listOf(SimpleExpression(arg))
|
||||
handler.executeFunction(arguments, editor, context, scriptContext)
|
||||
|
||||
VimRepeater.repeatHandler = saveRepeatHandler
|
||||
return result
|
||||
return true
|
||||
}
|
||||
|
||||
@CommandOrMotion(keys = ["g@"], modes = [Mode.NORMAL])
|
||||
|
@@ -7,9 +7,9 @@
|
||||
*/
|
||||
package com.maddyhome.idea.vim.action.change
|
||||
|
||||
import com.intellij.openapi.command.CommandProcessor
|
||||
import com.intellij.vim.annotations.CommandOrMotion
|
||||
import com.intellij.vim.annotations.Mode
|
||||
import com.intellij.openapi.command.CommandProcessor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
@@ -58,11 +58,11 @@ internal class RepeatChangeAction : VimActionHandler.SingleExecution() {
|
||||
)
|
||||
} else if (!repeatHandler && lastCommand != null) {
|
||||
if (cmd.rawCount > 0) {
|
||||
lastCommand.count = cmd.count
|
||||
lastCommand.rawCount = cmd.count
|
||||
val arg = lastCommand.argument
|
||||
if (arg != null) {
|
||||
val mot = arg.motion
|
||||
mot.count = 0
|
||||
mot.rawCount = 0
|
||||
}
|
||||
}
|
||||
state.executingCommand = lastCommand
|
||||
|
@@ -34,7 +34,7 @@ public class DeleteJoinLinesSpacesAction : ChangeEditorActionHandler.SingleExecu
|
||||
}
|
||||
injector.editorGroup.notifyIdeaJoin(editor)
|
||||
var res = true
|
||||
editor.nativeCarets().sortedByDescending { it.offset.point }.forEach { caret ->
|
||||
editor.nativeCarets().sortedByDescending { it.offset }.forEach { caret ->
|
||||
if (!injector.changeGroup.deleteJoinLines(editor, caret, operatorArguments.count1, true, operatorArguments)) {
|
||||
res = false
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ public class DeleteJoinVisualLinesAction : VisualOperatorActionHandler.SingleExe
|
||||
return true
|
||||
}
|
||||
var res = true
|
||||
editor.nativeCarets().sortedByDescending { it.offset.point }.forEach { caret ->
|
||||
editor.nativeCarets().sortedByDescending { it.offset }.forEach { caret ->
|
||||
if (!caret.isValid) return@forEach
|
||||
val range = caretsAndSelections[caret] ?: return@forEach
|
||||
if (!injector.changeGroup.deleteJoinRange(
|
||||
|
@@ -39,7 +39,7 @@ public class DeleteJoinVisualLinesSpacesAction : VisualOperatorActionHandler.Sin
|
||||
return true
|
||||
}
|
||||
var res = true
|
||||
editor.carets().sortedByDescending { it.offset.point }.forEach { caret ->
|
||||
editor.carets().sortedByDescending { it.offset }.forEach { caret ->
|
||||
if (!caret.isValid) return@forEach
|
||||
val range = caretsAndSelections[caret] ?: return@forEach
|
||||
if (!injector.changeGroup.deleteJoinRange(
|
||||
|
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2023 The IdeaVim authors
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE.txt file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package com.maddyhome.idea.vim.action.ex
|
||||
|
||||
import com.intellij.vim.annotations.CommandOrMotion
|
||||
import com.intellij.vim.annotations.Mode
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Called by KeyHandler to process the contents of the ex entry panel
|
||||
*
|
||||
* The mapping for this action means that the ex command is executed as a write action
|
||||
*/
|
||||
@CommandOrMotion(keys = ["<CR>", "<C-M>", "<C-J>"], modes = [Mode.CMD_LINE])
|
||||
public class ProcessExEntryAction : VimActionHandler.SingleExecution() {
|
||||
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = EnumSet.of(CommandFlags.FLAG_COMPLETE_EX)
|
||||
|
||||
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
||||
return VimPlugin.getProcess().processExEntry(editor, context)
|
||||
}
|
||||
}
|
@@ -21,19 +21,19 @@ import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
public class CommandState(private val machine: VimStateMachine) {
|
||||
|
||||
public val isOperatorPending: Boolean
|
||||
get() = machine.isOperatorPending
|
||||
get() = machine.isOperatorPending(machine.mode)
|
||||
|
||||
public val mode: CommandState.Mode
|
||||
public val mode: Mode
|
||||
get() {
|
||||
val myMode = machine.mode
|
||||
return when (myMode) {
|
||||
is com.maddyhome.idea.vim.state.mode.Mode.CMD_LINE -> CommandState.Mode.CMD_LINE
|
||||
com.maddyhome.idea.vim.state.mode.Mode.INSERT -> CommandState.Mode.INSERT
|
||||
is com.maddyhome.idea.vim.state.mode.Mode.NORMAL -> CommandState.Mode.COMMAND
|
||||
is com.maddyhome.idea.vim.state.mode.Mode.OP_PENDING -> CommandState.Mode.OP_PENDING
|
||||
com.maddyhome.idea.vim.state.mode.Mode.REPLACE -> CommandState.Mode.REPLACE
|
||||
is com.maddyhome.idea.vim.state.mode.Mode.SELECT -> CommandState.Mode.SELECT
|
||||
is com.maddyhome.idea.vim.state.mode.Mode.VISUAL -> CommandState.Mode.VISUAL
|
||||
is com.maddyhome.idea.vim.state.mode.Mode.CMD_LINE -> Mode.CMD_LINE
|
||||
com.maddyhome.idea.vim.state.mode.Mode.INSERT -> Mode.INSERT
|
||||
is com.maddyhome.idea.vim.state.mode.Mode.NORMAL -> Mode.COMMAND
|
||||
is com.maddyhome.idea.vim.state.mode.Mode.OP_PENDING -> Mode.OP_PENDING
|
||||
com.maddyhome.idea.vim.state.mode.Mode.REPLACE -> Mode.REPLACE
|
||||
is com.maddyhome.idea.vim.state.mode.Mode.SELECT -> Mode.SELECT
|
||||
is com.maddyhome.idea.vim.state.mode.Mode.VISUAL -> Mode.VISUAL
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -9,8 +9,6 @@
|
||||
package com.maddyhome.idea.vim.common
|
||||
|
||||
import com.intellij.application.options.CodeStyle
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings.IndentOptions
|
||||
@@ -39,13 +37,12 @@ internal class IndentConfig private constructor(indentOptions: IndentOptions) {
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun create(editor: Editor, context: DataContext): IndentConfig {
|
||||
return create(editor, PlatformDataKeys.PROJECT.getData(context))
|
||||
fun create(editor: Editor): IndentConfig {
|
||||
return create(editor, editor.project)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun create(editor: Editor, project: Project? = editor.project): IndentConfig {
|
||||
fun create(editor: Editor, project: Project?): IndentConfig {
|
||||
val indentOptions = if (project != null) {
|
||||
CodeStyle.getIndentOptions(project, editor.document)
|
||||
} else {
|
||||
|
@@ -13,24 +13,46 @@ import com.maddyhome.idea.vim.api.VimExOutputPanel
|
||||
import com.maddyhome.idea.vim.helper.vimExOutput
|
||||
import com.maddyhome.idea.vim.ui.ExOutputPanel
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
// TODO: We need a nicer way to handle output, especially wrt testing, appending + clearing
|
||||
public class ExOutputModel private constructor(private val myEditor: Editor) : VimExOutputPanel {
|
||||
private var isActiveInTestMode = false
|
||||
|
||||
override val isActive: Boolean
|
||||
get() = if (!ApplicationManager.getApplication().isUnitTestMode) {
|
||||
ExOutputPanel.isPanelActive(myEditor)
|
||||
} else {
|
||||
isActiveInTestMode
|
||||
}
|
||||
|
||||
override var text: String? = null
|
||||
private set
|
||||
get() = if (!ApplicationManager.getApplication().isUnitTestMode) {
|
||||
ExOutputPanel.getInstance(myEditor).text
|
||||
} else {
|
||||
field
|
||||
}
|
||||
set(value) {
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode) {
|
||||
ExOutputPanel.getInstance(myEditor).setText(value ?: "")
|
||||
} else {
|
||||
field = value
|
||||
isActiveInTestMode = !value.isNullOrEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
override fun output(text: String) {
|
||||
this.text = text
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode) {
|
||||
ExOutputPanel.getInstance(myEditor).setText(text)
|
||||
}
|
||||
}
|
||||
|
||||
override fun clear() {
|
||||
text = null
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode) {
|
||||
ExOutputPanel.getInstance(myEditor).deactivate(false)
|
||||
ExOutputPanel.getInstance(myEditor).close()
|
||||
}
|
||||
else {
|
||||
isActiveInTestMode = false
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
package com.maddyhome.idea.vim.extension
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
@@ -14,21 +15,33 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.action.change.Extension
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.ImmutableVimCaret
|
||||
import com.maddyhome.idea.vim.api.VimCaret
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.command.MappingMode
|
||||
import com.maddyhome.idea.vim.common.CommandAlias
|
||||
import com.maddyhome.idea.vim.common.CommandAliasHandler
|
||||
import com.maddyhome.idea.vim.helper.CommandLineHelper
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.helper.TestInputModel
|
||||
import com.maddyhome.idea.vim.helper.noneOfEnum
|
||||
import com.maddyhome.idea.vim.helper.vimStateMachine
|
||||
import com.maddyhome.idea.vim.key.MappingOwner
|
||||
import com.maddyhome.idea.vim.key.OperatorFunction
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
import com.maddyhome.idea.vim.ui.ModalEntry
|
||||
import com.maddyhome.idea.vim.vimscript.model.Executable
|
||||
import com.maddyhome.idea.vim.vimscript.model.ExecutionResult
|
||||
import com.maddyhome.idea.vim.vimscript.model.VimLContext
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType
|
||||
import com.maddyhome.idea.vim.vimscript.model.expressions.Expression
|
||||
import com.maddyhome.idea.vim.vimscript.model.expressions.Scope
|
||||
import com.maddyhome.idea.vim.vimscript.model.statements.FunctionDeclaration
|
||||
import com.maddyhome.idea.vim.vimscript.model.statements.FunctionFlag
|
||||
import java.awt.event.KeyEvent
|
||||
import java.util.*
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
/**
|
||||
@@ -120,12 +133,6 @@ public object VimExtensionFacade {
|
||||
.setAlias(name, CommandAlias.Call(minimumNumberOfArguments, maximumNumberOfArguments, name, handler))
|
||||
}
|
||||
|
||||
/** Sets the value of 'operatorfunc' to be used as the operator function in 'g@'. */
|
||||
@JvmStatic
|
||||
public fun setOperatorFunction(function: OperatorFunction) {
|
||||
VimPlugin.getKey().operatorFunction = function
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs normal mode commands similar to ':normal! {commands}'.
|
||||
* Mappings doesn't work with this function
|
||||
@@ -135,8 +142,9 @@ public object VimExtensionFacade {
|
||||
*/
|
||||
@JvmStatic
|
||||
public fun executeNormalWithoutMapping(keys: List<KeyStroke>, editor: Editor) {
|
||||
val context = injector.executionContextManager.onEditor(editor.vim)
|
||||
keys.forEach { KeyHandler.getInstance().handleKey(editor.vim, it, context, false, false) }
|
||||
val context = injector.executionContextManager.getEditorExecutionContext(editor.vim)
|
||||
val keyHandler = KeyHandler.getInstance()
|
||||
keys.forEach { keyHandler.handleKey(editor.vim, it, context, false, false, keyHandler.keyHandlerState) }
|
||||
}
|
||||
|
||||
/** Returns a single key stroke from the user input similar to 'getchar()'. */
|
||||
@@ -152,7 +160,7 @@ public object VimExtensionFacade {
|
||||
LOG.trace("Unit test mode is active")
|
||||
val mappingStack = KeyHandler.getInstance().keyStack
|
||||
mappingStack.feedSomeStroke() ?: TestInputModel.getInstance(editor).nextKeyStroke()?.also {
|
||||
if (editor.vim.vimStateMachine.isRecording) {
|
||||
if (injector.registerGroup.isRecording) {
|
||||
KeyHandler.getInstance().modalEntryKeys += it
|
||||
}
|
||||
}
|
||||
@@ -173,8 +181,8 @@ public object VimExtensionFacade {
|
||||
|
||||
/** Returns a string typed in the input box similar to 'input()'. */
|
||||
@JvmStatic
|
||||
public fun inputString(editor: Editor, prompt: String, finishOn: Char?): String {
|
||||
return service<CommandLineHelper>().inputString(editor.vim, prompt, finishOn) ?: ""
|
||||
public fun inputString(editor: Editor, context: DataContext, prompt: String, finishOn: Char?): String {
|
||||
return injector.commandLine.inputString(editor.vim, context.vim, prompt, finishOn) ?: ""
|
||||
}
|
||||
|
||||
/** Get the current contents of the given register similar to 'getreg()'. */
|
||||
@@ -207,4 +215,65 @@ public object VimExtensionFacade {
|
||||
public fun setRegister(register: Char, keys: List<KeyStroke?>?, type: SelectionType) {
|
||||
VimPlugin.getRegister().setKeys(register, keys?.filterNotNull() ?: emptyList(), type)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
public fun exportScriptFunction(
|
||||
scope: Scope?,
|
||||
name: String,
|
||||
args: List<String>,
|
||||
defaultArgs: List<Pair<String, Expression>>,
|
||||
hasOptionalArguments: Boolean,
|
||||
flags: EnumSet<FunctionFlag>,
|
||||
function: ScriptFunction
|
||||
) {
|
||||
var functionDeclaration: FunctionDeclaration? = null
|
||||
val body = listOf(object : Executable {
|
||||
// This context is set to the function declaration during initialisation and then set to the function execution
|
||||
// context during execution
|
||||
override lateinit var vimContext: VimLContext
|
||||
override var rangeInScript: TextRange = TextRange(0, 0)
|
||||
|
||||
override fun execute(editor: VimEditor, context: ExecutionContext): ExecutionResult {
|
||||
return function.execute(editor, context, functionDeclaration!!.functionVariables)
|
||||
}
|
||||
})
|
||||
functionDeclaration = FunctionDeclaration(
|
||||
scope,
|
||||
name,
|
||||
args,
|
||||
defaultArgs,
|
||||
body,
|
||||
replaceExisting = true,
|
||||
flags,
|
||||
hasOptionalArguments
|
||||
)
|
||||
functionDeclaration.rangeInScript = TextRange(0, 0)
|
||||
body.forEach { it.vimContext = functionDeclaration }
|
||||
injector.functionService.storeFunction(functionDeclaration)
|
||||
}
|
||||
}
|
||||
|
||||
public fun VimExtensionFacade.exportOperatorFunction(name: String, function: OperatorFunction) {
|
||||
exportScriptFunction(null, name, listOf("type"), emptyList(), false, noneOfEnum()) {
|
||||
editor, context, args ->
|
||||
|
||||
val type = args["type"]?.asString()
|
||||
val selectionType = when (type) {
|
||||
"line" -> SelectionType.LINE_WISE
|
||||
"block" -> SelectionType.BLOCK_WISE
|
||||
"char" -> SelectionType.CHARACTER_WISE
|
||||
else -> return@exportScriptFunction ExecutionResult.Error
|
||||
}
|
||||
|
||||
if (function.apply(editor, context, selectionType)) {
|
||||
ExecutionResult.Success
|
||||
}
|
||||
else {
|
||||
ExecutionResult.Error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public fun interface ScriptFunction {
|
||||
public fun execute(editor: VimEditor, context: ExecutionContext, args: Map<String, VimDataType>): ExecutionResult
|
||||
}
|
@@ -67,7 +67,7 @@ internal object VimExtensionRegistrar : VimExtensionRegistrator {
|
||||
VimPlugin.getOptionGroup().addGlobalOptionChangeListener(option) {
|
||||
if (injector.optionGroup.getOptionValue(option, OptionAccessScope.GLOBAL(null)).asBoolean()) {
|
||||
initExtension(extensionBean, name)
|
||||
PluginState.enabledExtensions.add(name)
|
||||
PluginState.Util.enabledExtensions.add(name)
|
||||
} else {
|
||||
extensionBean.instance.dispose()
|
||||
}
|
||||
|
@@ -251,7 +251,7 @@ public class VimArgTextObjExtension implements VimExtension {
|
||||
|
||||
final ArgumentTextObjectHandler textObjectHandler = new ArgumentTextObjectHandler(isInner);
|
||||
//noinspection DuplicatedCode
|
||||
if (!vimStateMachine.isOperatorPending()) {
|
||||
if (!vimStateMachine.isOperatorPending(editor.getMode())) {
|
||||
editor.nativeCarets().forEach((VimCaret caret) -> {
|
||||
final TextRange range = textObjectHandler.getRange(editor, caret, context, count, 0);
|
||||
if (range != null) {
|
||||
|
@@ -22,26 +22,27 @@ import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.ImmutableVimCaret
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.getLineEndOffset
|
||||
import com.maddyhome.idea.vim.api.globalOptions
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
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.command.MappingMode
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
import com.maddyhome.idea.vim.command.TextObjectVisualType
|
||||
import com.maddyhome.idea.vim.common.CommandAliasHandler
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.ex.ranges.Ranges
|
||||
import com.maddyhome.idea.vim.ex.ranges.Range
|
||||
import com.maddyhome.idea.vim.ex.ranges.toTextRange
|
||||
import com.maddyhome.idea.vim.extension.ExtensionHandler
|
||||
import com.maddyhome.idea.vim.extension.VimExtension
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.addCommand
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.executeNormalWithoutMapping
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putExtensionHandlerMapping
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMapping
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMappingIfMissing
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.setOperatorFunction
|
||||
import com.maddyhome.idea.vim.extension.exportOperatorFunction
|
||||
import com.maddyhome.idea.vim.handler.TextObjectActionHandler
|
||||
import com.maddyhome.idea.vim.helper.PsiHelper
|
||||
import com.maddyhome.idea.vim.helper.vimStateMachine
|
||||
@@ -49,17 +50,19 @@ import com.maddyhome.idea.vim.key.OperatorFunction
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
import java.util.*
|
||||
|
||||
internal class CommentaryExtension : VimExtension {
|
||||
|
||||
companion object {
|
||||
object Util {
|
||||
fun doCommentary(
|
||||
editor: VimEditor,
|
||||
context: ExecutionContext,
|
||||
range: TextRange,
|
||||
selectionType: SelectionType,
|
||||
resetCaret: Boolean,
|
||||
resetCaret: Boolean = true,
|
||||
): Boolean {
|
||||
val mode = editor.vimStateMachine.mode
|
||||
if (mode !is Mode.VISUAL) {
|
||||
@@ -67,8 +70,7 @@ internal class CommentaryExtension : VimExtension {
|
||||
}
|
||||
|
||||
return runWriteAction {
|
||||
// Treat block- and character-wise selections as block comments. Be ready to fall back to if the first action
|
||||
// isn't available
|
||||
// Treat block- and character-wise selections as block comments. Fall back if the first action isn't available
|
||||
val actions = if (selectionType === SelectionType.LINE_WISE) {
|
||||
listOf(IdeActions.ACTION_COMMENT_LINE, IdeActions.ACTION_COMMENT_BLOCK)
|
||||
} else {
|
||||
@@ -113,12 +115,17 @@ internal class CommentaryExtension : VimExtension {
|
||||
// first non-whitespace character, then the caret is in the right place. If it's inserted at the first column,
|
||||
// then the caret is now in a bit of a weird place. We can't detect this scenario, so we just have to accept
|
||||
// the difference
|
||||
// TODO: If we don't move the caret to the start offset, we should maintain the current logical position
|
||||
if (resetCaret) {
|
||||
editor.primaryCaret().moveToOffset(range.startOffset)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val OPERATOR_FUNC = "CommentaryOperatorFunc"
|
||||
}
|
||||
|
||||
override fun getName() = "commentary"
|
||||
|
||||
override fun init() {
|
||||
@@ -145,6 +152,16 @@ internal class CommentaryExtension : VimExtension {
|
||||
putKeyMapping(MappingMode.N, injector.parser.parseKeys("<Plug>(CommentLine)"), owner, plugCommentaryLineKeys, true)
|
||||
|
||||
addCommand("Commentary", CommentaryCommandAliasHandler())
|
||||
|
||||
VimExtensionFacade.exportOperatorFunction(OPERATOR_FUNC, CommentaryOperatorFunction())
|
||||
}
|
||||
|
||||
private class CommentaryOperatorFunction : OperatorFunction {
|
||||
// todo make it multicaret
|
||||
override fun apply(editor: VimEditor, context: ExecutionContext, selectionType: SelectionType?): Boolean {
|
||||
val range = injector.markService.getChangeMarks(editor.primaryCaret()) ?: return false
|
||||
return Util.doCommentary(editor, context, range, selectionType ?: SelectionType.CHARACTER_WISE, true)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,19 +170,13 @@ internal class CommentaryExtension : VimExtension {
|
||||
* E.g. handles the `gc` in `gc_`, by setting the operator function, then invoking `g@` to receive the `_` motion to
|
||||
* invoke the operator. This object is both the mapping handler and the operator function.
|
||||
*/
|
||||
private class CommentaryOperatorHandler : OperatorFunction, ExtensionHandler {
|
||||
private class CommentaryOperatorHandler : ExtensionHandler {
|
||||
override val isRepeatable = true
|
||||
|
||||
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
|
||||
setOperatorFunction(this)
|
||||
injector.globalOptions().operatorfunc = OPERATOR_FUNC
|
||||
executeNormalWithoutMapping(injector.parser.parseKeys("g@"), editor.ij)
|
||||
}
|
||||
|
||||
// todo make it multicaret
|
||||
override fun apply(editor: VimEditor, context: ExecutionContext, selectionType: SelectionType?): Boolean {
|
||||
val range = injector.markService.getChangeMarks(editor.primaryCaret()) ?: return false
|
||||
return doCommentary(editor, context, range, selectionType ?: SelectionType.CHARACTER_WISE, true)
|
||||
}
|
||||
}
|
||||
|
||||
private class CommentaryMappingHandler : ExtensionHandler {
|
||||
@@ -238,8 +249,14 @@ internal class CommentaryExtension : VimExtension {
|
||||
* Used like `:1,3Commentary` or `g/fun/Commentary`
|
||||
*/
|
||||
private class CommentaryCommandAliasHandler : CommandAliasHandler {
|
||||
override fun execute(command: String, ranges: Ranges, editor: VimEditor, context: ExecutionContext) {
|
||||
doCommentary(editor, context, ranges.getTextRange(editor, -1), SelectionType.LINE_WISE, false)
|
||||
override fun execute(command: String, range: Range, editor: VimEditor, context: ExecutionContext) {
|
||||
Util.doCommentary(
|
||||
editor,
|
||||
context,
|
||||
range.getLineRange(editor, editor.primaryCaret()).toTextRange(editor),
|
||||
SelectionType.LINE_WISE,
|
||||
false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,24 +19,22 @@ import com.intellij.openapi.util.Key
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.getOffset
|
||||
import com.maddyhome.idea.vim.api.globalOptions
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.api.setChangeMarks
|
||||
import com.maddyhome.idea.vim.command.MappingMode
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType.CHARACTER_WISE
|
||||
import com.maddyhome.idea.vim.state.mode.selectionType
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.extension.ExtensionHandler
|
||||
import com.maddyhome.idea.vim.extension.VimExtension
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.executeNormalWithoutMapping
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.getRegister
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putExtensionHandlerMapping
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMappingIfMissing
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.setOperatorFunction
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.setRegister
|
||||
import com.maddyhome.idea.vim.extension.exportOperatorFunction
|
||||
import com.maddyhome.idea.vim.helper.fileSize
|
||||
import com.maddyhome.idea.vim.state.mode.mode
|
||||
import com.maddyhome.idea.vim.helper.moveToInlayAwareLogicalPosition
|
||||
import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset
|
||||
import com.maddyhome.idea.vim.key.OperatorFunction
|
||||
@@ -45,6 +43,8 @@ import com.maddyhome.idea.vim.mark.VimMarkConstants
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
import com.maddyhome.idea.vim.state.mode.selectionType
|
||||
import org.jetbrains.annotations.NonNls
|
||||
|
||||
/**
|
||||
@@ -72,30 +72,13 @@ internal class VimExchangeExtension : VimExtension {
|
||||
putKeyMappingIfMissing(MappingMode.X, injector.parser.parseKeys("X"), owner, injector.parser.parseKeys(EXCHANGE_CMD), true)
|
||||
putKeyMappingIfMissing(MappingMode.N, injector.parser.parseKeys("cxc"), owner, injector.parser.parseKeys(EXCHANGE_CLEAR_CMD), true)
|
||||
putKeyMappingIfMissing(MappingMode.N, injector.parser.parseKeys("cxx"), owner, injector.parser.parseKeys(EXCHANGE_LINE_CMD), true)
|
||||
|
||||
VimExtensionFacade.exportOperatorFunction(OPERATOR_FUNC, Operator())
|
||||
}
|
||||
|
||||
companion object {
|
||||
@NonNls
|
||||
const val EXCHANGE_CMD = "<Plug>(Exchange)"
|
||||
|
||||
@NonNls
|
||||
const val EXCHANGE_CLEAR_CMD = "<Plug>(ExchangeClear)"
|
||||
|
||||
@NonNls
|
||||
const val EXCHANGE_LINE_CMD = "<Plug>(ExchangeLine)"
|
||||
|
||||
object Util {
|
||||
val EXCHANGE_KEY = Key<Exchange>("exchange")
|
||||
|
||||
// End mark has always greater of eq offset than start mark
|
||||
class Exchange(val type: SelectionType, val start: Mark, val end: Mark, val text: String) {
|
||||
private var myHighlighter: RangeHighlighter? = null
|
||||
fun setHighlighter(highlighter: RangeHighlighter) {
|
||||
myHighlighter = highlighter
|
||||
}
|
||||
|
||||
fun getHighlighter(): RangeHighlighter? = myHighlighter
|
||||
}
|
||||
|
||||
fun clearExchange(editor: Editor) {
|
||||
editor.getUserData(EXCHANGE_KEY)?.getHighlighter()?.let {
|
||||
editor.markupModel.removeHighlighter(it)
|
||||
@@ -104,18 +87,25 @@ internal class VimExchangeExtension : VimExtension {
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@NonNls private const val EXCHANGE_CMD = "<Plug>(Exchange)"
|
||||
@NonNls private const val EXCHANGE_CLEAR_CMD = "<Plug>(ExchangeClear)"
|
||||
@NonNls private const val EXCHANGE_LINE_CMD = "<Plug>(ExchangeLine)"
|
||||
@NonNls private const val OPERATOR_FUNC = "ExchangeOperatorFunc"
|
||||
}
|
||||
|
||||
private class ExchangeHandler(private val isLine: Boolean) : ExtensionHandler {
|
||||
override val isRepeatable = true
|
||||
|
||||
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
|
||||
setOperatorFunction(Operator(false))
|
||||
injector.globalOptions().operatorfunc = OPERATOR_FUNC
|
||||
executeNormalWithoutMapping(injector.parser.parseKeys(if (isLine) "g@_" else "g@"), editor.ij)
|
||||
}
|
||||
}
|
||||
|
||||
private class ExchangeClearHandler : ExtensionHandler {
|
||||
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
|
||||
clearExchange(editor.ij)
|
||||
Util.clearExchange(editor.ij)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,12 +115,12 @@ internal class VimExchangeExtension : VimExtension {
|
||||
val mode = editor.mode
|
||||
// Leave visual mode to create selection marks
|
||||
executeNormalWithoutMapping(injector.parser.parseKeys("<Esc>"), editor.ij)
|
||||
Operator(true).apply(editor, context, mode.selectionType ?: CHARACTER_WISE)
|
||||
Operator(true).apply(editor, context, mode.selectionType ?: SelectionType.CHARACTER_WISE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class Operator(private val isVisual: Boolean) : OperatorFunction {
|
||||
private class Operator(private val isVisual: Boolean = false) : OperatorFunction {
|
||||
fun Editor.getMarkOffset(mark: Mark) = IjVimEditor(this).getOffset(mark.line, mark.col)
|
||||
fun SelectionType.getString() = when (this) {
|
||||
SelectionType.CHARACTER_WISE -> "v"
|
||||
@@ -148,7 +138,7 @@ internal class VimExchangeExtension : VimExtension {
|
||||
else -> HighlighterTargetArea.EXACT_RANGE
|
||||
}
|
||||
val isVisualLine = ex.type == SelectionType.LINE_WISE
|
||||
val endAdj = if (!(isVisualLine) && (hlArea == HighlighterTargetArea.EXACT_RANGE || (isVisual))) 1 else 0
|
||||
val endAdj = if (!(isVisualLine) && (hlArea == HighlighterTargetArea.EXACT_RANGE || isVisual)) 1 else 0
|
||||
return ijEditor.markupModel.addRangeHighlighter(
|
||||
ijEditor.getMarkOffset(ex.start),
|
||||
(ijEditor.getMarkOffset(ex.end) + endAdj).coerceAtMost(ijEditor.fileSize),
|
||||
@@ -158,12 +148,12 @@ internal class VimExchangeExtension : VimExtension {
|
||||
)
|
||||
}
|
||||
|
||||
val currentExchange = getExchange(ijEditor, isVisual, selectionType ?: CHARACTER_WISE)
|
||||
val exchange1 = ijEditor.getUserData(EXCHANGE_KEY)
|
||||
val currentExchange = getExchange(ijEditor, isVisual, selectionType ?: SelectionType.CHARACTER_WISE)
|
||||
val exchange1 = ijEditor.getUserData(Util.EXCHANGE_KEY)
|
||||
if (exchange1 == null) {
|
||||
val highlighter = highlightExchange(currentExchange)
|
||||
currentExchange.setHighlighter(highlighter)
|
||||
ijEditor.putUserData(EXCHANGE_KEY, currentExchange)
|
||||
ijEditor.putUserData(Util.EXCHANGE_KEY, currentExchange)
|
||||
return true
|
||||
} else {
|
||||
val cmp = compareExchanges(exchange1, currentExchange)
|
||||
@@ -189,7 +179,7 @@ internal class VimExchangeExtension : VimExtension {
|
||||
}
|
||||
}
|
||||
exchange(ijEditor, ex1, ex2, reverse, expand)
|
||||
clearExchange(ijEditor)
|
||||
Util.clearExchange(ijEditor)
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -354,4 +344,14 @@ internal class VimExchangeExtension : VimExtension {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// End mark has always greater of eq offset than start mark
|
||||
class Exchange(val type: SelectionType, val start: Mark, val end: Mark, val text: String) {
|
||||
private var myHighlighter: RangeHighlighter? = null
|
||||
fun setHighlighter(highlighter: RangeHighlighter) {
|
||||
myHighlighter = highlighter
|
||||
}
|
||||
|
||||
fun getHighlighter(): RangeHighlighter? = myHighlighter
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ package com.maddyhome.idea.vim.extension.highlightedyank
|
||||
|
||||
import com.intellij.ide.ui.LafManager
|
||||
import com.intellij.ide.ui.LafManagerListener
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.ModalityState
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.colors.EditorColors
|
||||
import com.intellij.openapi.editor.markup.EffectType
|
||||
@@ -19,25 +19,24 @@ import com.intellij.openapi.editor.markup.HighlighterTargetArea
|
||||
import com.intellij.openapi.editor.markup.RangeHighlighter
|
||||
import com.intellij.openapi.editor.markup.TextAttributes
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.util.Alarm
|
||||
import com.intellij.util.Alarm.ThreadToUse
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.VimProjectService
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.extension.VimExtension
|
||||
import com.maddyhome.idea.vim.helper.MessageHelper
|
||||
import com.maddyhome.idea.vim.helper.StrictMode
|
||||
import com.maddyhome.idea.vim.helper.VimNlsSafe
|
||||
import com.maddyhome.idea.vim.listener.VimInsertListener
|
||||
import com.maddyhome.idea.vim.listener.VimYankListener
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString
|
||||
import org.jetbrains.annotations.NonNls
|
||||
import java.awt.Color
|
||||
import java.awt.Font
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
internal const val DEFAULT_HIGHLIGHT_DURATION: Long = 300
|
||||
internal const val DEFAULT_HIGHLIGHT_DURATION: Int = 300
|
||||
|
||||
@NonNls
|
||||
private val HIGHLIGHT_DURATION_VARIABLE_NAME = "highlightedyank_highlight_duration"
|
||||
@@ -78,111 +77,128 @@ internal class HighlightColorResetter : LafManagerListener {
|
||||
*/
|
||||
internal class VimHighlightedYank : VimExtension, VimYankListener, VimInsertListener {
|
||||
private val highlightHandler = HighlightHandler()
|
||||
private var initialised = false
|
||||
|
||||
override fun getName() = "highlightedyank"
|
||||
|
||||
override fun init() {
|
||||
// Note that these listeners will still be registered when IdeaVim is disabled. However, they'll never get called
|
||||
VimPlugin.getYank().addListener(this)
|
||||
VimPlugin.getChange().addInsertListener(this)
|
||||
|
||||
// Register our own disposable to remove highlights when IdeaVim is disabled. Somehow, we need to re-register when
|
||||
// IdeaVim is re-enabled. We don't get a call back for that, but because the listeners are active until the
|
||||
// _extension_ is disabled, make sure we're properly initialised each time we're called.
|
||||
registerIdeaVimDisabledCallback()
|
||||
initialised = true
|
||||
}
|
||||
|
||||
private fun registerIdeaVimDisabledCallback() {
|
||||
// TODO: IdeaVim should help with lifecycle management here - VIM-3419
|
||||
// IdeaVim should possibly unregister extensions, but it would also need to re-register them. We have to do this
|
||||
// state management manually for now
|
||||
Disposer.register(VimPlugin.getInstance().onOffDisposable) {
|
||||
highlightHandler.clearYankHighlighters()
|
||||
initialised = false
|
||||
}
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
// Called when the extension is disabled with `:set no{extension}` or if the plugin owning the extension unloads
|
||||
VimPlugin.getYank().removeListener(this)
|
||||
VimPlugin.getChange().removeInsertListener(this)
|
||||
|
||||
highlightHandler.clearYankHighlighters()
|
||||
initialised = false
|
||||
}
|
||||
|
||||
override fun yankPerformed(editor: VimEditor, range: TextRange) {
|
||||
ensureInitialised()
|
||||
highlightHandler.highlightYankRange(editor.ij, range)
|
||||
}
|
||||
|
||||
override fun insertModeStarted(editor: Editor) {
|
||||
highlightHandler.clearAllYankHighlighters()
|
||||
ensureInitialised()
|
||||
highlightHandler.clearYankHighlighters()
|
||||
}
|
||||
|
||||
private fun ensureInitialised() {
|
||||
if (!initialised) {
|
||||
registerIdeaVimDisabledCallback()
|
||||
initialised = true
|
||||
}
|
||||
}
|
||||
|
||||
private class HighlightHandler {
|
||||
private var editor: Editor? = null
|
||||
private val yankHighlighters: MutableSet<RangeHighlighter> = mutableSetOf()
|
||||
private val alarm = Alarm(ThreadToUse.SWING_THREAD)
|
||||
private var lastEditor: Editor? = null
|
||||
private val highlighters = mutableSetOf<RangeHighlighter>()
|
||||
|
||||
fun highlightYankRange(editor: Editor, range: TextRange) {
|
||||
// from vim-highlightedyank docs: When a new text is yanked or user starts editing, the old highlighting would be deleted
|
||||
clearAllYankHighlighters()
|
||||
clearYankHighlighters()
|
||||
|
||||
this.editor = editor
|
||||
val project = editor.project
|
||||
if (project != null) {
|
||||
Disposer.register(
|
||||
VimProjectService.getInstance(project),
|
||||
) {
|
||||
this.editor = null
|
||||
yankHighlighters.clear()
|
||||
}
|
||||
lastEditor = editor
|
||||
|
||||
val attributes = getHighlightTextAttributes(editor)
|
||||
for (i in 0 until range.size()) {
|
||||
val highlighter = editor.markupModel.addRangeHighlighter(
|
||||
range.startOffsets[i],
|
||||
range.endOffsets[i],
|
||||
HighlighterLayer.SELECTION,
|
||||
attributes,
|
||||
HighlighterTargetArea.EXACT_RANGE,
|
||||
)
|
||||
highlighters.add(highlighter)
|
||||
}
|
||||
|
||||
if (range.isMultiple) {
|
||||
for (i in 0 until range.size()) {
|
||||
highlightSingleRange(editor, range.startOffsets[i]..range.endOffsets[i])
|
||||
}
|
||||
} else {
|
||||
highlightSingleRange(editor, range.startOffset..range.endOffset)
|
||||
}
|
||||
}
|
||||
|
||||
fun clearAllYankHighlighters() {
|
||||
yankHighlighters.forEach { highlighter ->
|
||||
editor?.markupModel?.removeHighlighter(highlighter) ?: StrictMode.fail("Highlighters without an editor")
|
||||
}
|
||||
|
||||
yankHighlighters.clear()
|
||||
}
|
||||
|
||||
private fun highlightSingleRange(editor: Editor, range: ClosedRange<Int>) {
|
||||
val highlighter = editor.markupModel.addRangeHighlighter(
|
||||
range.start,
|
||||
range.endInclusive,
|
||||
HighlighterLayer.SELECTION,
|
||||
getHighlightTextAttributes(),
|
||||
HighlighterTargetArea.EXACT_RANGE,
|
||||
)
|
||||
|
||||
yankHighlighters.add(highlighter)
|
||||
|
||||
setClearHighlightRangeTimer(highlighter)
|
||||
}
|
||||
|
||||
private fun setClearHighlightRangeTimer(highlighter: RangeHighlighter) {
|
||||
val timeout = extractUsersHighlightDuration()
|
||||
|
||||
// from vim-highlightedyank docs: A negative number makes the highlight persistent.
|
||||
val timeout = extractUsersHighlightDuration()
|
||||
if (timeout >= 0) {
|
||||
Executors.newSingleThreadScheduledExecutor().schedule(
|
||||
{
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
editor?.markupModel?.removeHighlighter(highlighter) ?: StrictMode.fail("Highlighters without an editor")
|
||||
}
|
||||
},
|
||||
// Note modality. This is important when highlighting an editor when a modal dialog is open, such as the resolve
|
||||
// conflict diff view
|
||||
alarm.addRequest(
|
||||
{ clearYankHighlighters() },
|
||||
timeout,
|
||||
TimeUnit.MILLISECONDS,
|
||||
ModalityState.any()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getHighlightTextAttributes() = TextAttributes(
|
||||
fun clearYankHighlighters() {
|
||||
alarm.cancelAllRequests()
|
||||
// Make sure the last editor we saved is still alive before we use it. We can't just use the list of open editors
|
||||
// because this list is empty when IdeaVim is disabled, so we're unable to clean up
|
||||
lastEditor?.let { editor ->
|
||||
if (!editor.isDisposed) {
|
||||
highlighters.forEach { highlighter -> editor.markupModel.removeHighlighter(highlighter) }
|
||||
}
|
||||
}
|
||||
lastEditor = null
|
||||
highlighters.clear()
|
||||
}
|
||||
|
||||
private fun getHighlightTextAttributes(editor: Editor) = TextAttributes(
|
||||
null,
|
||||
extractUsersHighlightColor(),
|
||||
editor?.colorsScheme?.getColor(EditorColors.CARET_COLOR),
|
||||
editor.colorsScheme.getColor(EditorColors.CARET_COLOR),
|
||||
EffectType.SEARCH_MATCH,
|
||||
Font.PLAIN,
|
||||
)
|
||||
|
||||
private fun extractUsersHighlightDuration(): Long {
|
||||
private fun extractUsersHighlightDuration(): Int {
|
||||
return extractVariable(HIGHLIGHT_DURATION_VARIABLE_NAME, DEFAULT_HIGHLIGHT_DURATION) {
|
||||
it.toLong()
|
||||
// toVimNumber will return 0 for an invalid string. Let's force it to throw
|
||||
when (it) {
|
||||
is VimString -> it.value.toInt()
|
||||
else -> it.toVimNumber().value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun extractUsersHighlightColor(): Color {
|
||||
return extractVariable(HIGHLIGHT_COLOR_VARIABLE_NAME, getDefaultHighlightTextColor()) { value ->
|
||||
val rgba = value
|
||||
val rgba = value.asString()
|
||||
.substring(4)
|
||||
.filter { it != '(' && it != ')' && !it.isWhitespace() }
|
||||
.split(',')
|
||||
@@ -192,12 +208,11 @@ internal class VimHighlightedYank : VimExtension, VimYankListener, VimInsertList
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> extractVariable(variable: String, default: T, extractFun: (value: String) -> T): T {
|
||||
private fun <T> extractVariable(variable: String, default: T, extractFun: (value: VimDataType) -> T): T {
|
||||
val value = VimPlugin.getVariableService().getGlobalVariableValue(variable)
|
||||
|
||||
if (value is VimString) {
|
||||
if (value != null) {
|
||||
return try {
|
||||
extractFun(value.value)
|
||||
extractFun(value)
|
||||
} catch (e: Exception) {
|
||||
@VimNlsSafe val message = MessageHelper.message(
|
||||
"highlightedyank.invalid.value.of.0.1",
|
||||
|
@@ -99,7 +99,7 @@ internal class Matchit : VimExtension {
|
||||
|
||||
// Normally we want to jump to the start of the matching pair. But when moving forward in operator
|
||||
// pending mode, we want to include the entire match. isInOpPending makes that distinction.
|
||||
val isInOpPending = commandState.isOperatorPending
|
||||
val isInOpPending = commandState.isOperatorPending(editor.mode)
|
||||
|
||||
if (isInOpPending) {
|
||||
val matchitAction = MatchitAction()
|
||||
|
@@ -37,7 +37,7 @@ import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.common.CommandAlias
|
||||
import com.maddyhome.idea.vim.common.CommandAliasHandler
|
||||
import com.maddyhome.idea.vim.ex.ranges.Ranges
|
||||
import com.maddyhome.idea.vim.ex.ranges.Range
|
||||
import com.maddyhome.idea.vim.extension.VimExtension
|
||||
import com.maddyhome.idea.vim.group.KeyGroup
|
||||
import com.maddyhome.idea.vim.helper.MessageHelper
|
||||
@@ -130,32 +130,32 @@ internal class NerdTree : VimExtension {
|
||||
addCommand("NERDTreeFind", IjCommandHandler("SelectInProjectView"))
|
||||
addCommand("NERDTreeRefreshRoot", IjCommandHandler("Synchronize"))
|
||||
|
||||
synchronized(monitor) {
|
||||
commandsRegistered = true
|
||||
synchronized(Util.monitor) {
|
||||
Util.commandsRegistered = true
|
||||
ProjectManager.getInstance().openProjects.forEach { project -> installDispatcher(project) }
|
||||
}
|
||||
}
|
||||
|
||||
class IjCommandHandler(private val actionId: String) : CommandAliasHandler {
|
||||
override fun execute(command: String, ranges: Ranges, editor: VimEditor, context: ExecutionContext) {
|
||||
callAction(editor, actionId, context)
|
||||
override fun execute(command: String, range: Range, editor: VimEditor, context: ExecutionContext) {
|
||||
Util.callAction(editor, actionId, context)
|
||||
}
|
||||
}
|
||||
|
||||
class ToggleHandler : CommandAliasHandler {
|
||||
override fun execute(command: String, ranges: Ranges, editor: VimEditor, context: ExecutionContext) {
|
||||
override fun execute(command: String, range: Range, editor: VimEditor, context: ExecutionContext) {
|
||||
val project = editor.ij.project ?: return
|
||||
val toolWindow = ToolWindowManagerEx.getInstanceEx(project).getToolWindow(ToolWindowId.PROJECT_VIEW) ?: return
|
||||
if (toolWindow.isVisible) {
|
||||
toolWindow.hide()
|
||||
} else {
|
||||
callAction(editor, "ActivateProjectToolWindow", context)
|
||||
Util.callAction(editor, "ActivateProjectToolWindow", context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CloseHandler : CommandAliasHandler {
|
||||
override fun execute(command: String, ranges: Ranges, editor: VimEditor, context: ExecutionContext) {
|
||||
override fun execute(command: String, range: Range, editor: VimEditor, context: ExecutionContext) {
|
||||
val project = editor.ij.project ?: return
|
||||
val toolWindow = ToolWindowManagerEx.getInstanceEx(project).getToolWindow(ToolWindowId.PROJECT_VIEW) ?: return
|
||||
if (toolWindow.isVisible) {
|
||||
@@ -187,8 +187,8 @@ internal class NerdTree : VimExtension {
|
||||
// TODO I'm not sure is this activity runs at all? Should we use [RunOnceUtil] instead?
|
||||
class NerdStartupActivity : ProjectActivity {
|
||||
override suspend fun execute(project: Project) {
|
||||
synchronized(monitor) {
|
||||
if (!commandsRegistered) return
|
||||
synchronized(Util.monitor) {
|
||||
if (!Util.commandsRegistered) return
|
||||
installDispatcher(project)
|
||||
}
|
||||
}
|
||||
@@ -214,7 +214,7 @@ internal class NerdTree : VimExtension {
|
||||
|
||||
val action = nextNode.actionHolder
|
||||
when (action) {
|
||||
is NerdAction.ToIj -> callAction(null, action.name, e.dataContext.vim)
|
||||
is NerdAction.ToIj -> Util.callAction(null, action.name, e.dataContext.vim)
|
||||
is NerdAction.Code -> e.project?.let { action.action(it, e.dataContext, e) }
|
||||
}
|
||||
}
|
||||
@@ -356,7 +356,7 @@ internal class NerdTree : VimExtension {
|
||||
currentWindow?.split(SwingConstants.VERTICAL, true, file, true)
|
||||
|
||||
// FIXME: 22.01.2021 This solution bouncing a bit
|
||||
callAction(null, "ActivateProjectToolWindow", context.vim)
|
||||
Util.callAction(null, "ActivateProjectToolWindow", context.vim)
|
||||
},
|
||||
)
|
||||
registerCommand(
|
||||
@@ -368,7 +368,7 @@ internal class NerdTree : VimExtension {
|
||||
val currentWindow = splitters.currentWindow
|
||||
currentWindow?.split(SwingConstants.HORIZONTAL, true, file, true)
|
||||
|
||||
callAction(null, "ActivateProjectToolWindow", context.vim)
|
||||
Util.callAction(null, "ActivateProjectToolWindow", context.vim)
|
||||
},
|
||||
)
|
||||
registerCommand(
|
||||
@@ -477,6 +477,7 @@ internal class NerdTree : VimExtension {
|
||||
"r",
|
||||
NerdAction.ToIj("SynchronizeCurrentFile"),
|
||||
)
|
||||
registerCommand("NERDTreeMapToggleHidden", "I", NerdAction.ToIj("ProjectView.ShowExcludedFiles"))
|
||||
registerCommand("NERDTreeMapRefreshRoot", "R", NerdAction.ToIj("Synchronize"))
|
||||
registerCommand("NERDTreeMapMenu", "m", NerdAction.ToIj("ShowPopupMenu"))
|
||||
registerCommand("NERDTreeMapQuit", "q", NerdAction.ToIj("HideActiveWindow"))
|
||||
@@ -502,23 +503,11 @@ internal class NerdTree : VimExtension {
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
for (c in ('a'..'z') + ('A'..'Z')) {
|
||||
val ks = KeyStroke.getKeyStroke(c)
|
||||
if (ks !in actionsRoot) {
|
||||
registerCommand(c.toString(), NerdAction.Code { _, _, _ -> })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val pluginName = "NERDTree"
|
||||
|
||||
object Util {
|
||||
internal val monitor = Any()
|
||||
internal var commandsRegistered = false
|
||||
|
||||
private val LOG = logger<NerdTree>()
|
||||
|
||||
fun callAction(editor: VimEditor?, name: String, context: ExecutionContext) {
|
||||
val action = ActionManager.getInstance().getAction(name) ?: run {
|
||||
VimPlugin.showMessage(MessageHelper.message("action.not.found.0", name))
|
||||
@@ -533,45 +522,51 @@ internal class NerdTree : VimExtension {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addCommand(alias: String, handler: CommandAliasHandler) {
|
||||
VimPlugin.getCommand().setAlias(alias, CommandAlias.Call(0, -1, alias, handler))
|
||||
}
|
||||
|
||||
private fun registerCommand(variable: String, default: String, action: NerdAction) {
|
||||
val variableValue = VimPlugin.getVariableService().getGlobalVariableValue(variable)
|
||||
val mappings = if (variableValue is VimString) {
|
||||
variableValue.value
|
||||
} else {
|
||||
default
|
||||
}
|
||||
actionsRoot.addLeafs(mappings, action)
|
||||
}
|
||||
|
||||
private fun registerCommand(default: String, action: NerdAction) {
|
||||
actionsRoot.addLeafs(default, action)
|
||||
}
|
||||
|
||||
private val actionsRoot: RootNode<NerdAction> = RootNode()
|
||||
private var currentNode: CommandPartNode<NerdAction> = actionsRoot
|
||||
|
||||
private fun collectShortcuts(node: Node<NerdAction>): Set<KeyStroke> {
|
||||
return if (node is CommandPartNode<NerdAction>) {
|
||||
val res = node.keys.toMutableSet()
|
||||
res += node.values.map { collectShortcuts(it) }.flatten()
|
||||
res
|
||||
} else {
|
||||
emptySet()
|
||||
}
|
||||
}
|
||||
|
||||
private fun installDispatcher(project: Project) {
|
||||
val dispatcher = NerdDispatcher.getInstance(project)
|
||||
val shortcuts = collectShortcuts(actionsRoot).map { RequiredShortcut(it, MappingOwner.Plugin.get(pluginName)) }
|
||||
dispatcher.registerCustomShortcutSet(
|
||||
KeyGroup.toShortcutSet(shortcuts),
|
||||
(ProjectView.getInstance(project) as ProjectViewImpl).component,
|
||||
)
|
||||
}
|
||||
companion object {
|
||||
const val pluginName = "NERDTree"
|
||||
private val LOG = logger<NerdTree>()
|
||||
}
|
||||
}
|
||||
|
||||
private fun addCommand(alias: String, handler: CommandAliasHandler) {
|
||||
VimPlugin.getCommand().setAlias(alias, CommandAlias.Call(0, -1, alias, handler))
|
||||
}
|
||||
|
||||
private fun registerCommand(variable: String, default: String, action: NerdAction) {
|
||||
val variableValue = VimPlugin.getVariableService().getGlobalVariableValue(variable)
|
||||
val mappings = if (variableValue is VimString) {
|
||||
variableValue.value
|
||||
} else {
|
||||
default
|
||||
}
|
||||
actionsRoot.addLeafs(mappings, action)
|
||||
}
|
||||
|
||||
private fun registerCommand(default: String, action: NerdAction) {
|
||||
actionsRoot.addLeafs(default, action)
|
||||
}
|
||||
|
||||
|
||||
private val actionsRoot: RootNode<NerdAction> = RootNode()
|
||||
private var currentNode: CommandPartNode<NerdAction> = actionsRoot
|
||||
private fun collectShortcuts(node: Node<NerdAction>): Set<KeyStroke> {
|
||||
return if (node is CommandPartNode<NerdAction>) {
|
||||
val res = node.keys.toMutableSet()
|
||||
res += node.values.map { collectShortcuts(it) }.flatten()
|
||||
res
|
||||
} else {
|
||||
emptySet()
|
||||
}
|
||||
}
|
||||
|
||||
private fun installDispatcher(project: Project) {
|
||||
val dispatcher = NerdTree.NerdDispatcher.getInstance(project)
|
||||
val shortcuts =
|
||||
collectShortcuts(actionsRoot).map { RequiredShortcut(it, MappingOwner.Plugin.get(NerdTree.pluginName)) }
|
||||
dispatcher.registerCustomShortcutSet(
|
||||
KeyGroup.toShortcutSet(shortcuts),
|
||||
(ProjectView.getInstance(project) as ProjectViewImpl).component,
|
||||
)
|
||||
}
|
||||
|
@@ -9,10 +9,11 @@
|
||||
package com.maddyhome.idea.vim.extension.paragraphmotion
|
||||
|
||||
import com.intellij.openapi.editor.Caret
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.getLineEndForOffset
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.api.normalizeOffset
|
||||
import com.maddyhome.idea.vim.command.MappingMode
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.extension.ExtensionHandler
|
||||
@@ -20,8 +21,10 @@ import com.maddyhome.idea.vim.extension.VimExtension
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMappingIfMissing
|
||||
import com.maddyhome.idea.vim.helper.vimForEachCaret
|
||||
import com.maddyhome.idea.vim.key.MappingOwner
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
internal class ParagraphMotion : VimExtension {
|
||||
override fun getName(): String = "vim-paragraph-motion"
|
||||
@@ -30,8 +33,8 @@ internal class ParagraphMotion : VimExtension {
|
||||
VimExtensionFacade.putExtensionHandlerMapping(MappingMode.NXO, injector.parser.parseKeys("<Plug>(ParagraphNextMotion)"), owner, ParagraphMotionHandler(1), false)
|
||||
VimExtensionFacade.putExtensionHandlerMapping(MappingMode.NXO, injector.parser.parseKeys("<Plug>(ParagraphPrevMotion)"), owner, ParagraphMotionHandler(-1), false)
|
||||
|
||||
putKeyMappingIfMissing(MappingMode.NXO, injector.parser.parseKeys("}"), owner, injector.parser.parseKeys("<Plug>(ParagraphNextMotion)"), true)
|
||||
putKeyMappingIfMissing(MappingMode.NXO, injector.parser.parseKeys("{"), owner, injector.parser.parseKeys("<Plug>(ParagraphPrevMotion)"), true)
|
||||
putKeyMappingIfMissingFromAndToKeys(MappingMode.NXO, injector.parser.parseKeys("}"), owner, injector.parser.parseKeys("<Plug>(ParagraphNextMotion)"), true)
|
||||
putKeyMappingIfMissingFromAndToKeys(MappingMode.NXO, injector.parser.parseKeys("{"), owner, injector.parser.parseKeys("<Plug>(ParagraphPrevMotion)"), true)
|
||||
}
|
||||
|
||||
private class ParagraphMotionHandler(private val count: Int) : ExtensionHandler {
|
||||
@@ -45,7 +48,21 @@ internal class ParagraphMotion : VimExtension {
|
||||
}
|
||||
|
||||
fun moveCaretToNextParagraph(editor: VimEditor, caret: Caret, count: Int): Int? {
|
||||
return injector.searchHelper.findNextParagraph(editor, caret.vim, count, true)?.let(editor::getLineEndForOffset)
|
||||
return injector.searchHelper.findNextParagraph(editor, caret.vim, count, true)
|
||||
?.let { editor.normalizeOffset(it, true) }
|
||||
}
|
||||
}
|
||||
|
||||
// For VIM-3306
|
||||
@Suppress("SameParameterValue")
|
||||
private fun putKeyMappingIfMissingFromAndToKeys(
|
||||
modes: Set<MappingMode>,
|
||||
fromKeys: List<KeyStroke>,
|
||||
pluginOwner: MappingOwner,
|
||||
toKeys: List<KeyStroke>,
|
||||
recursive: Boolean,
|
||||
) {
|
||||
val filteredModes = modes.filterNotTo(HashSet()) { VimPlugin.getKey().hasmapfrom(it, fromKeys) }
|
||||
putKeyMappingIfMissing(filteredModes, fromKeys, pluginOwner, toKeys, recursive)
|
||||
}
|
||||
}
|
||||
|
@@ -8,30 +8,26 @@
|
||||
|
||||
package com.maddyhome.idea.vim.extension.replacewithregister
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.ImmutableVimCaret
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.getLineEndOffset
|
||||
import com.maddyhome.idea.vim.api.globalOptions
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.command.MappingMode
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType.CHARACTER_WISE
|
||||
import com.maddyhome.idea.vim.state.mode.isLine
|
||||
import com.maddyhome.idea.vim.state.mode.selectionType
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.extension.ExtensionHandler
|
||||
import com.maddyhome.idea.vim.extension.VimExtension
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.executeNormalWithoutMapping
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMappingIfMissing
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.setOperatorFunction
|
||||
import com.maddyhome.idea.vim.extension.exportOperatorFunction
|
||||
import com.maddyhome.idea.vim.group.visual.VimSelection
|
||||
import com.maddyhome.idea.vim.helper.exitVisualMode
|
||||
import com.maddyhome.idea.vim.state.mode.mode
|
||||
import com.maddyhome.idea.vim.helper.vimStateMachine
|
||||
import com.maddyhome.idea.vim.key.OperatorFunction
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
|
||||
@@ -39,6 +35,10 @@ import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.options.helpers.ClipboardOptionHelper
|
||||
import com.maddyhome.idea.vim.put.PutData
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
import com.maddyhome.idea.vim.state.mode.isLine
|
||||
import com.maddyhome.idea.vim.state.mode.selectionType
|
||||
import org.jetbrains.annotations.NonNls
|
||||
|
||||
internal class ReplaceWithRegister : VimExtension {
|
||||
@@ -53,17 +53,19 @@ internal class ReplaceWithRegister : VimExtension {
|
||||
putKeyMappingIfMissing(MappingMode.N, injector.parser.parseKeys("gr"), owner, injector.parser.parseKeys(RWR_OPERATOR), true)
|
||||
putKeyMappingIfMissing(MappingMode.N, injector.parser.parseKeys("grr"), owner, injector.parser.parseKeys(RWR_LINE), true)
|
||||
putKeyMappingIfMissing(MappingMode.X, injector.parser.parseKeys("gr"), owner, injector.parser.parseKeys(RWR_VISUAL), true)
|
||||
|
||||
VimExtensionFacade.exportOperatorFunction(OPERATOR_FUNC, Operator())
|
||||
}
|
||||
|
||||
private class RwrVisual : ExtensionHandler {
|
||||
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
|
||||
val typeInEditor = editor.mode.selectionType ?: CHARACTER_WISE
|
||||
val typeInEditor = editor.mode.selectionType ?: SelectionType.CHARACTER_WISE
|
||||
editor.sortedCarets().forEach { caret ->
|
||||
val selectionStart = caret.selectionStart
|
||||
val selectionEnd = caret.selectionEnd
|
||||
|
||||
val visualSelection = caret to VimSelection.create(selectionStart, selectionEnd - 1, typeInEditor, editor)
|
||||
doReplace(editor.ij, caret, PutData.VisualSelection(mapOf(visualSelection), typeInEditor))
|
||||
doReplace(editor.ij, context.ij, caret, PutData.VisualSelection(mapOf(visualSelection), typeInEditor))
|
||||
}
|
||||
editor.exitVisualMode()
|
||||
}
|
||||
@@ -73,7 +75,7 @@ internal class ReplaceWithRegister : VimExtension {
|
||||
override val isRepeatable: Boolean = true
|
||||
|
||||
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
|
||||
setOperatorFunction(Operator())
|
||||
injector.globalOptions().operatorfunc = OPERATOR_FUNC
|
||||
executeNormalWithoutMapping(injector.parser.parseKeys("g@"), editor.ij)
|
||||
}
|
||||
}
|
||||
@@ -91,7 +93,7 @@ internal class ReplaceWithRegister : VimExtension {
|
||||
val visualSelection = caret to VimSelection.create(lineStart, lineEnd, SelectionType.LINE_WISE, editor)
|
||||
caretsAndSelections += visualSelection
|
||||
|
||||
doReplace(editor.ij, caret, PutData.VisualSelection(mapOf(visualSelection), SelectionType.LINE_WISE))
|
||||
doReplace(editor.ij, context.ij, caret, PutData.VisualSelection(mapOf(visualSelection), SelectionType.LINE_WISE))
|
||||
}
|
||||
|
||||
editor.sortedCarets().forEach { caret ->
|
||||
@@ -112,14 +114,14 @@ internal class ReplaceWithRegister : VimExtension {
|
||||
editor.primaryCaret() to VimSelection.create(
|
||||
range.startOffset,
|
||||
range.endOffset - 1,
|
||||
selectionType ?: CHARACTER_WISE,
|
||||
selectionType ?: SelectionType.CHARACTER_WISE,
|
||||
editor,
|
||||
),
|
||||
),
|
||||
selectionType ?: CHARACTER_WISE,
|
||||
selectionType ?: SelectionType.CHARACTER_WISE,
|
||||
)
|
||||
// todo multicaret
|
||||
doReplace(ijEditor, editor.primaryCaret(), visualSelection)
|
||||
doReplace(ijEditor, context.ij, editor.primaryCaret(), visualSelection)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -132,52 +134,49 @@ internal class ReplaceWithRegister : VimExtension {
|
||||
}
|
||||
|
||||
companion object {
|
||||
@NonNls
|
||||
private const val RWR_OPERATOR = "<Plug>ReplaceWithRegisterOperator"
|
||||
|
||||
@NonNls
|
||||
private const val RWR_LINE = "<Plug>ReplaceWithRegisterLine"
|
||||
|
||||
@NonNls
|
||||
private const val RWR_VISUAL = "<Plug>ReplaceWithRegisterVisual"
|
||||
|
||||
private fun doReplace(editor: Editor, caret: ImmutableVimCaret, visualSelection: PutData.VisualSelection) {
|
||||
val registerGroup = injector.registerGroup
|
||||
val lastRegisterChar = if (editor.caretModel.caretCount == 1) registerGroup.currentRegister else registerGroup.getCurrentRegisterForMulticaret()
|
||||
val savedRegister = caret.registerStorage.getRegister(lastRegisterChar) ?: return
|
||||
|
||||
var usedType = savedRegister.type
|
||||
var usedText = savedRegister.text
|
||||
if (usedType.isLine && usedText?.endsWith('\n') == true) {
|
||||
// Code from original plugin implementation. Correct text for linewise selected text
|
||||
usedText = usedText.dropLast(1)
|
||||
usedType = SelectionType.CHARACTER_WISE
|
||||
}
|
||||
|
||||
val textData = PutData.TextData(usedText, usedType, savedRegister.transferableData, savedRegister.name)
|
||||
|
||||
val putData = PutData(
|
||||
textData,
|
||||
visualSelection,
|
||||
1,
|
||||
insertTextBeforeCaret = true,
|
||||
rawIndent = true,
|
||||
caretAfterInsertedText = false,
|
||||
putToLine = -1,
|
||||
)
|
||||
ClipboardOptionHelper.IdeaputDisabler().use {
|
||||
VimPlugin.getPut().putText(
|
||||
IjVimEditor(editor),
|
||||
injector.executionContextManager.onEditor(editor.vim),
|
||||
putData,
|
||||
operatorArguments = OperatorArguments(
|
||||
editor.vimStateMachine?.isOperatorPending ?: false,
|
||||
0,
|
||||
editor.vim.mode,
|
||||
),
|
||||
saveToRegister = false
|
||||
)
|
||||
}
|
||||
}
|
||||
@NonNls private const val RWR_OPERATOR = "<Plug>ReplaceWithRegisterOperator"
|
||||
@NonNls private const val RWR_LINE = "<Plug>ReplaceWithRegisterLine"
|
||||
@NonNls private const val RWR_VISUAL = "<Plug>ReplaceWithRegisterVisual"
|
||||
@NonNls private const val OPERATOR_FUNC = "ReplaceWithRegisterOperatorFunc"
|
||||
}
|
||||
}
|
||||
|
||||
private fun doReplace(editor: Editor, context: DataContext, caret: ImmutableVimCaret, visualSelection: PutData.VisualSelection) {
|
||||
val registerGroup = injector.registerGroup
|
||||
val lastRegisterChar = if (editor.caretModel.caretCount == 1) registerGroup.currentRegister else registerGroup.getCurrentRegisterForMulticaret()
|
||||
val savedRegister = caret.registerStorage.getRegister(lastRegisterChar) ?: return
|
||||
|
||||
var usedType = savedRegister.type
|
||||
var usedText = savedRegister.text
|
||||
if (usedType.isLine && usedText?.endsWith('\n') == true) {
|
||||
// Code from original plugin implementation. Correct text for linewise selected text
|
||||
usedText = usedText.dropLast(1)
|
||||
usedType = SelectionType.CHARACTER_WISE
|
||||
}
|
||||
|
||||
val textData = PutData.TextData(usedText, usedType, savedRegister.transferableData, savedRegister.name)
|
||||
|
||||
val putData = PutData(
|
||||
textData,
|
||||
visualSelection,
|
||||
1,
|
||||
insertTextBeforeCaret = true,
|
||||
rawIndent = true,
|
||||
caretAfterInsertedText = false,
|
||||
putToLine = -1,
|
||||
)
|
||||
val vimEditor = editor.vim
|
||||
ClipboardOptionHelper.IdeaputDisabler().use {
|
||||
VimPlugin.getPut().putText(
|
||||
vimEditor,
|
||||
context.vim,
|
||||
putData,
|
||||
operatorArguments = OperatorArguments(
|
||||
editor.vimStateMachine?.isOperatorPending(vimEditor.mode) ?: false,
|
||||
0,
|
||||
editor.vim.mode,
|
||||
),
|
||||
saveToRegister = false
|
||||
)
|
||||
}
|
||||
}
|
@@ -36,6 +36,7 @@ import com.maddyhome.idea.vim.helper.StrictMode
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import java.awt.Font
|
||||
import java.awt.event.KeyEvent
|
||||
import java.util.*
|
||||
import javax.swing.Timer
|
||||
|
||||
|
||||
@@ -48,17 +49,20 @@ internal class IdeaVimSneakExtension : VimExtension {
|
||||
|
||||
override fun init() {
|
||||
val highlightHandler = HighlightHandler()
|
||||
mapToFunctionAndProvideKeys("s", SneakHandler(highlightHandler, Direction.FORWARD))
|
||||
mapToFunctionAndProvideKeys("S", SneakHandler(highlightHandler, Direction.BACKWARD))
|
||||
mapToFunctionAndProvideKeys("s", SneakHandler(highlightHandler, Direction.FORWARD), MappingMode.NXO)
|
||||
|
||||
// vim-sneak uses `Z` for visual mode because `S` conflict with vim-sneak plugin VIM-3330
|
||||
mapToFunctionAndProvideKeys("S", SneakHandler(highlightHandler, Direction.BACKWARD), MappingMode.NO)
|
||||
mapToFunctionAndProvideKeys("Z", SneakHandler(highlightHandler, Direction.BACKWARD), MappingMode.X)
|
||||
|
||||
// workaround to support ; and , commands
|
||||
mapToFunctionAndProvideKeys("f", SneakMemoryHandler("f"))
|
||||
mapToFunctionAndProvideKeys("F", SneakMemoryHandler("F"))
|
||||
mapToFunctionAndProvideKeys("t", SneakMemoryHandler("t"))
|
||||
mapToFunctionAndProvideKeys("T", SneakMemoryHandler("T"))
|
||||
mapToFunctionAndProvideKeys("f", SneakMemoryHandler("f"), MappingMode.NXO)
|
||||
mapToFunctionAndProvideKeys("F", SneakMemoryHandler("F"), MappingMode.NXO)
|
||||
mapToFunctionAndProvideKeys("t", SneakMemoryHandler("t"), MappingMode.NXO)
|
||||
mapToFunctionAndProvideKeys("T", SneakMemoryHandler("T"), MappingMode.NXO)
|
||||
|
||||
mapToFunctionAndProvideKeys(";", SneakRepeatHandler(highlightHandler, RepeatDirection.IDENTICAL))
|
||||
mapToFunctionAndProvideKeys(",", SneakRepeatHandler(highlightHandler, RepeatDirection.REVERSE))
|
||||
mapToFunctionAndProvideKeys(";", SneakRepeatHandler(highlightHandler, RepeatDirection.IDENTICAL), MappingMode.NXO)
|
||||
mapToFunctionAndProvideKeys(",", SneakRepeatHandler(highlightHandler, RepeatDirection.REVERSE), MappingMode.NXO)
|
||||
}
|
||||
|
||||
private class SneakHandler(
|
||||
@@ -114,7 +118,7 @@ internal class IdeaVimSneakExtension : VimExtension {
|
||||
var lastSymbols: String = ""
|
||||
fun jumpTo(editor: VimEditor, charone: Char, chartwo: Char, sneakDirection: Direction): TextRange? {
|
||||
val caret = editor.primaryCaret()
|
||||
val position = caret.offset.point
|
||||
val position = caret.offset
|
||||
val chars = editor.text()
|
||||
val foundPosition = sneakDirection.findBiChar(editor, chars, position, charone, chartwo)
|
||||
if (foundPosition != null) {
|
||||
@@ -273,16 +277,18 @@ internal class IdeaVimSneakExtension : VimExtension {
|
||||
* Map some <Plug>(keys) command to given handler
|
||||
* and create mapping to <Plug>(prefix)[keys]
|
||||
*/
|
||||
private fun VimExtension.mapToFunctionAndProvideKeys(keys: String, handler: ExtensionHandler) {
|
||||
private fun VimExtension.mapToFunctionAndProvideKeys(
|
||||
keys: String, handler: ExtensionHandler, mappingModes: EnumSet<MappingMode>
|
||||
) {
|
||||
VimExtensionFacade.putExtensionHandlerMapping(
|
||||
MappingMode.NXO,
|
||||
mappingModes,
|
||||
injector.parser.parseKeys(command(keys)),
|
||||
owner,
|
||||
handler,
|
||||
false
|
||||
)
|
||||
VimExtensionFacade.putExtensionHandlerMapping(
|
||||
MappingMode.NXO,
|
||||
mappingModes,
|
||||
injector.parser.parseKeys(commandFromOriginalPlugin(keys)),
|
||||
owner,
|
||||
handler,
|
||||
@@ -294,17 +300,17 @@ private fun VimExtension.mapToFunctionAndProvideKeys(keys: String, handler: Exte
|
||||
// - The shortcut should not be registered if any of these mappings is overridden in .ideavimrc
|
||||
// - The shortcut should not be registered if some other shortcut for this key exists
|
||||
val fromKeys = injector.parser.parseKeys(keys)
|
||||
val filteredModes = MappingMode.NXO.filterNotTo(HashSet()) {
|
||||
val filteredModes = mappingModes.filterNotTo(HashSet()) {
|
||||
VimPlugin.getKey().hasmapto(it, injector.parser.parseKeys(command(keys)))
|
||||
}
|
||||
val filteredModes2 = MappingMode.NXO.filterNotTo(HashSet()) {
|
||||
val filteredModes2 = mappingModes.filterNotTo(HashSet()) {
|
||||
VimPlugin.getKey().hasmapto(it, injector.parser.parseKeys(commandFromOriginalPlugin(keys)))
|
||||
}
|
||||
val filteredFromModes = MappingMode.NXO.filterNotTo(HashSet()) {
|
||||
val filteredFromModes = mappingModes.filterNotTo(HashSet()) {
|
||||
injector.keyGroup.hasmapfrom(it, fromKeys)
|
||||
}
|
||||
|
||||
val doubleFiltered = MappingMode.NXO
|
||||
val doubleFiltered = mappingModes
|
||||
.filter { it in filteredModes2 && it in filteredModes && it in filteredFromModes }
|
||||
.toSet()
|
||||
putKeyMapping(doubleFiltered, fromKeys, owner, injector.parser.parseKeys(command(keys)), true)
|
||||
|
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
package com.maddyhome.idea.vim.extension.surround
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.application.runWriteAction
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.editor.Editor
|
||||
@@ -17,6 +18,7 @@ import com.maddyhome.idea.vim.api.VimChangeGroup
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.endsWithNewLine
|
||||
import com.maddyhome.idea.vim.api.getLeadingCharacterOffset
|
||||
import com.maddyhome.idea.vim.api.globalOptions
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.api.setChangeMarks
|
||||
import com.maddyhome.idea.vim.command.MappingMode
|
||||
@@ -24,14 +26,16 @@ import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.extension.ExtensionHandler
|
||||
import com.maddyhome.idea.vim.extension.VimExtension
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.executeNormalWithoutMapping
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.getRegisterForCaret
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.inputKeyStroke
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.inputString
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putExtensionHandlerMapping
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMappingIfMissing
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.setOperatorFunction
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionFacade.setRegisterForCaret
|
||||
import com.maddyhome.idea.vim.extension.exportOperatorFunction
|
||||
import com.maddyhome.idea.vim.group.findBlockRange
|
||||
import com.maddyhome.idea.vim.helper.runWithEveryCaretAndRestore
|
||||
import com.maddyhome.idea.vim.key.OperatorFunction
|
||||
import com.maddyhome.idea.vim.newapi.IjVimCaret
|
||||
@@ -42,7 +46,6 @@ import com.maddyhome.idea.vim.options.helpers.ClipboardOptionHelper
|
||||
import com.maddyhome.idea.vim.put.PutData
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
import com.maddyhome.idea.vim.state.mode.mode
|
||||
import com.maddyhome.idea.vim.state.mode.selectionType
|
||||
import org.jetbrains.annotations.NonNls
|
||||
import java.awt.event.KeyEvent
|
||||
@@ -78,13 +81,15 @@ internal class VimSurroundExtension : VimExtension {
|
||||
putKeyMappingIfMissing(MappingMode.N, injector.parser.parseKeys("ds"), owner, injector.parser.parseKeys("<Plug>DSurround"), true)
|
||||
putKeyMappingIfMissing(MappingMode.XO, injector.parser.parseKeys("S"), owner, injector.parser.parseKeys("<Plug>VSurround"), true)
|
||||
}
|
||||
|
||||
VimExtensionFacade.exportOperatorFunction(OPERATOR_FUNC, Operator(supportsMultipleCursors = false, count = 1)) // TODO
|
||||
}
|
||||
|
||||
private class YSurroundHandler : ExtensionHandler {
|
||||
override val isRepeatable = true
|
||||
|
||||
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
|
||||
setOperatorFunction(Operator(supportsMultipleCursors = false, count = 1)) // TODO
|
||||
injector.globalOptions().operatorfunc = OPERATOR_FUNC
|
||||
executeNormalWithoutMapping(injector.parser.parseKeys("g@"), editor.ij)
|
||||
}
|
||||
}
|
||||
@@ -96,7 +101,7 @@ internal class VimSurroundExtension : VimExtension {
|
||||
val ijEditor = editor.ij
|
||||
val c = getChar(ijEditor)
|
||||
if (c.code == 0) return
|
||||
val pair = getOrInputPair(c, ijEditor) ?: return
|
||||
val pair = getOrInputPair(c, ijEditor, context.ij) ?: return
|
||||
|
||||
editor.forEachCaret {
|
||||
val line = it.getBufferPosition().line
|
||||
@@ -146,7 +151,7 @@ internal class VimSurroundExtension : VimExtension {
|
||||
val charTo = getChar(editor.ij)
|
||||
if (charTo.code == 0) return
|
||||
|
||||
val newSurround = getOrInputPair(charTo, editor.ij) ?: return
|
||||
val newSurround = getOrInputPair(charTo, editor.ij, context.ij) ?: return
|
||||
runWriteAction { change(editor, context, charFrom, newSurround) }
|
||||
}
|
||||
|
||||
@@ -223,12 +228,12 @@ internal class VimSurroundExtension : VimExtension {
|
||||
val searchHelper = injector.searchHelper
|
||||
return when (char) {
|
||||
't' -> searchHelper.findBlockTagRange(editor, caret, 1, true)
|
||||
'(', ')', 'b' -> searchHelper.findBlockRange(editor, caret, '(', 1, true)
|
||||
'[', ']' -> searchHelper.findBlockRange(editor, caret, '[', 1, true)
|
||||
'{', '}', 'B' -> searchHelper.findBlockRange(editor, caret, '{', 1, true)
|
||||
'<', '>' -> searchHelper.findBlockRange(editor, caret, '<', 1, true)
|
||||
'(', ')', 'b' -> findBlockRange(editor, caret, '(', 1, true)
|
||||
'[', ']' -> findBlockRange(editor, caret, '[', 1, true)
|
||||
'{', '}', 'B' -> findBlockRange(editor, caret, '{', 1, true)
|
||||
'<', '>' -> findBlockRange(editor, caret, '<', 1, true)
|
||||
'`', '\'', '"' -> {
|
||||
val caretOffset = caret.offset.point
|
||||
val caretOffset = caret.offset
|
||||
val text = editor.text()
|
||||
if (text.getOrNull(caretOffset - 1) == char && text.getOrNull(caretOffset) == char) {
|
||||
TextRange(caretOffset - 1, caretOffset + 1)
|
||||
@@ -265,23 +270,23 @@ internal class VimSurroundExtension : VimExtension {
|
||||
|
||||
private class Operator(private val supportsMultipleCursors: Boolean, private val count: Int) : OperatorFunction {
|
||||
override fun apply(vimEditor: VimEditor, context: ExecutionContext, selectionType: SelectionType?): Boolean {
|
||||
val editor = vimEditor.ij
|
||||
val c = getChar(editor)
|
||||
val ijEditor = vimEditor.ij
|
||||
val c = getChar(ijEditor)
|
||||
if (c.code == 0) return true
|
||||
|
||||
val pair = getOrInputPair(c, editor) ?: return false
|
||||
val pair = getOrInputPair(c, ijEditor, context.ij) ?: return false
|
||||
|
||||
runWriteAction {
|
||||
val change = VimPlugin.getChange()
|
||||
if (supportsMultipleCursors) {
|
||||
editor.runWithEveryCaretAndRestore {
|
||||
applyOnce(editor, change, pair, count)
|
||||
ijEditor.runWithEveryCaretAndRestore {
|
||||
applyOnce(ijEditor, change, pair, count)
|
||||
}
|
||||
}
|
||||
else {
|
||||
applyOnce(editor, change, pair, count)
|
||||
applyOnce(ijEditor, change, pair, count)
|
||||
// Jump back to start
|
||||
executeNormalWithoutMapping(injector.parser.parseKeys("`["), editor)
|
||||
executeNormalWithoutMapping(injector.parser.parseKeys("`["), ijEditor)
|
||||
}
|
||||
}
|
||||
return true
|
||||
@@ -315,7 +320,9 @@ private val LOG = logger<VimSurroundExtension>()
|
||||
|
||||
private const val REGISTER = '"'
|
||||
|
||||
private val tagNameAndAttributesCapturePattern = "(\\S+)([^>]*)>".toPattern()
|
||||
private const val OPERATOR_FUNC = "SurroundOperatorFunc"
|
||||
|
||||
private val tagNameAndAttributesCapturePattern = "(\\S+)([^>]*)>".toPattern()
|
||||
|
||||
private val SURROUND_PAIRS = mapOf(
|
||||
'b' to ("(" to ")"),
|
||||
@@ -341,8 +348,8 @@ private fun getSurroundPair(c: Char): Pair<String, String>? = if (c in SURROUND_
|
||||
null
|
||||
}
|
||||
|
||||
private fun inputTagPair(editor: Editor): Pair<String, String>? {
|
||||
val tagInput = inputString(editor, "<", '>')
|
||||
private fun inputTagPair(editor: Editor, context: DataContext): Pair<String, String>? {
|
||||
val tagInput = inputString(editor, context, "<", '>')
|
||||
val matcher = tagNameAndAttributesCapturePattern.matcher(tagInput)
|
||||
return if (matcher.find()) {
|
||||
val tagName = matcher.group(1)
|
||||
@@ -355,17 +362,18 @@ private fun inputTagPair(editor: Editor): Pair<String, String>? {
|
||||
|
||||
private fun inputFunctionName(
|
||||
editor: Editor,
|
||||
context: DataContext,
|
||||
withInternalSpaces: Boolean,
|
||||
): Pair<String, String>? {
|
||||
val functionNameInput = inputString(editor, "function: ", null)
|
||||
val functionNameInput = inputString(editor, context, "function: ", null)
|
||||
if (functionNameInput.isEmpty()) return null
|
||||
return if (withInternalSpaces) "$functionNameInput( " to " )" else "$functionNameInput(" to ")"
|
||||
}
|
||||
|
||||
private fun getOrInputPair(c: Char, editor: Editor): Pair<String, String>? = when (c) {
|
||||
'<', 't' -> inputTagPair(editor)
|
||||
'f' -> inputFunctionName(editor, false)
|
||||
'F' -> inputFunctionName(editor, true)
|
||||
private fun getOrInputPair(c: Char, editor: Editor, context: DataContext): Pair<String, String>? = when (c) {
|
||||
'<', 't' -> inputTagPair(editor, context)
|
||||
'f' -> inputFunctionName(editor, context, false)
|
||||
'F' -> inputFunctionName(editor, context, true)
|
||||
else -> getSurroundPair(c)
|
||||
}
|
||||
|
||||
|
@@ -138,7 +138,7 @@ public class VimTextObjEntireExtension implements VimExtension {
|
||||
|
||||
final EntireTextObjectHandler textObjectHandler = new EntireTextObjectHandler(ignoreLeadingAndTrailing);
|
||||
//noinspection DuplicatedCode
|
||||
if (!vimStateMachine.isOperatorPending()) {
|
||||
if (!vimStateMachine.isOperatorPending(editor.getMode())) {
|
||||
((IjVimEditor) editor).getEditor().getCaretModel().runForEachCaret((Caret caret) -> {
|
||||
final TextRange range = textObjectHandler.getRange(editor, new IjVimCaret(caret), context, count, 0);
|
||||
if (range != null) {
|
||||
|
@@ -131,10 +131,11 @@ public class VimIndentObject implements VimExtension {
|
||||
// This is done as a separate step so that it works even when the caret is inside the indentation.
|
||||
int offset = caretLineStartOffset;
|
||||
int indentSize = 0;
|
||||
while (++offset < charSequence.length()) {
|
||||
while (offset < charSequence.length()) {
|
||||
final char ch = charSequence.charAt(offset);
|
||||
if (ch == ' ' || ch == '\t') {
|
||||
++indentSize;
|
||||
++offset;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@@ -267,7 +268,7 @@ public class VimIndentObject implements VimExtension {
|
||||
|
||||
final IndentObjectHandler textObjectHandler = new IndentObjectHandler(includeAbove, includeBelow);
|
||||
|
||||
if (!vimStateMachine.isOperatorPending()) {
|
||||
if (!vimStateMachine.isOperatorPending(editor.getMode())) {
|
||||
((IjVimEditor)editor).getEditor().getCaretModel().runForEachCaret((Caret caret) -> {
|
||||
final TextRange range = textObjectHandler.getRange(vimEditor, new IjVimCaret(caret), context, count, 0);
|
||||
if (range != null) {
|
||||
|
@@ -68,10 +68,11 @@ import com.maddyhome.idea.vim.newapi.IjEditorExecutionContext
|
||||
import com.maddyhome.idea.vim.newapi.IjVimCaret
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.regexp.VimRegex
|
||||
import com.maddyhome.idea.vim.regexp.match.VimMatchResult
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
import com.maddyhome.idea.vim.state.mode.Mode.VISUAL
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
import com.maddyhome.idea.vim.state.mode.mode
|
||||
import com.maddyhome.idea.vim.vimscript.model.commands.SortOption
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import java.math.BigInteger
|
||||
@@ -196,7 +197,7 @@ public class ChangeGroup : VimChangeGroupBase() {
|
||||
val allowWrap = injector.options(editor).whichwrap.contains("~")
|
||||
var motion = injector.motion.getHorizontalMotion(editor, caret, count, true, allowWrap)
|
||||
if (motion is Motion.Error) return false
|
||||
changeCase(editor, caret, caret.offset.point, (motion as AbsoluteOffset).offset, CharacterHelper.CASE_TOGGLE)
|
||||
changeCase(editor, caret, caret.offset, (motion as AbsoluteOffset).offset, CharacterHelper.CASE_TOGGLE)
|
||||
motion = injector.motion.getHorizontalMotion(
|
||||
editor,
|
||||
caret,
|
||||
@@ -234,8 +235,7 @@ public class ChangeGroup : VimChangeGroupBase() {
|
||||
}
|
||||
val lineLength = editor.lineLength(line)
|
||||
if (column < VimMotionGroupBase.LAST_COLUMN && lineLength < column) {
|
||||
val pad =
|
||||
EditorHelper.pad((editor as IjVimEditor).editor, (context as IjEditorExecutionContext).context, line, column)
|
||||
val pad = EditorHelper.pad((editor as IjVimEditor).editor, line, column)
|
||||
val offset = editor.getLineEndOffset(line)
|
||||
insertText(editor, caret, offset, pad)
|
||||
}
|
||||
@@ -394,7 +394,7 @@ public class ChangeGroup : VimChangeGroupBase() {
|
||||
context: ExecutionContext,
|
||||
range: TextRange,
|
||||
) {
|
||||
val startPos = editor.offsetToBufferPosition(caret.offset.point)
|
||||
val startPos = editor.offsetToBufferPosition(caret.offset)
|
||||
val startOffset = editor.getLineStartForOffset(range.startOffset)
|
||||
val endOffset = editor.getLineEndForOffset(range.endOffset)
|
||||
val ijEditor = (editor as IjVimEditor).editor
|
||||
@@ -450,7 +450,7 @@ public class ChangeGroup : VimChangeGroupBase() {
|
||||
dir: Int,
|
||||
operatorArguments: OperatorArguments,
|
||||
) {
|
||||
val start = caret.offset.point
|
||||
val start = caret.offset
|
||||
val end = injector.motion.moveCaretToRelativeLineEnd(editor, caret, lines - 1, true)
|
||||
indentRange(editor, caret, context, TextRange(start, end), 1, dir, operatorArguments)
|
||||
}
|
||||
@@ -484,7 +484,7 @@ public class ChangeGroup : VimChangeGroupBase() {
|
||||
|
||||
// Remember the current caret column
|
||||
val intendedColumn = caret.vimLastColumn
|
||||
val indentConfig = create((editor as IjVimEditor).editor, (context as IjEditorExecutionContext).context)
|
||||
val indentConfig = create((editor as IjVimEditor).editor)
|
||||
val sline = editor.offsetToBufferPosition(range.startOffset).line
|
||||
val endLogicalPosition = editor.offsetToBufferPosition(range.endOffset)
|
||||
val eline = if (endLogicalPosition.column == 0) max((endLogicalPosition.line - 1).toDouble(), 0.0)
|
||||
@@ -567,54 +567,68 @@ public class ChangeGroup : VimChangeGroupBase() {
|
||||
): Boolean {
|
||||
val startLine = range.startLine
|
||||
val endLine = range.endLine
|
||||
val count = endLine - startLine + 1
|
||||
val count = range.size
|
||||
if (count < 2) {
|
||||
return false
|
||||
}
|
||||
val startOffset = editor.getLineStartOffset(startLine)
|
||||
val endOffset = editor.getLineEndOffset(endLine)
|
||||
return sortTextRange(editor, caret, startOffset, endOffset, lineComparator, sortOptions)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts a text range with a comparator. Returns true if a replace was performed, false otherwise.
|
||||
*
|
||||
* @param editor The editor to replace text in
|
||||
* @param start The starting position for the sort
|
||||
* @param end The ending position for the sort
|
||||
* @param lineComparator The comparator to use to sort
|
||||
* @param sortOption The option to sort the range
|
||||
* @return true if able to sort the text, false if not
|
||||
*/
|
||||
private fun sortTextRange(
|
||||
editor: VimEditor,
|
||||
caret: VimCaret,
|
||||
start: Int,
|
||||
end: Int,
|
||||
lineComparator: Comparator<String>,
|
||||
sortOption: SortOption,
|
||||
): Boolean {
|
||||
val selectedText = (editor as IjVimEditor).editor.document.getText(TextRangeInterval(start, end))
|
||||
val lines: MutableList<String> = selectedText.split("\n").sortedWith(lineComparator).toMutableList()
|
||||
if (sortOption.unique) {
|
||||
val iterator = lines.iterator()
|
||||
val selectedText = (editor as IjVimEditor).editor.document.getText(TextRangeInterval(startOffset, endOffset))
|
||||
val lines = selectedText.split("\n")
|
||||
val modifiedLines = sortOptions.pattern?.let {
|
||||
if (sortOptions.sortOnPattern) {
|
||||
extractPatternFromLines(editor, lines, startLine, it)
|
||||
} else {
|
||||
deletePatternFromLines(editor, lines, startLine, it)
|
||||
}
|
||||
} ?: lines
|
||||
val sortedLines = lines.zip(modifiedLines)
|
||||
.sortedWith { l1, l2 -> lineComparator.compare(l1.second, l2.second) }
|
||||
.map {it.first}
|
||||
.toMutableList()
|
||||
|
||||
if (sortOptions.unique) {
|
||||
val iterator = sortedLines.iterator()
|
||||
var previous: String? = null
|
||||
while (iterator.hasNext()) {
|
||||
val current = iterator.next()
|
||||
if (current == previous || sortOption.ignoreCase && current.equals(previous, ignoreCase = true)) {
|
||||
if (current == previous || sortOptions.ignoreCase && current.equals(previous, ignoreCase = true)) {
|
||||
iterator.remove()
|
||||
} else {
|
||||
previous = current
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lines.size < 1) {
|
||||
if (sortedLines.isEmpty()) {
|
||||
return false
|
||||
}
|
||||
replaceText(editor, caret, start, end, StringUtil.join(lines, "\n"))
|
||||
replaceText(editor, caret, startOffset, endOffset, StringUtil.join(sortedLines, "\n"))
|
||||
return true
|
||||
}
|
||||
|
||||
private fun extractPatternFromLines(editor: VimEditor, lines: List<String>, startLine: Int, pattern: String): List<String> {
|
||||
val regex = VimRegex(pattern)
|
||||
return lines.mapIndexed { i: Int, line: String ->
|
||||
val result = regex.findInLine(editor, startLine + i, 0)
|
||||
when (result) {
|
||||
is VimMatchResult.Success -> result.value
|
||||
is VimMatchResult.Failure -> line
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun deletePatternFromLines(editor: VimEditor, lines: List<String>, startLine: Int, pattern: String): List<String> {
|
||||
val regex = VimRegex(pattern)
|
||||
return lines.mapIndexed { i: Int, line: String ->
|
||||
val result = regex.findInLine(editor, startLine + i, 0)
|
||||
when (result) {
|
||||
is VimMatchResult.Success -> line.substring(result.value.length, line.length)
|
||||
is VimMatchResult.Failure -> line
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform increment and decrement for numbers in visual mode
|
||||
*
|
||||
|
@@ -8,9 +8,11 @@
|
||||
|
||||
package com.maddyhome.idea.vim.group
|
||||
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.maddyhome.idea.vim.api.VimCommandGroupBase
|
||||
|
||||
/**
|
||||
* @author Elliot Courant
|
||||
*/
|
||||
@Service
|
||||
internal class CommandGroup : VimCommandGroupBase()
|
||||
|
@@ -11,6 +11,9 @@ package com.maddyhome.idea.vim.group;
|
||||
import com.intellij.execution.impl.ConsoleViewImpl;
|
||||
import com.intellij.find.EditorSearchSession;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.client.ClientAppSession;
|
||||
import com.intellij.openapi.client.ClientKind;
|
||||
import com.intellij.openapi.client.ClientSessionsManager;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
@@ -22,7 +25,10 @@ import com.intellij.openapi.project.Project;
|
||||
import com.maddyhome.idea.vim.KeyHandler;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.api.*;
|
||||
import com.maddyhome.idea.vim.helper.*;
|
||||
import com.maddyhome.idea.vim.helper.CaretVisualAttributesHelperKt;
|
||||
import com.maddyhome.idea.vim.helper.CommandStateHelper;
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper;
|
||||
import com.maddyhome.idea.vim.helper.UserDataManager;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimDocument;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import com.maddyhome.idea.vim.options.EffectiveOptionValueChangeListener;
|
||||
@@ -33,11 +39,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.intellij.openapi.editor.EditorSettings.*;
|
||||
import static com.maddyhome.idea.vim.api.VimInjectorKt.injector;
|
||||
import static com.maddyhome.idea.vim.api.VimInjectorKt.options;
|
||||
import static com.maddyhome.idea.vim.helper.CaretVisualAttributesHelperKt.updateCaretsVisualAttributes;
|
||||
import static com.maddyhome.idea.vim.newapi.IjVimInjectorKt.ijOptions;
|
||||
|
||||
/**
|
||||
@@ -49,12 +56,31 @@ public class EditorGroup implements PersistentStateComponent<Element>, VimEditor
|
||||
|
||||
private Boolean isKeyRepeat = null;
|
||||
|
||||
// TODO: Get rid of this custom line converter once we support soft wraps properly
|
||||
// The builtin relative line converter looks like it's using Vim's logical lines for counting, where a Vim logical
|
||||
// line is a buffer line, or a single line representing a fold of several buffer lines. This converter is counting
|
||||
// screen lines (but badly - if you're on the second line of a wrapped line, it still counts like you're on the first.
|
||||
// We really want to use Vim logical lines, but we don't currently support them for movement - we move by screen line.
|
||||
|
||||
private final CaretListener myLineNumbersCaretListener = new CaretListener() {
|
||||
@Override
|
||||
public void caretPositionChanged(@NotNull CaretEvent e) {
|
||||
final boolean requiresRepaint = e.getNewPosition().line != e.getOldPosition().line;
|
||||
if (requiresRepaint && options(injector, new IjVimEditor(e.getEditor())).getRelativenumber()) {
|
||||
repaintRelativeLineNumbers(e.getEditor());
|
||||
// We don't get notified when the IDE's settings change, so make sure we're up-to-date when the caret moves
|
||||
final Editor editor = e.getEditor();
|
||||
boolean relativenumber = ijOptions(injector, new IjVimEditor(editor)).getRelativenumber();
|
||||
if (relativenumber) {
|
||||
if (!hasRelativeLineNumbersInstalled(editor)) {
|
||||
installRelativeLineNumbers(editor);
|
||||
}
|
||||
else {
|
||||
// We must repaint on each caret move, so we update when caret's visual line doesn't match logical line
|
||||
repaintRelativeLineNumbers(editor);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (hasRelativeLineNumbersInstalled(editor)) {
|
||||
removeRelativeLineNumbers(editor);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -67,11 +93,10 @@ public class EditorGroup implements PersistentStateComponent<Element>, VimEditor
|
||||
editor.getCaretModel().addCaretListener(myLineNumbersCaretListener);
|
||||
UserDataManager.setVimEditorGroup(editor, true);
|
||||
|
||||
UserDataManager.setVimLineNumbersInitialState(editor, editor.getSettings().isLineNumbersShown());
|
||||
updateLineNumbers(editor);
|
||||
}
|
||||
|
||||
private void deinitLineNumbers(@NotNull Editor editor, boolean isReleasing) {
|
||||
private void deinitLineNumbers(@NotNull Editor editor) {
|
||||
if (isProjectDisposed(editor) || !supportsVimLineNumbers(editor) || !UserDataManager.getVimEditorGroup(editor)) {
|
||||
return;
|
||||
}
|
||||
@@ -80,14 +105,6 @@ public class EditorGroup implements PersistentStateComponent<Element>, VimEditor
|
||||
UserDataManager.setVimEditorGroup(editor, false);
|
||||
|
||||
removeRelativeLineNumbers(editor);
|
||||
|
||||
// Don't reset the built in line numbers if we're releasing the editor. If we do, EditorSettings.setLineNumbersShown
|
||||
// can cause the editor to refresh settings and can call into FileManagerImpl.getCachedPsiFile AFTER FileManagerImpl
|
||||
// has been disposed (Closing the project with a Find Usages result showing a preview panel is a good repro case).
|
||||
// See IDEA-184351 and VIM-1671
|
||||
if (!isReleasing) {
|
||||
setBuiltinLineNumbers(editor, UserDataManager.getVimLineNumbersInitialState(editor));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean supportsVimLineNumbers(final @NotNull Editor editor) {
|
||||
@@ -101,41 +118,22 @@ public class EditorGroup implements PersistentStateComponent<Element>, VimEditor
|
||||
}
|
||||
|
||||
private static void updateLineNumbers(final @NotNull Editor editor) {
|
||||
final EffectiveOptions options = options(injector, new IjVimEditor(editor));
|
||||
final boolean relativeNumber = options.getRelativenumber();
|
||||
final boolean number = options.getNumber();
|
||||
|
||||
final boolean showBuiltinEditorLineNumbers = shouldShowBuiltinLineNumbers(editor, number, relativeNumber);
|
||||
|
||||
final EditorSettings settings = editor.getSettings();
|
||||
if (settings.isLineNumbersShown() ^ showBuiltinEditorLineNumbers) {
|
||||
// Update line numbers later since it may be called from a caret listener
|
||||
// on the caret move and it may move the caret internally
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
if (editor.isDisposed()) return;
|
||||
setBuiltinLineNumbers(editor, showBuiltinEditorLineNumbers);
|
||||
});
|
||||
final boolean isLineNumbersShown = editor.getSettings().isLineNumbersShown();
|
||||
if (!isLineNumbersShown) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (relativeNumber) {
|
||||
final LineNumerationType lineNumerationType = editor.getSettings().getLineNumerationType();
|
||||
if (lineNumerationType == LineNumerationType.RELATIVE || lineNumerationType == LineNumerationType.HYBRID) {
|
||||
if (!hasRelativeLineNumbersInstalled(editor)) {
|
||||
installRelativeLineNumbers(editor);
|
||||
}
|
||||
}
|
||||
else if (hasRelativeLineNumbersInstalled(editor)) {
|
||||
else {
|
||||
removeRelativeLineNumbers(editor);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldShowBuiltinLineNumbers(final @NotNull Editor editor, boolean number, boolean relativeNumber) {
|
||||
final boolean initialState = UserDataManager.getVimLineNumbersInitialState(editor);
|
||||
return initialState || number || relativeNumber;
|
||||
}
|
||||
|
||||
private static void setBuiltinLineNumbers(final @NotNull Editor editor, boolean show) {
|
||||
editor.getSettings().setLineNumbersShown(show);
|
||||
}
|
||||
|
||||
private static boolean hasRelativeLineNumbersInstalled(final @NotNull Editor editor) {
|
||||
return UserDataManager.getVimHasRelativeLineNumbersInstalled(editor);
|
||||
}
|
||||
@@ -204,7 +202,8 @@ public class EditorGroup implements PersistentStateComponent<Element>, VimEditor
|
||||
}
|
||||
|
||||
public void editorCreated(@NotNull Editor editor) {
|
||||
DocumentManager.INSTANCE.addListeners(editor.getDocument());
|
||||
UserDataManager.setVimInitialised(editor, true);
|
||||
|
||||
VimPlugin.getKey().registerRequiredShortcutKeys(new IjVimEditor(editor));
|
||||
|
||||
initLineNumbers(editor);
|
||||
@@ -228,7 +227,7 @@ public class EditorGroup implements PersistentStateComponent<Element>, VimEditor
|
||||
// Note that we need a similar check in `VimEditor.isWritable` to allow Escape to work to exit insert mode. We need
|
||||
// to know that a read-only editor that is hosting a console view with a running process can be treated as writable.
|
||||
Runnable switchToInsertMode = () -> {
|
||||
ExecutionContext.Editor context = injector.getExecutionContextManager().onEditor(new IjVimEditor(editor), null);
|
||||
ExecutionContext context = injector.getExecutionContextManager().getEditorExecutionContext(new IjVimEditor(editor));
|
||||
VimPlugin.getChange().insertBeforeCursor(new IjVimEditor(editor), context);
|
||||
KeyHandler.getInstance().reset(new IjVimEditor(editor));
|
||||
};
|
||||
@@ -246,14 +245,13 @@ public class EditorGroup implements PersistentStateComponent<Element>, VimEditor
|
||||
switchToInsertMode.run();
|
||||
}
|
||||
});
|
||||
updateCaretsVisualAttributes(editor);
|
||||
updateCaretsVisualAttributes(new IjVimEditor(editor));
|
||||
}
|
||||
|
||||
public void editorDeinit(@NotNull Editor editor, boolean isReleased) {
|
||||
deinitLineNumbers(editor, isReleased);
|
||||
public void editorDeinit(@NotNull Editor editor) {
|
||||
deinitLineNumbers(editor);
|
||||
UserDataManager.unInitializeEditor(editor);
|
||||
VimPlugin.getKey().unregisterShortcutKeys(new IjVimEditor(editor));
|
||||
DocumentManager.INSTANCE.removeListeners(editor.getDocument());
|
||||
CaretVisualAttributesHelperKt.removeCaretsVisualAttributes(editor);
|
||||
}
|
||||
|
||||
@@ -284,6 +282,18 @@ public class EditorGroup implements PersistentStateComponent<Element>, VimEditor
|
||||
notifyIdeaJoin(((IjVimEditor) editor).getEditor().getProject(), editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCaretsVisualAttributes(@NotNull VimEditor editor) {
|
||||
Editor ijEditor = ((IjVimEditor) editor).getEditor();
|
||||
CaretVisualAttributesHelperKt.updateCaretsVisualAttributes(ijEditor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCaretsVisualPosition(@NotNull VimEditor editor) {
|
||||
Editor ijEditor = ((IjVimEditor) editor).getEditor();
|
||||
CaretVisualAttributesHelperKt.updateCaretsVisualAttributes(ijEditor);
|
||||
}
|
||||
|
||||
public static class NumberChangeListener implements EffectiveOptionValueChangeListener {
|
||||
public static NumberChangeListener INSTANCE = new NumberChangeListener();
|
||||
|
||||
@@ -304,17 +314,18 @@ public class EditorGroup implements PersistentStateComponent<Element>, VimEditor
|
||||
private static class RelativeLineNumberConverter implements LineNumberConverter {
|
||||
@Override
|
||||
public Integer convert(@NotNull Editor editor, int lineNumber) {
|
||||
final boolean number = options(injector, new IjVimEditor(editor)).getNumber();
|
||||
final IjVimEditor ijVimEditor = new IjVimEditor(editor);
|
||||
final boolean number = ijOptions(injector, ijVimEditor).getNumber();
|
||||
final int caretLine = editor.getCaretModel().getLogicalPosition().line;
|
||||
|
||||
// lineNumber is 1 based
|
||||
if (number && (lineNumber - 1) == caretLine) {
|
||||
return lineNumber;
|
||||
if ((lineNumber - 1) == caretLine) {
|
||||
return number ? lineNumber : 0;
|
||||
}
|
||||
else {
|
||||
final int visualLine = new IjVimEditor(editor).bufferLineToVisualLine(lineNumber - 1);
|
||||
final int currentVisualLine = new IjVimEditor(editor).bufferLineToVisualLine(caretLine);
|
||||
return Math.abs(currentVisualLine - visualLine);
|
||||
final int visualLine = ijVimEditor.bufferLineToVisualLine(lineNumber - 1);
|
||||
final int caretVisualLine = editor.getCaretModel().getVisualPosition().line;
|
||||
return Math.abs(caretVisualLine - visualLine);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,20 +335,51 @@ public class EditorGroup implements PersistentStateComponent<Element>, VimEditor
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<VimEditor> localEditors() {
|
||||
return HelperKt.localEditors().stream()
|
||||
public @NotNull Collection<VimEditor> getEditorsRaw() {
|
||||
return getLocalEditors()
|
||||
.map(IjVimEditor::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<VimEditor> localEditors(@NotNull VimDocument buffer) {
|
||||
final Document document = ((IjVimDocument)buffer).getDocument();
|
||||
return HelperKt.localEditors(document).stream()
|
||||
public Collection<VimEditor> getEditors() {
|
||||
return getLocalEditors()
|
||||
.filter(UserDataManager::getVimInitialised)
|
||||
.map(IjVimEditor::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<VimEditor> getEditors(@NotNull VimDocument buffer) {
|
||||
final Document document = ((IjVimDocument)buffer).getDocument();
|
||||
return getLocalEditors()
|
||||
.filter(editor -> UserDataManager.getVimInitialised(editor) && editor.getDocument().equals(document))
|
||||
.map(IjVimEditor::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Stream<Editor> getLocalEditors() {
|
||||
// Always fetch local editors. If we're hosting a Code With Me session, any connected guests will create hidden
|
||||
// editors to handle syntax highlighting, completion requests, etc. We need to make sure that IdeaVim only makes
|
||||
// changes (e.g., adding search highlights) to local editors so things don't incorrectly flow through to any Clients.
|
||||
// In non-CWM scenarios, or if IdeaVim is installed on the Client, there are only ever local editors, so this will
|
||||
// also work there. In Gateway remote development scenarios, IdeaVim should not be installed on the host, only the
|
||||
// Client, so all should work there too.
|
||||
// Note that most IdeaVim operations are in response to interactive keystrokes, which would mean that
|
||||
// ClientEditorManager.getCurrentInstance would return local editors. However, some operations are in response to
|
||||
// events such as document change (to update search highlights), and these can come from CWM guests, and we'd get
|
||||
// the remote editors.
|
||||
// This invocation will always get local editors, regardless of the current context.
|
||||
List<ClientAppSession> appSessions = ClientSessionsManager.getAppSessions(ClientKind.ALL);
|
||||
if (!appSessions.isEmpty()) {
|
||||
ClientAppSession localSession = appSessions.get(0);
|
||||
return localSession.getService(ClientEditorManager.class).editors();
|
||||
}
|
||||
else {
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -22,16 +22,17 @@ import com.intellij.openapi.fileEditor.impl.EditorsSplitters;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.openapi.vfs.VirtualFileSystem;
|
||||
import com.intellij.psi.search.FilenameIndex;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.api.*;
|
||||
import com.maddyhome.idea.vim.state.mode.Mode;
|
||||
import com.maddyhome.idea.vim.state.VimStateMachine;
|
||||
import com.maddyhome.idea.vim.common.TextRange;
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper;
|
||||
import com.maddyhome.idea.vim.helper.EditorHelperRt;
|
||||
@@ -40,10 +41,13 @@ import com.maddyhome.idea.vim.helper.SearchHelper;
|
||||
import com.maddyhome.idea.vim.newapi.ExecuteExtensionKt;
|
||||
import com.maddyhome.idea.vim.newapi.IjEditorExecutionContext;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import com.maddyhome.idea.vim.state.VimStateMachine;
|
||||
import com.maddyhome.idea.vim.state.mode.Mode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import static com.maddyhome.idea.vim.api.VimInjectorKt.injector;
|
||||
@@ -438,14 +442,35 @@ public class FileGroup extends VimFileBase {
|
||||
private static final @NotNull Logger logger = Logger.getInstance(FileGroup.class.getName());
|
||||
|
||||
/**
|
||||
* This method listens for editor tab changes so any insert/replace modes that need to be reset can be.
|
||||
* Respond to editor tab selection and remember the last used tab
|
||||
*/
|
||||
public static void fileEditorManagerSelectionChangedCallback(@NotNull FileEditorManagerEvent event) {
|
||||
// The user has changed the editor they are working with - exit insert/replace mode, and complete any
|
||||
// appropriate repeat
|
||||
if (event.getOldFile() != null) {
|
||||
LastTabService.getInstance(event.getManager().getProject()).setLastTab(event.getOldFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public VimEditor selectEditor(@NotNull String projectId, @NotNull String documentPath, @Nullable String protocol) {
|
||||
VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(protocol);
|
||||
if (fileSystem == null) return null;
|
||||
VirtualFile virtualFile = fileSystem.findFileByPath(documentPath);
|
||||
if (virtualFile == null) return null;
|
||||
|
||||
Project project = Arrays.stream(ProjectManager.getInstance().getOpenProjects())
|
||||
.filter(p -> injector.getFile().getProjectId(p).equals(projectId))
|
||||
.findFirst().orElseThrow();
|
||||
|
||||
Editor editor = selectEditor(project, virtualFile);
|
||||
if (editor == null) return null;
|
||||
return new IjVimEditor(editor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getProjectId(@NotNull Object project) {
|
||||
if (!(project instanceof Project)) throw new IllegalArgumentException();
|
||||
return ((Project) project).getName();
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,6 @@ import com.maddyhome.idea.vim.options.OptionAccessScope
|
||||
*/
|
||||
@Suppress("SpellCheckingInspection")
|
||||
public open class GlobalIjOptions(scope: OptionAccessScope) : OptionsPropertiesBase(scope) {
|
||||
public var closenotebooks: Boolean by optionProperty(IjOptions.closenotebooks)
|
||||
public var ide: String by optionProperty(IjOptions.ide)
|
||||
public var ideamarks: Boolean by optionProperty(IjOptions.ideamarks)
|
||||
public var ideastatusicon: String by optionProperty(IjOptions.ideastatusicon)
|
||||
@@ -29,15 +28,15 @@ public open class GlobalIjOptions(scope: OptionAccessScope) : OptionsPropertiesB
|
||||
public val lookupkeys: StringListOptionValue by optionProperty(IjOptions.lookupkeys)
|
||||
public var trackactionids: Boolean by optionProperty(IjOptions.trackactionids)
|
||||
public var visualdelay: Int by optionProperty(IjOptions.visualdelay)
|
||||
public var showmodewidget: Boolean by optionProperty(IjOptions.showmodewidget)
|
||||
|
||||
// Temporary options to control work-in-progress behaviour
|
||||
public var closenotebooks: Boolean by optionProperty(IjOptions.closenotebooks)
|
||||
public var commandOrMotionAnnotation: Boolean by optionProperty(IjOptions.commandOrMotionAnnotation)
|
||||
public var exCommandAnnotation: Boolean by optionProperty(IjOptions.exCommandAnnotation)
|
||||
public var oldundo: Boolean by optionProperty(IjOptions.oldundo)
|
||||
public var unifyjumps: Boolean by optionProperty(IjOptions.unifyjumps)
|
||||
public var exCommandAnnotation: Boolean by optionProperty(IjOptions.exCommandAnnotation)
|
||||
public var vimscriptFunctionAnnotation: Boolean by optionProperty(IjOptions.vimscriptFunctionAnnotation)
|
||||
public var commandOrMotionAnnotation: Boolean by optionProperty(IjOptions.commandOrMotionAnnotation)
|
||||
public var useNewRegex: Boolean by optionProperty(IjOptions.useNewRegex)
|
||||
public var vimscriptFunctionAnnotation: Boolean by optionProperty(IjOptions.vimscriptFunctionAnnotation)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,6 +45,18 @@ public open class GlobalIjOptions(scope: OptionAccessScope) : OptionsPropertiesB
|
||||
* As a convenience, this class also provides access to the IntelliJ specific global options, via inheritance.
|
||||
*/
|
||||
public class EffectiveIjOptions(scope: OptionAccessScope.EFFECTIVE): GlobalIjOptions(scope) {
|
||||
// Vim options that are implemented purely by existing IntelliJ features and not used by vim-engine
|
||||
public var breakindent: Boolean by optionProperty(IjOptions.breakindent)
|
||||
public val colorcolumn: StringListOptionValue by optionProperty(IjOptions.colorcolumn)
|
||||
public var cursorline: Boolean by optionProperty(IjOptions.cursorline)
|
||||
public var fileformat: String by optionProperty(IjOptions.fileformat)
|
||||
public var list: Boolean by optionProperty(IjOptions.list)
|
||||
public var number: Boolean by optionProperty(IjOptions.number)
|
||||
public var relativenumber: Boolean by optionProperty(IjOptions.relativenumber)
|
||||
public var textwidth: Int by optionProperty(IjOptions.textwidth)
|
||||
public var wrap: Boolean by optionProperty(IjOptions.wrap)
|
||||
|
||||
// IntelliJ specific options
|
||||
public var ideacopypreprocess: Boolean by optionProperty(IjOptions.ideacopypreprocess)
|
||||
public var ideajoin: Boolean by optionProperty(IjOptions.ideajoin)
|
||||
public var idearefactormode: String by optionProperty(IjOptions.idearefactormode)
|
||||
|
@@ -10,9 +10,14 @@ package com.maddyhome.idea.vim.group
|
||||
|
||||
import com.intellij.openapi.application.ApplicationNamesInfo
|
||||
import com.maddyhome.idea.vim.api.Options
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.ex.exExceptionMessage
|
||||
import com.maddyhome.idea.vim.options.NumberOption
|
||||
import com.maddyhome.idea.vim.options.Option
|
||||
import com.maddyhome.idea.vim.options.OptionDeclaredScope.GLOBAL
|
||||
import com.maddyhome.idea.vim.options.OptionDeclaredScope.GLOBAL_OR_LOCAL_TO_BUFFER
|
||||
import com.maddyhome.idea.vim.options.OptionDeclaredScope.LOCAL_TO_BUFFER
|
||||
import com.maddyhome.idea.vim.options.OptionDeclaredScope.LOCAL_TO_WINDOW
|
||||
import com.maddyhome.idea.vim.options.StringListOption
|
||||
import com.maddyhome.idea.vim.options.StringOption
|
||||
import com.maddyhome.idea.vim.options.ToggleOption
|
||||
@@ -33,8 +38,56 @@ public object IjOptions {
|
||||
Options.overrideDefaultValue(Options.clipboard, VimString("ideaput,autoselect,exclude:cons\\|linux"))
|
||||
}
|
||||
|
||||
public val closenotebooks: ToggleOption = addOption(ToggleOption("closenotebooks", GLOBAL, "closenotebooks", true))
|
||||
public val exCommandAnnotation: ToggleOption = addOption(ToggleOption("excommandannotation", GLOBAL, "excommandannotation", true))
|
||||
// Vim options that are implemented purely by existing IntelliJ features and not used by vim-engine
|
||||
public val breakindent: ToggleOption = addOption(ToggleOption("breakindent", LOCAL_TO_WINDOW, "bri", false))
|
||||
public val colorcolumn: StringListOption = addOption(object : StringListOption("colorcolumn", LOCAL_TO_WINDOW, "cc", "") {
|
||||
override fun checkIfValueValid(value: VimDataType, token: String) {
|
||||
super.checkIfValueValid(value, token)
|
||||
if (value != VimString.EMPTY) {
|
||||
// Each element in the comma-separated string list needs to be a number. No spaces. Vim supports numbers
|
||||
// beginning "+" or "-" to draw a highlight column relative to the 'textwidth' value. We don't fully support
|
||||
// that, but we do automatically add "+0" because IntelliJ always displays the right margin
|
||||
split((value as VimString).asString()).forEach {
|
||||
if (!it.matches(Regex("[+-]?[0-9]+"))) {
|
||||
throw exExceptionMessage("E474", token)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
public val cursorline: ToggleOption = addOption(ToggleOption("cursorline", LOCAL_TO_WINDOW, "cul", false))
|
||||
public val list: ToggleOption = addOption(ToggleOption("list", LOCAL_TO_WINDOW, "list", false))
|
||||
public val number: ToggleOption = addOption(ToggleOption("number", LOCAL_TO_WINDOW, "nu", false))
|
||||
public val relativenumber: ToggleOption = addOption(ToggleOption("relativenumber", LOCAL_TO_WINDOW, "rnu", false))
|
||||
public val textwidth: NumberOption = addOption(UnsignedNumberOption("textwidth", LOCAL_TO_BUFFER, "tw", 0))
|
||||
public val wrap: ToggleOption = addOption(ToggleOption("wrap", LOCAL_TO_WINDOW, "wrap", true))
|
||||
|
||||
// These options are not explicitly listed as local-noglobal in Vim's help, but are set when a new buffer is edited,
|
||||
// based on the value of 'fileformats' or 'fileencodings'. To prevent unexpected file cnversion, we treat them as
|
||||
// local-noglobal. See `:help local-noglobal`, `:help 'fileformats'` and `:help 'fileencodings'`
|
||||
public val bomb: ToggleOption =
|
||||
addOption(ToggleOption("bomb", LOCAL_TO_BUFFER, "bomb", false, isLocalNoGlobal = true))
|
||||
public val fileencoding: StringOption = addOption(
|
||||
StringOption(
|
||||
"fileencoding",
|
||||
LOCAL_TO_BUFFER,
|
||||
"fenc",
|
||||
VimString.EMPTY,
|
||||
isLocalNoGlobal = true
|
||||
)
|
||||
)
|
||||
public val fileformat: StringOption = addOption(
|
||||
StringOption(
|
||||
"fileformat",
|
||||
LOCAL_TO_BUFFER,
|
||||
"ff",
|
||||
if (injector.systemInfoService.isWindows) "dos" else "unix",
|
||||
boundedValues = setOf("dos", "unix", "mac"),
|
||||
isLocalNoGlobal = true
|
||||
)
|
||||
)
|
||||
|
||||
// IntelliJ specific functionality - custom options
|
||||
public val ide: StringOption = addOption(
|
||||
StringOption("ide", GLOBAL, "ide", ApplicationNamesInfo.getInstance().fullProductNameWithEdition)
|
||||
)
|
||||
@@ -81,13 +134,16 @@ public object IjOptions {
|
||||
"<Tab>,<Down>,<Up>,<Enter>,<Left>,<Right>,<C-Down>,<C-Up>,<PageUp>,<PageDown>,<C-J>,<C-Q>")
|
||||
)
|
||||
public val trackactionids: ToggleOption = addOption(ToggleOption("trackactionids", GLOBAL, "tai", false))
|
||||
public val unifyjumps: ToggleOption = addOption(ToggleOption("unifyjumps", GLOBAL, "unifyjumps", true))
|
||||
public val visualdelay: UnsignedNumberOption = addOption(UnsignedNumberOption("visualdelay", GLOBAL, "visualdelay", 100))
|
||||
public val oldundo: ToggleOption = addOption(ToggleOption("oldundo", GLOBAL, "oldundo", true, isTemporary = true))
|
||||
public val vimscriptFunctionAnnotation: ToggleOption = addOption(ToggleOption("vimscriptfunctionannotation", GLOBAL, "vimscriptfunctionannotation", true, isTemporary = true))
|
||||
public val commandOrMotionAnnotation: ToggleOption = addOption(ToggleOption("commandormotionannotation", GLOBAL, "commandormotionannotation", true, isTemporary = true))
|
||||
public val showmodewidget: ToggleOption = addOption(ToggleOption("showmodewidget", GLOBAL, "showmodewidget", false, isTemporary = true))
|
||||
public val useNewRegex: ToggleOption = addOption(ToggleOption("usenewregex", GLOBAL, "usenewregex", true, isTemporary = true))
|
||||
|
||||
// Temporary feature flags during development, not really intended for external use
|
||||
public val closenotebooks: ToggleOption = addOption(ToggleOption("closenotebooks", GLOBAL, "closenotebooks", true, isHidden = true))
|
||||
public val commandOrMotionAnnotation: ToggleOption = addOption(ToggleOption("commandormotionannotation", GLOBAL, "commandormotionannotation", true, isHidden = true))
|
||||
public val exCommandAnnotation: ToggleOption = addOption(ToggleOption("excommandannotation", GLOBAL, "excommandannotation", true, isHidden = true))
|
||||
public val oldundo: ToggleOption = addOption(ToggleOption("oldundo", GLOBAL, "oldundo", true, isHidden = true))
|
||||
public val unifyjumps: ToggleOption = addOption(ToggleOption("unifyjumps", GLOBAL, "unifyjumps", true, isHidden = true))
|
||||
public val useNewRegex: ToggleOption = addOption(ToggleOption("usenewregex", GLOBAL, "usenewregex", true, isHidden = true))
|
||||
public val vimscriptFunctionAnnotation: ToggleOption = addOption(ToggleOption("vimscriptfunctionannotation", GLOBAL, "vimscriptfunctionannotation", true, isHidden = true))
|
||||
|
||||
// This needs to be Option<out VimDataType> so that it can work with derived option types, such as NumberOption, which
|
||||
// derives from Option<VimInt>
|
||||
|
@@ -15,38 +15,38 @@ import com.maddyhome.idea.vim.statistic.VimscriptState
|
||||
internal class IjStatisticsService : VimStatistics {
|
||||
|
||||
override fun logTrackedAction(actionId: String) {
|
||||
ActionTracker.logTrackedAction(actionId)
|
||||
ActionTracker.Util.logTrackedAction(actionId)
|
||||
}
|
||||
|
||||
override fun logCopiedAction(actionId: String) {
|
||||
ActionTracker.logCopiedAction(actionId)
|
||||
ActionTracker.Util.logCopiedAction(actionId)
|
||||
}
|
||||
|
||||
override fun setIfLoopUsed(value: Boolean) {
|
||||
VimscriptState.isLoopUsed = value
|
||||
VimscriptState.Util.isLoopUsed = value
|
||||
}
|
||||
|
||||
override fun setIfMapExprUsed(value: Boolean) {
|
||||
VimscriptState.isMapExprUsed = value
|
||||
VimscriptState.Util.isMapExprUsed = value
|
||||
}
|
||||
|
||||
override fun setIfFunctionCallUsed(value: Boolean) {
|
||||
VimscriptState.isFunctionCallUsed = value
|
||||
VimscriptState.Util.isFunctionCallUsed = value
|
||||
}
|
||||
|
||||
override fun setIfFunctionDeclarationUsed(value: Boolean) {
|
||||
VimscriptState.isFunctionDeclarationUsed = value
|
||||
VimscriptState.Util.isFunctionDeclarationUsed = value
|
||||
}
|
||||
|
||||
override fun setIfIfUsed(value: Boolean) {
|
||||
VimscriptState.isIfUsed = value
|
||||
VimscriptState.Util.isIfUsed = value
|
||||
}
|
||||
|
||||
override fun addExtensionEnabledWithPlug(extension: String) {
|
||||
VimscriptState.extensionsEnabledWithPlug.add(extension)
|
||||
VimscriptState.Util.extensionsEnabledWithPlug.add(extension)
|
||||
}
|
||||
|
||||
override fun addSourcedFile(path: String) {
|
||||
VimscriptState.sourcedFiles.add(path)
|
||||
VimscriptState.Util.sourcedFiles.add(path)
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2003-2024 The IdeaVim authors
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE.txt file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim.group
|
||||
|
||||
import com.intellij.lang.CodeDocumentationAwareCommenter
|
||||
import com.intellij.lang.LanguageCommenters
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.psi.PsiComment
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.VimPsiService
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.helper.PsiHelper
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
|
||||
@Service
|
||||
public class IjVimPsiService: VimPsiService {
|
||||
override fun getCommentAtPos(editor: VimEditor, pos: Int): Pair<TextRange, Pair<String, String>?>? {
|
||||
val psiFile = PsiHelper.getFile(editor.ij) ?: return null
|
||||
val psiElement = psiFile.findElementAt(pos) ?: return null
|
||||
val language = psiElement.language
|
||||
val commenter = LanguageCommenters.INSTANCE.forLanguage(language)
|
||||
val psiComment = PsiTreeUtil.getParentOfType(psiElement, PsiComment::class.java, false) ?: return null
|
||||
val commentText = psiComment.text
|
||||
|
||||
val blockCommentPrefix = commenter.blockCommentPrefix
|
||||
val blockCommentSuffix = commenter.blockCommentSuffix
|
||||
|
||||
val docCommentPrefix = (commenter as? CodeDocumentationAwareCommenter)?.documentationCommentPrefix
|
||||
val docCommentSuffix = (commenter as? CodeDocumentationAwareCommenter)?.documentationCommentSuffix
|
||||
|
||||
val prefixToSuffix: Pair<String, String>? =
|
||||
if (docCommentPrefix != null && docCommentSuffix != null && commentText.startsWith(docCommentPrefix) && commentText.endsWith(docCommentSuffix)) {
|
||||
docCommentPrefix to docCommentSuffix
|
||||
}
|
||||
else if (blockCommentPrefix != null && blockCommentSuffix != null && commentText.startsWith(blockCommentPrefix) && commentText.endsWith(blockCommentSuffix)) {
|
||||
blockCommentPrefix to blockCommentSuffix
|
||||
}
|
||||
else {
|
||||
null
|
||||
}
|
||||
return Pair(psiComment.textRange.vim, prefixToSuffix)
|
||||
}
|
||||
|
||||
override fun getDoubleQuotedString(editor: VimEditor, pos: Int, isInner: Boolean): TextRange? {
|
||||
// TODO[ideavim] It wasn't implemented before, but implementing it will significantly improve % motion
|
||||
return getDoubleQuotesRangeNoPSI(editor.text(), pos, isInner)
|
||||
}
|
||||
|
||||
override fun getSingleQuotedString(editor: VimEditor, pos: Int, isInner: Boolean): TextRange? {
|
||||
// TODO[ideavim] It wasn't implemented before, but implementing it will significantly improve % motion
|
||||
return getSingleQuotesRangeNoPSI(editor.text(), pos, isInner)
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2003-2024 The IdeaVim authors
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE.txt file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim.group
|
||||
|
||||
import com.intellij.openapi.editor.event.DocumentEvent
|
||||
import com.intellij.openapi.editor.event.DocumentListener
|
||||
import com.intellij.openapi.fileEditor.FileEditorManagerEvent
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.VimRedrawService
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
|
||||
public class IjVimRedrawService : VimRedrawService {
|
||||
override fun redraw() {
|
||||
// The only thing IntelliJ needs to redraw is the status line. Everything else is handled automatically.
|
||||
redrawStatusLine()
|
||||
}
|
||||
|
||||
override fun redrawStatusLine() {
|
||||
injector.messages.clearStatusBarMessage()
|
||||
}
|
||||
|
||||
public companion object {
|
||||
/**
|
||||
* Simulate Vim's redraw when the current editor changes
|
||||
*/
|
||||
public fun fileEditorManagerSelectionChangedCallback(event: FileEditorManagerEvent) {
|
||||
injector.redrawService.redraw()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulates Vim's redraw when the document changes
|
||||
*
|
||||
* Only redraw if lines are added/removed.
|
||||
*/
|
||||
public object RedrawListener : DocumentListener {
|
||||
override fun documentChanged(event: DocumentEvent) {
|
||||
if (VimPlugin.isNotEnabled()) return
|
||||
if (event.newFragment.contains("\n") || event.oldFragment.contains("\n")) {
|
||||
injector.redrawService.redraw()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -26,10 +26,12 @@ import com.maddyhome.idea.vim.EventFacade;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.action.VimShortcutKeyAction;
|
||||
import com.maddyhome.idea.vim.action.change.LazyVimCommand;
|
||||
import com.maddyhome.idea.vim.api.*;
|
||||
import com.maddyhome.idea.vim.api.NativeAction;
|
||||
import com.maddyhome.idea.vim.api.VimEditor;
|
||||
import com.maddyhome.idea.vim.api.VimInjectorKt;
|
||||
import com.maddyhome.idea.vim.api.VimKeyGroupBase;
|
||||
import com.maddyhome.idea.vim.command.MappingMode;
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel;
|
||||
import com.maddyhome.idea.vim.helper.HelperKt;
|
||||
import com.maddyhome.idea.vim.key.*;
|
||||
import com.maddyhome.idea.vim.newapi.IjNativeAction;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
@@ -99,9 +101,9 @@ public class KeyGroup extends VimKeyGroupBase implements PersistentStateComponen
|
||||
|
||||
@Override
|
||||
public void updateShortcutKeysRegistration() {
|
||||
for (Editor editor : HelperKt.localEditors()) {
|
||||
unregisterShortcutKeys(new IjVimEditor(editor));
|
||||
registerRequiredShortcutKeys(new IjVimEditor(editor));
|
||||
for (VimEditor editor : injector.getEditorGroup().getEditors()) {
|
||||
unregisterShortcutKeys(editor);
|
||||
registerRequiredShortcutKeys(editor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,7 +230,7 @@ public class KeyGroup extends VimKeyGroupBase implements PersistentStateComponen
|
||||
private void registerRequiredShortcut(@NotNull List<KeyStroke> keys, MappingOwner owner) {
|
||||
for (KeyStroke key : keys) {
|
||||
if (key.getKeyChar() == KeyEvent.CHAR_UNDEFINED) {
|
||||
if (!injector.getOptionGroup().getGlobalOptions().getOctopushandler() ||
|
||||
if (!injector.getApplication().isOctopusEnabled() ||
|
||||
!(key.getKeyCode() == KeyEvent.VK_ESCAPE && key.getModifiers() == 0) &&
|
||||
!(key.getKeyCode() == KeyEvent.VK_ENTER && key.getModifiers() == 0)) {
|
||||
getRequiredShortcutKeys().add(new RequiredShortcut(key, owner));
|
||||
|
@@ -10,6 +10,7 @@ package com.maddyhome.idea.vim.group
|
||||
import com.intellij.codeInsight.completion.CompletionPhase
|
||||
import com.intellij.codeInsight.completion.impl.CompletionServiceImpl
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
import com.intellij.openapi.progress.ProgressManager
|
||||
@@ -26,6 +27,7 @@ import com.maddyhome.idea.vim.newapi.ij
|
||||
/**
|
||||
* Used to handle playback of macros
|
||||
*/
|
||||
@Service
|
||||
internal class MacroGroup : VimMacroBase() {
|
||||
|
||||
// If it's null, this is the top macro (as in most cases). If it's not null, this macro is executed from top macro
|
||||
@@ -76,11 +78,12 @@ internal class MacroGroup : VimMacroBase() {
|
||||
} catch (e: ProcessCanceledException) {
|
||||
return@runnable
|
||||
}
|
||||
val keyHandler = getInstance()
|
||||
ProgressManager.getInstance().executeNonCancelableSection {
|
||||
// Prevent autocompletion during macros.
|
||||
// See https://github.com/JetBrains/ideavim/pull/772 for details
|
||||
CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion)
|
||||
getInstance().handleKey(editor, key, context)
|
||||
keyHandler.handleKey(editor, key, context, keyHandler.keyHandlerState)
|
||||
}
|
||||
if (injector.messages.isError()) return@runnable
|
||||
}
|
||||
|
@@ -8,43 +8,28 @@
|
||||
package com.maddyhome.idea.vim.group
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.LogicalPosition
|
||||
import com.intellij.openapi.editor.VisualPosition
|
||||
import com.intellij.openapi.fileEditor.FileEditorManagerEvent
|
||||
import com.intellij.openapi.fileEditor.TextEditor
|
||||
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
|
||||
import com.intellij.openapi.fileEditor.impl.EditorWindow
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.VirtualFileManager
|
||||
import com.intellij.openapi.vfs.VirtualFileSystem
|
||||
import com.intellij.util.MathUtil.clamp
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.BufferPosition
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.ImmutableVimCaret
|
||||
import com.maddyhome.idea.vim.api.VimCaret
|
||||
import com.maddyhome.idea.vim.api.VimChangeGroupBase
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.VimMotionGroupBase
|
||||
import com.maddyhome.idea.vim.api.addJump
|
||||
import com.maddyhome.idea.vim.api.anyNonWhitespace
|
||||
import com.maddyhome.idea.vim.api.getJump
|
||||
import com.maddyhome.idea.vim.api.getJumpSpot
|
||||
import com.maddyhome.idea.vim.api.getLeadingCharacterOffset
|
||||
import com.maddyhome.idea.vim.api.getVisualLineCount
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.api.lineLength
|
||||
import com.maddyhome.idea.vim.api.normalizeColumn
|
||||
import com.maddyhome.idea.vim.api.normalizeLine
|
||||
import com.maddyhome.idea.vim.api.normalizeOffset
|
||||
import com.maddyhome.idea.vim.api.normalizeVisualColumn
|
||||
import com.maddyhome.idea.vim.api.normalizeVisualLine
|
||||
import com.maddyhome.idea.vim.api.options
|
||||
import com.maddyhome.idea.vim.api.visualLineToBufferLine
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.MotionType
|
||||
@@ -53,59 +38,34 @@ import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel
|
||||
import com.maddyhome.idea.vim.handler.Motion
|
||||
import com.maddyhome.idea.vim.handler.Motion.AbsoluteOffset
|
||||
import com.maddyhome.idea.vim.handler.Motion.AdjustedOffset
|
||||
import com.maddyhome.idea.vim.handler.MotionActionHandler
|
||||
import com.maddyhome.idea.vim.handler.TextObjectActionHandler
|
||||
import com.maddyhome.idea.vim.handler.toMotionOrError
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.SearchHelper
|
||||
import com.maddyhome.idea.vim.helper.exitVisualMode
|
||||
import com.maddyhome.idea.vim.helper.fileSize
|
||||
import com.maddyhome.idea.vim.helper.getNormalizedScrollOffset
|
||||
import com.maddyhome.idea.vim.helper.getNormalizedSideScrollOffset
|
||||
import com.maddyhome.idea.vim.helper.isEndAllowed
|
||||
import com.maddyhome.idea.vim.helper.vimLastColumn
|
||||
import com.maddyhome.idea.vim.helper.vimStateMachine
|
||||
import com.maddyhome.idea.vim.listener.AppCodeTemplates
|
||||
import com.maddyhome.idea.vim.mark.Mark
|
||||
import com.maddyhome.idea.vim.newapi.IjEditorExecutionContext
|
||||
import com.maddyhome.idea.vim.newapi.IjVimCaret
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.state.VimStateMachine
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel
|
||||
import org.jetbrains.annotations.Range
|
||||
import java.io.File
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
* This handles all motion related commands and marks
|
||||
*/
|
||||
@Service
|
||||
internal class MotionGroup : VimMotionGroupBase() {
|
||||
override fun onAppCodeMovement(editor: VimEditor, caret: VimCaret, offset: Int, oldOffset: Int) {
|
||||
AppCodeTemplates.onMovement(editor.ij, caret.ij, oldOffset < offset)
|
||||
}
|
||||
|
||||
private fun selectEditor(project: Project, mark: Mark): Editor? {
|
||||
val virtualFile = markToVirtualFile(mark) ?: return null
|
||||
return selectEditor(project, virtualFile)
|
||||
}
|
||||
|
||||
private fun markToVirtualFile(mark: Mark): VirtualFile? {
|
||||
val protocol = mark.protocol
|
||||
val fileSystem: VirtualFileSystem? = VirtualFileManager.getInstance().getFileSystem(protocol)
|
||||
return fileSystem?.findFileByPath(mark.filepath)
|
||||
}
|
||||
|
||||
private fun selectEditor(project: Project?, file: VirtualFile) =
|
||||
VimPlugin.getFile().selectEditor(project, file)
|
||||
|
||||
override fun moveCaretToMatchingPair(editor: VimEditor, caret: ImmutableVimCaret): Motion {
|
||||
return SearchHelper.findMatchingPairOnCurrentLine(editor.ij, caret.ij).toMotionOrError()
|
||||
}
|
||||
|
||||
override fun moveCaretToFirstDisplayLine(
|
||||
editor: VimEditor,
|
||||
caret: ImmutableVimCaret,
|
||||
@@ -128,85 +88,12 @@ internal class MotionGroup : VimMotionGroupBase() {
|
||||
return moveCaretToScreenLocation(editor.ij, caret.ij, ScreenLocation.MIDDLE, 0, false)
|
||||
}
|
||||
|
||||
override fun moveCaretToMark(caret: ImmutableVimCaret, ch: Char, toLineStart: Boolean): Motion {
|
||||
val markService = injector.markService
|
||||
val mark = markService.getMark(caret, ch) ?: return Motion.Error
|
||||
|
||||
val caretEditor = caret.editor
|
||||
val caretVirtualFile = EditorHelper.getVirtualFile((caretEditor as IjVimEditor).editor)
|
||||
|
||||
val line = mark.line
|
||||
|
||||
if (caretVirtualFile!!.path == mark.filepath) {
|
||||
val offset = if (toLineStart) {
|
||||
moveCaretToLineStartSkipLeading(caretEditor, line)
|
||||
} else {
|
||||
caretEditor.bufferPositionToOffset(BufferPosition(line, mark.col, false))
|
||||
}
|
||||
return offset.toMotionOrError()
|
||||
}
|
||||
|
||||
val project = caretEditor.editor.project
|
||||
val markEditor = selectEditor(project!!, mark)
|
||||
if (markEditor != null) {
|
||||
// todo should we move all the carets or only one?
|
||||
for (carett in markEditor.caretModel.allCarets) {
|
||||
val offset = if (toLineStart) {
|
||||
moveCaretToLineStartSkipLeading(IjVimEditor(markEditor), line)
|
||||
} else {
|
||||
// todo should it be the same as getting offset above?
|
||||
markEditor.logicalPositionToOffset(LogicalPosition(line, mark.col))
|
||||
}
|
||||
IjVimCaret(carett!!).moveToOffset(offset)
|
||||
}
|
||||
}
|
||||
return Motion.Error
|
||||
}
|
||||
|
||||
override fun moveCaretToJump(editor: VimEditor, caret: ImmutableVimCaret, count: Int): Motion {
|
||||
val jumpService = injector.jumpService
|
||||
val spot = jumpService.getJumpSpot(editor)
|
||||
val (line, col, fileName) = jumpService.getJump(editor, count) ?: return Motion.Error
|
||||
val vf = EditorHelper.getVirtualFile(editor.ij) ?: return Motion.Error
|
||||
val lp = BufferPosition(line, col, false)
|
||||
val lpNative = LogicalPosition(line, col, false)
|
||||
return if (vf.path != fileName) {
|
||||
val newFile = LocalFileSystem.getInstance().findFileByPath(fileName.replace(File.separatorChar, '/'))
|
||||
?: return Motion.Error
|
||||
selectEditor(editor.ij.project, newFile)?.let { newEditor ->
|
||||
if (spot == -1) {
|
||||
jumpService.addJump(editor, false)
|
||||
}
|
||||
newEditor.vim.let {
|
||||
it.currentCaret().moveToOffset(it.normalizeOffset(newEditor.logicalPositionToOffset(lpNative), false))
|
||||
}
|
||||
}
|
||||
Motion.Error
|
||||
} else {
|
||||
if (spot == -1) {
|
||||
jumpService.addJump(editor, false)
|
||||
}
|
||||
editor.bufferPositionToOffset(lp).toMotionOrError()
|
||||
}
|
||||
}
|
||||
|
||||
override fun moveCaretToCurrentDisplayLineMiddle(editor: VimEditor, caret: ImmutableVimCaret): Motion {
|
||||
val width = EditorHelper.getApproximateScreenWidth(editor.ij) / 2
|
||||
val len = editor.lineLength(editor.currentCaret().getBufferPosition().line)
|
||||
return moveCaretToColumn(editor, caret, max(0, min(len - 1, width)), false)
|
||||
}
|
||||
|
||||
override fun moveCaretToColumn(editor: VimEditor, caret: ImmutableVimCaret, count: Int, allowEnd: Boolean): Motion {
|
||||
val line = caret.getLine().line
|
||||
val column = editor.normalizeColumn(line, count, allowEnd)
|
||||
val offset = editor.bufferPositionToOffset(BufferPosition(line, column, false))
|
||||
return if (column != count) {
|
||||
AdjustedOffset(offset, count)
|
||||
} else {
|
||||
AbsoluteOffset(offset)
|
||||
}
|
||||
}
|
||||
|
||||
override fun moveCaretToCurrentDisplayLineStart(editor: VimEditor, caret: ImmutableVimCaret): Motion {
|
||||
val col = EditorHelper.getVisualColumnAtLeftOfDisplay(editor.ij, caret.getVisualPosition().line)
|
||||
return moveCaretToColumn(editor, caret, col, false)
|
||||
@@ -217,7 +104,7 @@ internal class MotionGroup : VimMotionGroupBase() {
|
||||
caret: ImmutableVimCaret,
|
||||
): @Range(from = 0, to = Int.MAX_VALUE.toLong()) Int {
|
||||
val col = EditorHelper.getVisualColumnAtLeftOfDisplay(editor.ij, caret.getVisualPosition().line)
|
||||
val bufferLine = caret.getLine().line
|
||||
val bufferLine = caret.getLine()
|
||||
return editor.getLeadingCharacterOffset(bufferLine, col)
|
||||
}
|
||||
|
||||
@@ -230,36 +117,6 @@ internal class MotionGroup : VimMotionGroupBase() {
|
||||
return moveCaretToColumn(editor, caret, col, allowEnd)
|
||||
}
|
||||
|
||||
override fun moveCaretToLineWithSameColumn(
|
||||
editor: VimEditor,
|
||||
line: Int,
|
||||
caret: ImmutableVimCaret,
|
||||
): @Range(from = 0, to = Int.MAX_VALUE.toLong()) Int {
|
||||
var c = caret.vimLastColumn
|
||||
var l = line
|
||||
if (l < 0) {
|
||||
l = 0
|
||||
c = 0
|
||||
} else if (l >= editor.lineCount()) {
|
||||
l = editor.normalizeLine(editor.lineCount() - 1)
|
||||
c = editor.lineLength(l)
|
||||
}
|
||||
val newPos = BufferPosition(l, editor.normalizeColumn(l, c, false))
|
||||
return editor.bufferPositionToOffset(newPos)
|
||||
}
|
||||
|
||||
override fun moveCaretToLineWithStartOfLineOption(
|
||||
editor: VimEditor,
|
||||
line: Int,
|
||||
caret: ImmutableVimCaret,
|
||||
): @Range(from = 0, to = Int.MAX_VALUE.toLong()) Int {
|
||||
return if (injector.options(editor).startofline) {
|
||||
moveCaretToLineStartSkipLeading(editor, line)
|
||||
} else {
|
||||
moveCaretToLineWithSameColumn(editor, line, caret)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If 'absolute' is true, then set tab index to 'value', otherwise add 'value' to tab index with wraparound.
|
||||
*/
|
||||
@@ -277,30 +134,18 @@ internal class MotionGroup : VimMotionGroupBase() {
|
||||
}
|
||||
|
||||
override fun moveCaretGotoPreviousTab(editor: VimEditor, context: ExecutionContext, rawCount: Int): Int {
|
||||
val project = editor.ij.project ?: return editor.currentCaret().offset.point
|
||||
val project = editor.ij.project ?: return editor.currentCaret().offset
|
||||
val currentWindow = FileEditorManagerEx.getInstanceEx(project).splitters.currentWindow
|
||||
switchEditorTab(currentWindow, if (rawCount >= 1) -rawCount else -1, false)
|
||||
return editor.currentCaret().offset.point
|
||||
return editor.currentCaret().offset
|
||||
}
|
||||
|
||||
override fun moveCaretGotoNextTab(editor: VimEditor, context: ExecutionContext, rawCount: Int): Int {
|
||||
val absolute = rawCount >= 1
|
||||
val project = editor.ij.project ?: return editor.currentCaret().offset.point
|
||||
val project = editor.ij.project ?: return editor.currentCaret().offset
|
||||
val currentWindow = FileEditorManagerEx.getInstanceEx(project).splitters.currentWindow
|
||||
switchEditorTab(currentWindow, if (absolute) rawCount - 1 else 1, absolute)
|
||||
return editor.currentCaret().offset.point
|
||||
}
|
||||
|
||||
override fun moveCaretToLinePercent(
|
||||
editor: VimEditor,
|
||||
caret: ImmutableVimCaret,
|
||||
count: Int,
|
||||
): @Range(from = 0, to = Int.MAX_VALUE.toLong()) Int {
|
||||
return moveCaretToLineWithStartOfLineOption(
|
||||
editor,
|
||||
editor.normalizeLine((editor.lineCount() * clamp(count, 0, 100) + 99) / 100 - 1),
|
||||
caret,
|
||||
)
|
||||
return editor.currentCaret().offset
|
||||
}
|
||||
|
||||
private enum class ScreenLocation {
|
||||
@@ -457,16 +302,21 @@ internal class MotionGroup : VimMotionGroupBase() {
|
||||
}
|
||||
|
||||
fun fileEditorManagerSelectionChangedCallback(event: FileEditorManagerEvent) {
|
||||
ExEntryPanel.deactivateAll()
|
||||
val fileEditor = event.oldEditor
|
||||
if (fileEditor is TextEditor) {
|
||||
val editor = fileEditor.editor
|
||||
if (!editor.isDisposed) {
|
||||
ExOutputModel.getInstance(editor).clear()
|
||||
editor.vim.let { vimEditor ->
|
||||
if (VimStateMachine.getInstance(vimEditor).mode is Mode.VISUAL) {
|
||||
vimEditor.exitVisualMode()
|
||||
KeyHandler.getInstance().reset(vimEditor)
|
||||
when (vimEditor.vimStateMachine.mode) {
|
||||
is Mode.VISUAL -> {
|
||||
vimEditor.exitVisualMode()
|
||||
KeyHandler.getInstance().reset(vimEditor)
|
||||
}
|
||||
is Mode.CMD_LINE -> {
|
||||
injector.processGroup.cancelExEntry(vimEditor, false)
|
||||
ExOutputModel.getInstance(editor).clear()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ import com.intellij.openapi.actionSystem.ActionUpdateThread
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.actionSystem.KeyboardShortcut
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.ide.CopyPasteManager
|
||||
import com.intellij.openapi.keymap.KeymapUtil
|
||||
@@ -55,6 +56,7 @@ import javax.swing.KeyStroke
|
||||
* This service is can be used as application level and as project level service.
|
||||
* If project is null, this means that this is an application level service and notification will be shown for all projects
|
||||
*/
|
||||
@Service(Service.Level.PROJECT, Service.Level.APP)
|
||||
internal class NotificationService(private val project: Project?) {
|
||||
// This constructor is used to create an applicationService
|
||||
@Suppress("unused")
|
||||
@@ -276,7 +278,7 @@ internal class NotificationService(private val project: Project?) {
|
||||
}
|
||||
|
||||
if (id != null) {
|
||||
ActionTracker.logTrackedAction(id)
|
||||
ActionTracker.Util.logTrackedAction(id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,7 +286,7 @@ internal class NotificationService(private val project: Project?) {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
CopyPasteManager.getInstance().setContents(StringSelection(id ?: ""))
|
||||
if (id != null) {
|
||||
ActionTracker.logCopiedAction(id)
|
||||
ActionTracker.Util.logCopiedAction(id)
|
||||
}
|
||||
notification?.expire()
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,6 @@ import com.intellij.execution.configurations.GeneralCommandLine
|
||||
import com.intellij.execution.process.CapturingProcessHandler
|
||||
import com.intellij.execution.process.ProcessAdapter
|
||||
import com.intellij.execution.process.ProcessEvent
|
||||
import com.intellij.openapi.diagnostic.debug
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
import com.intellij.openapi.progress.ProgressIndicatorProvider
|
||||
@@ -20,6 +19,7 @@ import com.intellij.openapi.progress.ProgressManager
|
||||
import com.intellij.util.execution.ParametersListUtil
|
||||
import com.intellij.util.text.CharSequenceReader
|
||||
import com.maddyhome.idea.vim.KeyHandler.Companion.getInstance
|
||||
import com.maddyhome.idea.vim.KeyProcessResult
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
@@ -27,26 +27,20 @@ import com.maddyhome.idea.vim.api.VimProcessGroupBase
|
||||
import com.maddyhome.idea.vim.api.globalOptions
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.ex.ExException
|
||||
import com.maddyhome.idea.vim.ex.InvalidCommandException
|
||||
import com.maddyhome.idea.vim.helper.requestFocus
|
||||
import com.maddyhome.idea.vim.helper.vimStateMachine
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.state.VimStateMachine.Companion.getInstance
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
import com.maddyhome.idea.vim.state.mode.Mode.NORMAL
|
||||
import com.maddyhome.idea.vim.state.mode.Mode.VISUAL
|
||||
import com.maddyhome.idea.vim.state.mode.ReturnableFromCmd
|
||||
import com.maddyhome.idea.vim.state.mode.mode
|
||||
import com.maddyhome.idea.vim.state.mode.inVisualMode
|
||||
import com.maddyhome.idea.vim.state.mode.returnTo
|
||||
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel
|
||||
import com.maddyhome.idea.vim.vimscript.model.CommandLineVimLContext
|
||||
import java.io.BufferedWriter
|
||||
import java.io.IOException
|
||||
import java.io.OutputStreamWriter
|
||||
import java.io.Reader
|
||||
import java.io.Writer
|
||||
import javax.swing.KeyStroke
|
||||
import javax.swing.SwingUtilities
|
||||
|
||||
public class ProcessGroup : VimProcessGroupBase() {
|
||||
override var lastCommand: String? = null
|
||||
@@ -54,25 +48,13 @@ public class ProcessGroup : VimProcessGroupBase() {
|
||||
override var isCommandProcessing: Boolean = false
|
||||
override var modeBeforeCommandProcessing: Mode? = null
|
||||
|
||||
public override fun startSearchCommand(editor: VimEditor, context: ExecutionContext, count: Int, leader: Char) {
|
||||
// Don't allow searching in one line editors
|
||||
if (editor.isOneLineMode()) return
|
||||
|
||||
val initText = ""
|
||||
val label = leader.toString()
|
||||
|
||||
val panel = ExEntryPanel.getInstance()
|
||||
panel.activate(editor.ij, context.ij, label, initText, count)
|
||||
}
|
||||
|
||||
public override fun endSearchCommand(): String {
|
||||
val panel = ExEntryPanel.getInstance()
|
||||
panel.deactivate(true)
|
||||
|
||||
return panel.text
|
||||
}
|
||||
|
||||
public override fun startExCommand(editor: VimEditor, context: ExecutionContext, cmd: Command) {
|
||||
public override fun startExEntry(
|
||||
editor: VimEditor,
|
||||
context: ExecutionContext,
|
||||
command: Command,
|
||||
label: String,
|
||||
initialCommandText: String,
|
||||
) {
|
||||
// Don't allow ex commands in one line editors
|
||||
if (editor.isOneLineMode()) return
|
||||
|
||||
@@ -83,103 +65,60 @@ public class ProcessGroup : VimProcessGroupBase() {
|
||||
|
||||
isCommandProcessing = true
|
||||
modeBeforeCommandProcessing = currentMode
|
||||
val initText = getRange(editor, cmd)
|
||||
|
||||
// Make sure the Visual selection marks are up to date before we use them.
|
||||
injector.markService.setVisualSelectionMarks(editor)
|
||||
editor.vimStateMachine.mode = Mode.CMD_LINE(currentMode)
|
||||
val panel = ExEntryPanel.getInstance()
|
||||
panel.activate(editor.ij, context.ij, ":", initText, 1)
|
||||
|
||||
val rangeText = getRange(editor, command)
|
||||
|
||||
// Note that we should remove selection and reset caret offset before we switch back to Normal mode and then enter
|
||||
// Command-line mode. However, some IdeaVim commands can handle multiple carets, including multiple carets with
|
||||
// selection (which might or might not be a block selection). Unfortunately, because we're just entering
|
||||
// Command-line mode, we don't know which command is going to be entered, so we can't remove selection here.
|
||||
// Therefore, we switch to Normal and then Command-line even though we might still have a Visual selection...
|
||||
// On the plus side, it means we still show selection while editing the command line, which Vim also does
|
||||
// (Normal then Command-line is not strictly necessary, but done for completeness and autocmd)
|
||||
// Caret selection is finally handled in Command.execute
|
||||
editor.mode = Mode.NORMAL()
|
||||
editor.mode = Mode.CMD_LINE(currentMode)
|
||||
|
||||
injector.commandLine.create(editor, context, ":", rangeText + initialCommandText, 1)
|
||||
}
|
||||
|
||||
public override fun processExKey(editor: VimEditor, stroke: KeyStroke): Boolean {
|
||||
public override fun processExKey(editor: VimEditor, stroke: KeyStroke, processResultBuilder: KeyProcessResult.KeyProcessResultBuilder): Boolean {
|
||||
// This will only get called if somehow the key focus ended up in the editor while the ex entry window
|
||||
// is open. So I'll put focus back in the editor and process the key.
|
||||
|
||||
val panel = ExEntryPanel.getInstance()
|
||||
if (panel.isActive) {
|
||||
requestFocus(panel.entry)
|
||||
panel.handleKey(stroke)
|
||||
|
||||
processResultBuilder.addExecutionStep { _, _, _ ->
|
||||
requestFocus(panel.entry)
|
||||
panel.handleKey(stroke)
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
getInstance(editor).mode = NORMAL()
|
||||
getInstance().reset(editor)
|
||||
processResultBuilder.addExecutionStep { _, lambdaEditor, _ ->
|
||||
lambdaEditor.mode = Mode.NORMAL()
|
||||
getInstance().reset(lambdaEditor)
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
public override fun processExEntry(editor: VimEditor, context: ExecutionContext): Boolean {
|
||||
val panel = ExEntryPanel.getInstance()
|
||||
panel.deactivate(true)
|
||||
var res = true
|
||||
try {
|
||||
getInstance(editor).mode = NORMAL()
|
||||
|
||||
logger.debug("processing command")
|
||||
|
||||
val text = panel.text
|
||||
|
||||
if (panel.label != ":") {
|
||||
// Search is handled via Argument.Type.EX_STRING. Although ProcessExEntryAction is registered as the handler for
|
||||
// <CR> in both command and search modes, it's only invoked for command mode (see KeyHandler.handleCommandNode).
|
||||
// We should never be invoked for anything other than an actual ex command.
|
||||
throw InvalidCommandException("Expected ':' command. Got '" + panel.label + "'", text)
|
||||
}
|
||||
|
||||
logger.debug {
|
||||
"swing=" + SwingUtilities.isEventDispatchThread()
|
||||
}
|
||||
|
||||
injector.vimscriptExecutor.execute(text, editor, context, skipHistory(editor), true, CommandLineVimLContext)
|
||||
} catch (e: ExException) {
|
||||
VimPlugin.showMessage(e.message)
|
||||
VimPlugin.indicateError()
|
||||
res = false
|
||||
} catch (bad: Exception) {
|
||||
logger.error(bad)
|
||||
VimPlugin.indicateError()
|
||||
res = false
|
||||
} finally {
|
||||
isCommandProcessing = false
|
||||
modeBeforeCommandProcessing = null
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// commands executed from map command / macro should not be added to history
|
||||
private fun skipHistory(editor: VimEditor): Boolean {
|
||||
return getInstance(editor).mappingState.isExecutingMap() || injector.macro.isExecutingMacro
|
||||
}
|
||||
|
||||
public override fun cancelExEntry(editor: VimEditor, resetCaret: Boolean) {
|
||||
editor.vimStateMachine.mode = NORMAL()
|
||||
// If 'cpoptions' contains 'x', then Escape should execute the command line. This is the default for Vi but not Vim.
|
||||
// IdeaVim does not (currently?) support 'cpoptions', so sticks with Vim's default behaviour. Escape cancels.
|
||||
editor.mode = editor.mode.returnTo()
|
||||
getInstance().reset(editor)
|
||||
val panel = ExEntryPanel.getInstance()
|
||||
panel.deactivate(true, resetCaret)
|
||||
}
|
||||
|
||||
public override fun startFilterCommand(editor: VimEditor, context: ExecutionContext, cmd: Command) {
|
||||
val initText = getRange(editor, cmd) + "!"
|
||||
val currentMode = editor.mode
|
||||
check(currentMode is ReturnableFromCmd) { "Cannot enable cmd mode from $currentMode" }
|
||||
editor.vimStateMachine.mode = Mode.CMD_LINE(currentMode)
|
||||
val panel = ExEntryPanel.getInstance()
|
||||
panel.activate(editor.ij, context.ij, ":", initText, 1)
|
||||
}
|
||||
|
||||
private fun getRange(editor: VimEditor, cmd: Command): String {
|
||||
var initText = ""
|
||||
if (editor.vimStateMachine.mode is VISUAL) {
|
||||
initText = "'<,'>"
|
||||
} else if (cmd.rawCount > 0) {
|
||||
initText = if (cmd.count == 1) {
|
||||
"."
|
||||
} else {
|
||||
".,.+" + (cmd.count - 1)
|
||||
}
|
||||
}
|
||||
|
||||
return initText
|
||||
private fun getRange(editor: VimEditor, cmd: Command) = when {
|
||||
editor.inVisualMode -> "'<,'>"
|
||||
cmd.rawCount == 1 -> "."
|
||||
cmd.rawCount > 1 -> ".,.+" + (cmd.count - 1)
|
||||
else -> ""
|
||||
}
|
||||
|
||||
@Throws(ExecutionException::class, ProcessCanceledException::class)
|
||||
|
@@ -14,9 +14,9 @@ import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType;
|
||||
import com.maddyhome.idea.vim.register.Register;
|
||||
import com.maddyhome.idea.vim.register.VimRegisterGroupBase;
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -37,6 +37,10 @@ public class RegisterGroup extends VimRegisterGroupBase implements PersistentSta
|
||||
|
||||
private static final Logger logger = Logger.getInstance(RegisterGroup.class);
|
||||
|
||||
public RegisterGroup() {
|
||||
this.initClipboardOptionListener();
|
||||
}
|
||||
|
||||
public void saveData(final @NotNull Element element) {
|
||||
logger.debug("Save registers data");
|
||||
final Element registersElement = new Element("registers");
|
||||
|
@@ -24,7 +24,6 @@ import com.maddyhome.idea.vim.helper.ScrollViewHelper
|
||||
import com.maddyhome.idea.vim.helper.StrictMode
|
||||
import com.maddyhome.idea.vim.helper.getNormalizedScrollOffset
|
||||
import com.maddyhome.idea.vim.helper.getNormalizedSideScrollOffset
|
||||
import com.maddyhome.idea.vim.helper.vimEditorGroup
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.options.EffectiveOptionValueChangeListener
|
||||
@@ -258,11 +257,7 @@ internal class ScrollGroup : VimScrollGroup {
|
||||
|
||||
object ScrollOptionsChangeListener : EffectiveOptionValueChangeListener {
|
||||
override fun onEffectiveValueChanged(editor: VimEditor) {
|
||||
editor.ij.apply {
|
||||
if (vimEditorGroup) {
|
||||
ScrollViewHelper.scrollCaretIntoView(this)
|
||||
}
|
||||
}
|
||||
editor.ij.apply { ScrollViewHelper.scrollCaretIntoView(this) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -21,11 +21,10 @@ import com.intellij.openapi.editor.event.DocumentEvent;
|
||||
import com.intellij.openapi.editor.event.DocumentListener;
|
||||
import com.intellij.openapi.editor.markup.RangeHighlighter;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.api.*;
|
||||
import com.maddyhome.idea.vim.command.MotionType;
|
||||
import com.maddyhome.idea.vim.common.CharacterPosition;
|
||||
import com.maddyhome.idea.vim.common.Direction;
|
||||
import com.maddyhome.idea.vim.common.TextRange;
|
||||
@@ -33,12 +32,11 @@ import com.maddyhome.idea.vim.ex.ExException;
|
||||
import com.maddyhome.idea.vim.ex.ranges.LineRange;
|
||||
import com.maddyhome.idea.vim.helper.*;
|
||||
import com.maddyhome.idea.vim.history.HistoryConstants;
|
||||
import com.maddyhome.idea.vim.newapi.IjEditorExecutionContext;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimCaret;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimSearchGroup;
|
||||
import com.maddyhome.idea.vim.newapi.*;
|
||||
import com.maddyhome.idea.vim.options.GlobalOptionChangeListener;
|
||||
import com.maddyhome.idea.vim.regexp.*;
|
||||
import com.maddyhome.idea.vim.regexp.CharPointer;
|
||||
import com.maddyhome.idea.vim.regexp.CharacterClasses;
|
||||
import com.maddyhome.idea.vim.regexp.RegExp;
|
||||
import com.maddyhome.idea.vim.ui.ModalEntry;
|
||||
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel;
|
||||
import com.maddyhome.idea.vim.vimscript.model.VimLContext;
|
||||
@@ -59,28 +57,23 @@ import java.text.ParsePosition;
|
||||
import java.util.*;
|
||||
|
||||
import static com.maddyhome.idea.vim.api.VimInjectorKt.*;
|
||||
import static com.maddyhome.idea.vim.helper.HelperKt.localEditors;
|
||||
import static com.maddyhome.idea.vim.helper.SearchHelperKtKt.shouldIgnoreCase;
|
||||
import static com.maddyhome.idea.vim.newapi.IjVimInjectorKt.globalIjOptions;
|
||||
import static com.maddyhome.idea.vim.register.RegisterConstants.LAST_SEARCH_REGISTER;
|
||||
|
||||
/**
|
||||
* @deprecated Replace with IjVimSearchGroup
|
||||
*/
|
||||
@State(name = "VimSearchSettings", storages = {
|
||||
@Storage(value = "$APP_CONFIG$/vim_settings_local.xml", roamingType = RoamingType.DISABLED)
|
||||
})
|
||||
@Deprecated
|
||||
/**
|
||||
* @deprecated Replace with IjVimSearchGroup
|
||||
*/
|
||||
public class SearchGroup extends IjVimSearchGroup implements PersistentStateComponent<Element> {
|
||||
public SearchGroup() {
|
||||
super();
|
||||
if (!globalIjOptions(injector).getUseNewRegex()) {
|
||||
// TODO: Investigate migrating these listeners to use the effective value change listener
|
||||
// This would allow us to update the editor we're told to update, rather than looping over all projects and updating
|
||||
// the highlights in that project's current document's open editors (see VIM-2779).
|
||||
// However, we probably only want to update the editors associated with the current document, so maybe the whole
|
||||
// code needs to be reworked. We're currently using the same update code for changes in the search term as well as
|
||||
// changes in the search options.
|
||||
// We use the global option listener instead of the effective listener that gets called for each affected editor
|
||||
// because we handle updating the affected editors ourselves (e.g., we can filter for visible windows).
|
||||
VimPlugin.getOptionGroup().addGlobalOptionChangeListener(Options.hlsearch, () -> {
|
||||
resetShowSearchHighlight();
|
||||
forceUpdateSearchHighlights();
|
||||
@@ -154,11 +147,11 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
@Override
|
||||
protected @Nullable String getLastUsedPattern() {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) return super.getLastUsedPattern();
|
||||
switch (lastPatternIdx) {
|
||||
case RE_SEARCH: return lastSearch;
|
||||
case RE_SUBST: return lastSubstitute;
|
||||
}
|
||||
return null;
|
||||
return switch (lastPatternIdx) {
|
||||
case RE_SEARCH -> lastSearch;
|
||||
case RE_SUBST -> lastSubstitute;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,11 +269,18 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
* Can include a trailing offset, e.g. /{pattern}/{offset}, or multiple commands separated by a semicolon.
|
||||
* If the pattern is empty, the last used (search? substitute?) pattern (and offset?) is used.
|
||||
* @param dir The direction to search
|
||||
* @return Offset to the next occurrence of the pattern or -1 if not found
|
||||
* @return Pair containing the offset to the next occurrence of the pattern, and the [MotionType] based on
|
||||
* the search offset. The value will be `null` if no result is found.
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public int processSearchCommand(@NotNull VimEditor editor, @NotNull String command, int startOffset, @NotNull Direction dir) {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) return super.processSearchCommand(editor, command, startOffset, dir);
|
||||
public Pair<Integer, MotionType> processSearchCommand(@NotNull VimEditor editor,
|
||||
@NotNull String command,
|
||||
int startOffset,
|
||||
int count1,
|
||||
@NotNull Direction dir) {
|
||||
|
||||
if (globalIjOptions(injector).getUseNewRegex()) return super.processSearchCommand(editor, command, startOffset, count1, dir);
|
||||
|
||||
boolean isNewPattern = false;
|
||||
String pattern = null;
|
||||
@@ -288,7 +288,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
|
||||
final char type = dir == Direction.FORWARDS ? '/' : '?';
|
||||
|
||||
if (command.length() > 0) {
|
||||
if (!command.isEmpty()) {
|
||||
if (command.charAt(0) != type) {
|
||||
CharPointer p = new CharPointer(command);
|
||||
CharPointer end = RegExp.skip_regexp(p.ref(0), type, true);
|
||||
@@ -340,17 +340,19 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
// Direction is saved in do_search
|
||||
// IgnoreSmartCase is only ever set for searching words (`*`, `#`, `g*`, etc.) and is reset for all other operations
|
||||
|
||||
if (pattern == null || pattern.length() == 0) {
|
||||
if (pattern == null || pattern.isEmpty()) {
|
||||
pattern = getLastSearchPattern();
|
||||
patternOffset = lastPatternOffset;
|
||||
if (pattern == null || pattern.length() == 0) {
|
||||
if (pattern == null || pattern.isEmpty()) {
|
||||
isNewPattern = true;
|
||||
pattern = getLastSubstitutePattern();
|
||||
if (pattern == null || pattern.length() == 0) {
|
||||
if (pattern == null || pattern.isEmpty()) {
|
||||
VimPlugin.showMessage(MessageHelper.message("e_noprevre"));
|
||||
return -1;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (patternOffset == null || patternOffset.isEmpty()) {
|
||||
patternOffset = lastPatternOffset;
|
||||
}
|
||||
}
|
||||
|
||||
// Save the pattern. If it's explicitly entered, or comes from RE_SUBST, isNewPattern is true, and this becomes
|
||||
@@ -369,7 +371,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
resetShowSearchHighlight();
|
||||
forceUpdateSearchHighlights();
|
||||
|
||||
return findItOffset(((IjVimEditor)editor).getEditor(), startOffset, 1, lastDir);
|
||||
return findItOffset(((IjVimEditor)editor).getEditor(), startOffset, count1, lastDir);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -411,7 +413,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
resetShowSearchHighlight();
|
||||
forceUpdateSearchHighlights();
|
||||
|
||||
final int result = findItOffset(editor, startOffset, 1, lastDir);
|
||||
final Pair<Integer, MotionType> result = findItOffset(editor, startOffset, 1, lastDir);
|
||||
|
||||
// Set lastPatternOffset AFTER searching so it doesn't affect the result
|
||||
lastPatternOffset = patternOffset != 0 ? Integer.toString(patternOffset) : "";
|
||||
@@ -422,7 +424,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
logger.debug("lastDir=" + lastDir);
|
||||
}
|
||||
|
||||
return result;
|
||||
return result != null ? result.getFirst() : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -467,8 +469,9 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
resetShowSearchHighlight();
|
||||
forceUpdateSearchHighlights();
|
||||
|
||||
final int offset = findItOffset(((IjVimEditor)editor).getEditor(), range.getStartOffset(), count, lastDir);
|
||||
return offset == -1 ? range.getStartOffset() : offset;
|
||||
final Pair<Integer, MotionType> offsetAndMotion =
|
||||
findItOffset(((IjVimEditor)editor).getEditor(), range.getStartOffset(), count, lastDir);
|
||||
return offsetAndMotion == null ? range.getStartOffset() : offsetAndMotion.getFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -511,14 +514,14 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
resetShowSearchHighlight();
|
||||
updateSearchHighlights();
|
||||
final int startOffset = caret.getOffset();
|
||||
int offset = findItOffset(editor, startOffset, count, dir);
|
||||
if (offset == startOffset) {
|
||||
Pair<Integer, MotionType> offsetAndMotion = findItOffset(editor, startOffset, count, dir);
|
||||
if (offsetAndMotion != null && offsetAndMotion.getFirst() == startOffset) {
|
||||
/* Avoid getting stuck on the current cursor position, which can
|
||||
* happen when an offset is given and the cursor is on the last char
|
||||
* in the buffer: Repeat with count + 1. */
|
||||
offset = findItOffset(editor, startOffset, count + 1, dir);
|
||||
offsetAndMotion = findItOffset(editor, startOffset, count + 1, dir);
|
||||
}
|
||||
return offset;
|
||||
return offsetAndMotion != null ? offsetAndMotion.getFirst() : -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -542,20 +545,24 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
*
|
||||
* @param editor The editor to search in
|
||||
* @param caret The caret to use for initial search offset, and to move for interactive substitution
|
||||
* @param context
|
||||
* @param range Only search and substitute within the given line range. Must be valid
|
||||
* @param excmd The command part of the ex command line, e.g. `s` or `substitute`, or `~`
|
||||
* @param exarg The argument to the substitute command, such as `/{pattern}/{string}/[flags]`
|
||||
* @return True if the substitution succeeds, false on error. Will succeed even if nothing is modified
|
||||
* @return True if the substitution succeeds, false on error. Will succeed even if nothing is modified
|
||||
*/
|
||||
@Override
|
||||
@RWLockLabel.SelfSynchronized
|
||||
public boolean processSubstituteCommand(@NotNull VimEditor editor,
|
||||
@NotNull VimCaret caret,
|
||||
@NotNull ExecutionContext context,
|
||||
@NotNull LineRange range,
|
||||
@NotNull @NonNls String excmd,
|
||||
@NotNull @NonNls String exarg,
|
||||
@NotNull VimLContext parent) {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) return super.processSubstituteCommand(editor, caret, range, excmd, exarg, parent);
|
||||
if (globalIjOptions(injector).getUseNewRegex()) {
|
||||
return super.processSubstituteCommand(editor, caret, context, range, excmd, exarg, parent);
|
||||
}
|
||||
|
||||
// Explicitly exit visual mode here, so that visual mode marks don't change when we move the cursor to a match.
|
||||
List<ExException> exceptions = new ArrayList<>();
|
||||
@@ -804,7 +811,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
CharacterPosition startpos = new CharacterPosition(lnum + regmatch.startpos[0].lnum, regmatch.startpos[0].col);
|
||||
CharacterPosition endpos = new CharacterPosition(lnum + regmatch.endpos[0].lnum, regmatch.endpos[0].col);
|
||||
int startoff = startpos.toOffset(((IjVimEditor)editor).getEditor());
|
||||
int endoff = endpos.toOffset(((IjVimEditor)editor).getEditor());
|
||||
int endoff = (endpos.line >= lcount) ? (int) editor.fileSize() : endpos.toOffset(((IjVimEditor)editor).getEditor());
|
||||
|
||||
if (do_all || line != lastLine) {
|
||||
boolean doReplace = true;
|
||||
@@ -812,7 +819,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
RangeHighlighter hl =
|
||||
SearchHighlightsHelper.addSubstitutionConfirmationHighlight(((IjVimEditor)editor).getEditor(), startoff,
|
||||
endoff);
|
||||
final ReplaceConfirmationChoice choice = confirmChoice(((IjVimEditor)editor).getEditor(), match, ((IjVimCaret)caret).getCaret(), startoff);
|
||||
final ReplaceConfirmationChoice choice = confirmChoice(((IjVimEditor)editor).getEditor(), context, match, ((IjVimCaret)caret).getCaret(), startoff);
|
||||
((IjVimEditor)editor).getEditor().getMarkupModel().removeHighlighter(hl);
|
||||
switch (choice) {
|
||||
case SUBSTITUTE_THIS:
|
||||
@@ -841,8 +848,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
caret.moveToOffset(startoff);
|
||||
if (expression != null) {
|
||||
try {
|
||||
match =
|
||||
expression.evaluate(editor, injector.getExecutionContextManager().onEditor(editor, null), parent).toInsertableString();
|
||||
match = expression.evaluate(editor, context, parent).toInsertableString();
|
||||
}
|
||||
catch (Exception e) {
|
||||
exceptions.add((ExException)e);
|
||||
@@ -864,23 +870,23 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
|
||||
lastLine = line;
|
||||
|
||||
lnum += nmatch - 1;
|
||||
if (do_all && startoff != endoff) {
|
||||
if (newpos != null) {
|
||||
lnum = newpos.line;
|
||||
searchcol = newpos.column;
|
||||
}
|
||||
else {
|
||||
lnum += Math.max(1, nmatch - 1);
|
||||
searchcol = endpos.column;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lnum += Math.max(1, nmatch - 1);
|
||||
searchcol = 0;
|
||||
lnum++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lnum++;
|
||||
lnum += Math.max(1, nmatch - 1);
|
||||
searchcol = 0;
|
||||
}
|
||||
}
|
||||
@@ -891,7 +897,8 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
VimPlugin.getMotion().moveCaretToLineStartSkipLeading(editor, editor.offsetToBufferPosition(lastMatch).getLine()));
|
||||
}
|
||||
else {
|
||||
VimPlugin.showMessage(MessageHelper.message(Msg.e_patnotf2, pattern));
|
||||
// E486: Pattern not found: {0}
|
||||
VimPlugin.showMessage(MessageHelper.message("E486", pattern));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -953,17 +960,17 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
if (which_pat == RE_LAST) {
|
||||
which_pat = lastPatternIdx;
|
||||
}
|
||||
String errorMessage = null;
|
||||
switch (which_pat) {
|
||||
case RE_SEARCH:
|
||||
String errorMessage = switch (which_pat) {
|
||||
case RE_SEARCH -> {
|
||||
pattern = lastSearch;
|
||||
errorMessage = MessageHelper.message("e_nopresub");
|
||||
break;
|
||||
case RE_SUBST:
|
||||
yield MessageHelper.message("e_nopresub");
|
||||
}
|
||||
case RE_SUBST -> {
|
||||
pattern = lastSubstitute;
|
||||
errorMessage = MessageHelper.message("e_noprevre");
|
||||
break;
|
||||
}
|
||||
yield MessageHelper.message("e_noprevre");
|
||||
}
|
||||
default -> null;
|
||||
};
|
||||
|
||||
// Pattern was never defined
|
||||
if (pattern == null) {
|
||||
@@ -993,7 +1000,9 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
return new Pair<>(true, new Triple<>(regmatch, pattern, sp));
|
||||
}
|
||||
|
||||
private static @NotNull ReplaceConfirmationChoice confirmChoice(@NotNull Editor editor, @NotNull String match, @NotNull Caret caret, int startoff) {
|
||||
private static @NotNull ReplaceConfirmationChoice confirmChoice(@NotNull Editor editor,
|
||||
@NotNull ExecutionContext context,
|
||||
@NotNull String match, @NotNull Caret caret, int startoff) {
|
||||
final Ref<ReplaceConfirmationChoice> result = Ref.create(ReplaceConfirmationChoice.QUIT);
|
||||
final Function1<KeyStroke, Boolean> keyStrokeProcessor = key -> {
|
||||
final ReplaceConfirmationChoice choice;
|
||||
@@ -1027,7 +1036,6 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
else {
|
||||
// XXX: The Ex entry panel is used only for UI here, its logic might be inappropriate for this method
|
||||
final ExEntryPanel exEntryPanel = ExEntryPanel.getInstanceWithoutShortcuts();
|
||||
ExecutionContext.Editor context = injector.getExecutionContextManager().onEditor(new IjVimEditor(editor), null);
|
||||
exEntryPanel.activate(editor, ((IjEditorExecutionContext)context).getContext(), MessageHelper.message("replace.with.0", match), "", 1);
|
||||
new IjVimCaret(caret).moveToOffset(startoff);
|
||||
ModalEntry.INSTANCE.activate(new IjVimEditor(editor), keyStrokeProcessor);
|
||||
@@ -1085,9 +1093,9 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
private @Nullable TextRange findNextSearchForGn(@NotNull VimEditor editor, int count, boolean forwards) {
|
||||
if (forwards) {
|
||||
final EnumSet<SearchOptions> searchOptions = EnumSet.of(SearchOptions.WRAP, SearchOptions.WHOLE_FILE);
|
||||
return VimInjectorKt.getInjector().getSearchHelper().findPattern(editor, getLastUsedPattern(), editor.primaryCaret().getOffset().getPoint(), count, searchOptions);
|
||||
return VimInjectorKt.getInjector().getSearchHelper().findPattern(editor, getLastUsedPattern(), editor.primaryCaret().getOffset(), count, searchOptions);
|
||||
} else {
|
||||
return searchBackward(editor, editor.primaryCaret().getOffset().getPoint(), count);
|
||||
return searchBackward(editor, editor.primaryCaret().getOffset(), count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1200,47 +1208,56 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
public static DocumentSearchListener INSTANCE = new DocumentSearchListener();
|
||||
|
||||
@Contract(pure = true)
|
||||
private DocumentSearchListener () {
|
||||
private DocumentSearchListener() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void documentChanged(@NotNull DocumentEvent event) {
|
||||
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
|
||||
final Document document = event.getDocument();
|
||||
// Loop over all local editors for the changed document, across all projects, and update search highlights.
|
||||
// Note that the change may have come from a remote guest in Code With Me scenarios (in which case
|
||||
// ClientId.current will be a guest ID), but we don't care - we still need to add/remove highlights for the
|
||||
// changed text. Make sure we only update local editors, though.
|
||||
final Document document = event.getDocument();
|
||||
for (VimEditor vimEditor : injector.getEditorGroup().getEditors(new IjVimDocument(document))) {
|
||||
final Editor editor = ((IjVimEditor)vimEditor).getEditor();
|
||||
Collection<RangeHighlighter> existingHighlighters = UserDataManager.getVimLastHighlighters(editor);
|
||||
if (existingHighlighters == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Editor editor : localEditors(document, project)) {
|
||||
Collection<RangeHighlighter> hls = UserDataManager.getVimLastHighlighters(editor);
|
||||
if (hls == null) {
|
||||
continue;
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("hls=" + existingHighlighters);
|
||||
logger.debug("event=" + event);
|
||||
}
|
||||
|
||||
// We can only re-highlight whole lines, so clear any highlights in the affected lines.
|
||||
// If we're deleting lines, this will clear + re-highlight the new current line, which hasn't been modified.
|
||||
// However, we still want to re-highlight this line in case any highlights cross the line boundaries.
|
||||
// If we're adding lines, this will clear + re-highlight all new lines.
|
||||
final LogicalPosition startPosition = editor.offsetToLogicalPosition(event.getOffset());
|
||||
final LogicalPosition endPosition = editor.offsetToLogicalPosition(event.getOffset() + event.getNewLength());
|
||||
final int startLineOffset = document.getLineStartOffset(startPosition.line);
|
||||
final int endLineOffset = document.getLineEndOffset(endPosition.line);
|
||||
|
||||
// Remove any highlights that have already been deleted, and remove + clear those that intersect with the change
|
||||
final Iterator<RangeHighlighter> iter = existingHighlighters.iterator();
|
||||
while (iter.hasNext()) {
|
||||
final RangeHighlighter highlighter = iter.next();
|
||||
if (!highlighter.isValid()) {
|
||||
iter.remove();
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("hls=" + hls);
|
||||
logger.debug("event=" + event);
|
||||
else if (highlighter.getTextRange().intersects(startLineOffset, endLineOffset)) {
|
||||
iter.remove();
|
||||
editor.getMarkupModel().removeHighlighter(highlighter);
|
||||
}
|
||||
}
|
||||
|
||||
// We can only re-highlight whole lines, so clear any highlights in the affected lines
|
||||
final LogicalPosition startPosition = editor.offsetToLogicalPosition(event.getOffset());
|
||||
final LogicalPosition endPosition = editor.offsetToLogicalPosition(event.getOffset() + event.getNewLength());
|
||||
final int startLineOffset = document.getLineStartOffset(startPosition.line);
|
||||
final int endLineOffset = document.getLineEndOffset(endPosition.line);
|
||||
VimPlugin.getSearch().highlightSearchLines(editor, startPosition.line, endPosition.line);
|
||||
|
||||
final Iterator<RangeHighlighter> iter = hls.iterator();
|
||||
while (iter.hasNext()) {
|
||||
final RangeHighlighter highlighter = iter.next();
|
||||
if (!highlighter.isValid() || (highlighter.getStartOffset() >= startLineOffset && highlighter.getEndOffset() <= endLineOffset)) {
|
||||
iter.remove();
|
||||
editor.getMarkupModel().removeHighlighter(highlighter);
|
||||
}
|
||||
}
|
||||
|
||||
VimPlugin.getSearch().highlightSearchLines(editor, startPosition.line, endPosition.line);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
hls = UserDataManager.getVimLastHighlighters(editor);
|
||||
logger.debug("sl=" + startPosition.line + ", el=" + endPosition.line);
|
||||
logger.debug("hls=" + hls);
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
existingHighlighters = UserDataManager.getVimLastHighlighters(editor);
|
||||
logger.debug("sl=" + startPosition.line + ", el=" + endPosition.line);
|
||||
logger.debug("hls=" + existingHighlighters);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1266,9 +1283,11 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
* @param startOffset The offset to search from
|
||||
* @param count Find the nth occurrence
|
||||
* @param dir The direction to search in
|
||||
* @return The offset to the occurrence or -1 if not found
|
||||
* @return Pair containing the offset to the next occurrence of the pattern, and the [MotionType] based
|
||||
* on the search offset. The value will be `null` if no result is found.
|
||||
*/
|
||||
private int findItOffset(@NotNull Editor editor, int startOffset, int count, Direction dir) {
|
||||
@Nullable
|
||||
private Pair<Integer, MotionType> findItOffset(@NotNull Editor editor, int startOffset, int count, Direction dir) {
|
||||
boolean wrap = globalOptions(injector).getWrapscan();
|
||||
logger.debug("Perform search. Direction: " + dir + " wrap: " + wrap);
|
||||
|
||||
@@ -1278,7 +1297,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
|
||||
ParsePosition pp = new ParsePosition(0);
|
||||
|
||||
if (lastPatternOffset.length() > 0) {
|
||||
if (!lastPatternOffset.isEmpty()) {
|
||||
if (Character.isDigit(lastPatternOffset.charAt(0)) || lastPatternOffset.charAt(0) == '+' || lastPatternOffset.charAt(0) == '-') {
|
||||
offsetIsLineOffset = true;
|
||||
|
||||
@@ -1314,6 +1333,18 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
}
|
||||
}
|
||||
|
||||
// `/{pattern}/{offset}` is inclusive if offset contains `e`, and linewise if there's a line offset
|
||||
final MotionType motionType;
|
||||
if (offset != 0 && !hasEndOffset) {
|
||||
motionType = MotionType.LINE_WISE;
|
||||
}
|
||||
else if (hasEndOffset) {
|
||||
motionType = MotionType.INCLUSIVE;
|
||||
}
|
||||
else {
|
||||
motionType = MotionType.EXCLUSIVE;
|
||||
}
|
||||
|
||||
/*
|
||||
* If there is a character offset, subtract it from the current
|
||||
* position, so we don't get stuck at "?pat?e+2" or "/pat/s-2".
|
||||
@@ -1335,7 +1366,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
TextRange range = injector.getSearchHelper().findPattern(new IjVimEditor(editor), getLastUsedPattern(), startOffset, count, searchOptions);
|
||||
if (range == null) {
|
||||
logger.warn("No range is found");
|
||||
return -1;
|
||||
return null;
|
||||
}
|
||||
|
||||
int res = range.getStartOffset();
|
||||
@@ -1343,8 +1374,6 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
if (offsetIsLineOffset) {
|
||||
int line = editor.offsetToLogicalPosition(range.getStartOffset()).line;
|
||||
int newLine = EngineEditorHelperKt.normalizeLine(new IjVimEditor(editor), line + offset);
|
||||
|
||||
// TODO: Don't move the caret!
|
||||
res = VimPlugin.getMotion().moveCaretToLineStart(new IjVimEditor(editor), newLine);
|
||||
}
|
||||
else if (hasEndOffset || offset != 0) {
|
||||
@@ -1362,16 +1391,19 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
nextDir = Direction.BACKWARDS;
|
||||
}
|
||||
else {
|
||||
return res;
|
||||
return new Pair(res, motionType);
|
||||
}
|
||||
|
||||
if (lastPatternOffset.length() - ppos > 2) {
|
||||
ppos++;
|
||||
}
|
||||
|
||||
res = processSearchCommand(new IjVimEditor(editor), lastPatternOffset.substring(ppos + 1), res, nextDir);
|
||||
Pair<Integer, MotionType> offsetAndMotion =
|
||||
processSearchCommand(new IjVimEditor(editor), lastPatternOffset.substring(ppos + 1), res, 1, nextDir);
|
||||
res = offsetAndMotion != null ? offsetAndMotion.getFirst() : -1;
|
||||
}
|
||||
return res;
|
||||
|
||||
return new Pair<Integer, MotionType>(res, motionType);
|
||||
}
|
||||
|
||||
|
||||
@@ -1387,7 +1419,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
|
||||
addOptionalTextElement(search, "last-search", lastSearch);
|
||||
addOptionalTextElement(search, "last-substitute", lastSubstitute);
|
||||
addOptionalTextElement(search, "last-offset", lastPatternOffset.length() > 0 ? lastPatternOffset : null);
|
||||
addOptionalTextElement(search, "last-offset", !lastPatternOffset.isEmpty() ? lastPatternOffset : null);
|
||||
addOptionalTextElement(search, "last-replace", lastReplace);
|
||||
addOptionalTextElement(search, "last-pattern", lastPatternIdx == RE_SEARCH ? lastSearch : lastSubstitute);
|
||||
addOptionalTextElement(search, "last-dir", Integer.toString(lastDir.toInt()));
|
||||
|
@@ -111,7 +111,7 @@ internal class JumpsListener(val project: Project) : RecentPlacesListener {
|
||||
}
|
||||
|
||||
private fun buildJump(place: PlaceInfo): Jump? {
|
||||
val editor = injector.editorGroup.localEditors().firstOrNull { it.ij.virtualFile == place.file } ?: return null
|
||||
val editor = injector.editorGroup.getEditors().firstOrNull { it.ij.virtualFile == place.file } ?: return null
|
||||
val offset = place.caretPosition?.startOffset ?: return null
|
||||
|
||||
val bufferPosition = editor.offsetToBufferPosition(offset)
|
||||
|
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
package com.maddyhome.idea.vim.group
|
||||
|
||||
import com.intellij.codeWithMe.ClientId
|
||||
import com.intellij.ide.bookmark.Bookmark
|
||||
import com.intellij.ide.bookmark.BookmarkGroup
|
||||
import com.intellij.ide.bookmark.BookmarksListener
|
||||
@@ -18,7 +19,7 @@ import com.intellij.openapi.components.State
|
||||
import com.intellij.openapi.components.Storage
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.editor.Document
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.EditorFactory
|
||||
import com.intellij.openapi.editor.event.DocumentEvent
|
||||
import com.intellij.openapi.editor.event.DocumentListener
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||
@@ -28,11 +29,11 @@ import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.util.asSafely
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.VimEditorGroup
|
||||
import com.maddyhome.idea.vim.api.VimMarkService
|
||||
import com.maddyhome.idea.vim.api.VimMarkServiceBase
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.group.SystemMarks.Companion.createOrGetSystemMark
|
||||
import com.maddyhome.idea.vim.helper.localEditors
|
||||
import com.maddyhome.idea.vim.mark.IntellijMark
|
||||
import com.maddyhome.idea.vim.mark.Mark
|
||||
import com.maddyhome.idea.vim.mark.VimMark.Companion.create
|
||||
@@ -193,6 +194,10 @@ internal class VimMarkServiceImpl : VimMarkServiceBase(), PersistentStateCompone
|
||||
* This event indicates that a document is about to be changed. We use this event to update all the
|
||||
* editor's marks if text is about to be deleted.
|
||||
*
|
||||
* Note that the event is fired for both local changes and changes from remote guests in Code With Me scenarios (in
|
||||
* which case [ClientId.current] will be the remote client). We don't care who caused it, we just need to update the
|
||||
* stored marks.
|
||||
*
|
||||
* @param event The change event
|
||||
*/
|
||||
override fun beforeDocumentChange(event: DocumentEvent) {
|
||||
@@ -200,15 +205,18 @@ internal class VimMarkServiceImpl : VimMarkServiceBase(), PersistentStateCompone
|
||||
if (logger.isDebugEnabled) logger.debug("MarkUpdater before, event = $event")
|
||||
if (event.oldLength == 0) return
|
||||
val doc = event.document
|
||||
val anEditor = getAnEditor(doc) ?: return
|
||||
injector.markService
|
||||
.updateMarksFromDelete(IjVimEditor(anEditor), event.offset, event.oldLength)
|
||||
val anEditor = getAnyEditorForDocument(doc) ?: return
|
||||
injector.markService.updateMarksFromDelete(anEditor, event.offset, event.oldLength)
|
||||
}
|
||||
|
||||
/**
|
||||
* This event indicates that a document was just changed. We use this event to update all the editor's
|
||||
* marks if text was just added.
|
||||
*
|
||||
* Note that the event is fired for both local changes and changes from remote guests in Code With Me scenarios (in
|
||||
* which case [ClientId.current] will be the remote client). We don't care who caused it, we just need to update the
|
||||
* stored marks.
|
||||
*
|
||||
* @param event The change event
|
||||
*/
|
||||
override fun documentChanged(event: DocumentEvent) {
|
||||
@@ -216,19 +224,19 @@ internal class VimMarkServiceImpl : VimMarkServiceBase(), PersistentStateCompone
|
||||
if (logger.isDebugEnabled) logger.debug("MarkUpdater after, event = $event")
|
||||
if (event.newLength == 0 || event.newLength == 1 && event.newFragment[0] != '\n') return
|
||||
val doc = event.document
|
||||
val anEditor = getAnEditor(doc) ?: return
|
||||
injector.markService
|
||||
.updateMarksFromInsert(IjVimEditor(anEditor), event.offset, event.newLength)
|
||||
val anEditor = getAnyEditorForDocument(doc) ?: return
|
||||
injector.markService.updateMarksFromInsert(anEditor, event.offset, event.newLength)
|
||||
}
|
||||
|
||||
private fun getAnEditor(doc: Document): Editor? {
|
||||
val editors = localEditors(doc)
|
||||
return if (editors.size > 0) {
|
||||
editors[0]
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get any editor for the given document
|
||||
*
|
||||
* We need an editor to help calculate offsets for marks, and it doesn't matter which one we use, because they would
|
||||
* all return the same results. However, we cannot use [VimEditorGroup.getEditors] because the change might have
|
||||
* come from a remote guest and there might not be an open local editor.
|
||||
*/
|
||||
private fun getAnyEditorForDocument(doc: Document) =
|
||||
EditorFactory.getInstance().getEditors(doc).firstOrNull()?.let { IjVimEditor(it) }
|
||||
}
|
||||
|
||||
class VimBookmarksListener(private val myProject: Project) : BookmarksListener {
|
||||
|
@@ -8,9 +8,11 @@
|
||||
|
||||
package com.maddyhome.idea.vim.group
|
||||
|
||||
import com.intellij.openapi.components.Service
|
||||
import org.apache.commons.codec.binary.Base64
|
||||
import org.jdom.Element
|
||||
|
||||
@Service
|
||||
internal class XMLGroup {
|
||||
/**
|
||||
* Set the text of an XML element, safely encode it if needed.
|
||||
|
@@ -14,6 +14,7 @@ import com.intellij.ide.DataManager
|
||||
import com.intellij.ide.PasteProvider
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.RangeMarker
|
||||
import com.intellij.openapi.editor.ex.EditorEx
|
||||
@@ -51,6 +52,7 @@ import com.maddyhome.idea.vim.state.mode.isChar
|
||||
import com.maddyhome.idea.vim.state.mode.isLine
|
||||
import java.awt.datatransfer.DataFlavor
|
||||
|
||||
@Service
|
||||
internal class PutGroup : VimPutBase() {
|
||||
|
||||
override fun getProviderForPasteViaIde(
|
||||
|
@@ -20,17 +20,17 @@ import com.maddyhome.idea.vim.helper.exitVisualMode
|
||||
import com.maddyhome.idea.vim.helper.hasVisualSelection
|
||||
import com.maddyhome.idea.vim.helper.inInsertMode
|
||||
import com.maddyhome.idea.vim.helper.inNormalMode
|
||||
import com.maddyhome.idea.vim.helper.isIdeaVimDisabledHere
|
||||
import com.maddyhome.idea.vim.helper.isTemplateActive
|
||||
import com.maddyhome.idea.vim.helper.vimStateMachine
|
||||
import com.maddyhome.idea.vim.helper.vimDisabled
|
||||
import com.maddyhome.idea.vim.listener.VimListenerManager
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.options.OptionConstants
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
import com.maddyhome.idea.vim.state.mode.inCommandLineMode
|
||||
import com.maddyhome.idea.vim.state.mode.inNormalMode
|
||||
import com.maddyhome.idea.vim.state.mode.inSelectMode
|
||||
import com.maddyhome.idea.vim.state.mode.inVisualMode
|
||||
import com.maddyhome.idea.vim.state.mode.mode
|
||||
import com.maddyhome.idea.vim.state.mode.returnTo
|
||||
import com.maddyhome.idea.vim.vimscript.model.options.helpers.IdeaRefactorModeHelper
|
||||
import com.maddyhome.idea.vim.vimscript.model.options.helpers.isIdeaRefactorModeKeep
|
||||
import com.maddyhome.idea.vim.vimscript.model.options.helpers.isIdeaRefactorModeSelect
|
||||
@@ -55,9 +55,7 @@ internal object IdeaSelectionControl {
|
||||
selectionSource: VimListenerManager.SelectionSource = VimListenerManager.SelectionSource.OTHER,
|
||||
) {
|
||||
VimVisualTimer.singleTask(editor.vim.mode) { initialMode ->
|
||||
|
||||
if (VimPlugin.isNotEnabled()) return@singleTask
|
||||
if (editor.isIdeaVimDisabledHere) return@singleTask
|
||||
if (vimDisabled(editor)) return@singleTask
|
||||
|
||||
logger.debug("Adjust non-vim selection. Source: $selectionSource, initialMode: $initialMode")
|
||||
|
||||
@@ -71,6 +69,11 @@ internal object IdeaSelectionControl {
|
||||
}
|
||||
|
||||
if (editor.selectionModel.hasSelection(true)) {
|
||||
if (editor.vim.inCommandLineMode && editor.vim.mode.returnTo().hasVisualSelection) {
|
||||
logger.trace { "Modifying selection while in Command-line mode, most likely incsearch" }
|
||||
return@singleTask
|
||||
}
|
||||
|
||||
if (dontChangeMode(editor)) {
|
||||
IdeaRefactorModeHelper.correctSelection(editor)
|
||||
logger.trace { "Selection corrected for refactoring" }
|
||||
@@ -79,7 +82,7 @@ internal object IdeaSelectionControl {
|
||||
|
||||
logger.debug("Some carets have selection. State before adjustment: ${editor.vim.mode}")
|
||||
|
||||
editor.vim.vimStateMachine.mode = Mode.NORMAL()
|
||||
editor.vim.mode = Mode.NORMAL()
|
||||
|
||||
activateMode(editor, chooseSelectionMode(editor, selectionSource, true))
|
||||
} else {
|
||||
@@ -121,7 +124,7 @@ internal object IdeaSelectionControl {
|
||||
is Mode.VISUAL -> VimPlugin.getVisualMotion().enterVisualMode(editor.vim, mode.selectionType)
|
||||
is Mode.SELECT -> VimPlugin.getVisualMotion().enterSelectMode(editor.vim, mode.selectionType)
|
||||
is Mode.INSERT -> VimPlugin.getChange()
|
||||
.insertBeforeCursor(editor.vim, injector.executionContextManager.onEditor(editor.vim))
|
||||
.insertBeforeCursor(editor.vim, injector.executionContextManager.getEditorExecutionContext(editor.vim))
|
||||
|
||||
is Mode.NORMAL -> Unit
|
||||
else -> error("Unexpected mode: $mode")
|
||||
|
@@ -12,13 +12,13 @@ import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.api.getLineEndForOffset
|
||||
import com.maddyhome.idea.vim.api.getLineStartForOffset
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
import com.maddyhome.idea.vim.state.mode.inBlockSelection
|
||||
import com.maddyhome.idea.vim.helper.isEndAllowed
|
||||
import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset
|
||||
import com.maddyhome.idea.vim.helper.vimSelectionStart
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
import com.maddyhome.idea.vim.state.mode.inBlockSelection
|
||||
|
||||
internal fun moveCaretOneCharLeftFromSelectionEnd(editor: Editor, predictedMode: Mode) {
|
||||
if (predictedMode !is Mode.VISUAL) {
|
||||
|
@@ -13,10 +13,10 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.VimVisualMotionGroupBase
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
import com.maddyhome.idea.vim.command.engine
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
|
||||
/**
|
||||
* @author Alex Plate
|
||||
|
@@ -27,7 +27,6 @@ import com.intellij.openapi.util.UserDataHolder
|
||||
import com.intellij.openapi.util.removeUserData
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.globalOptions
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.api.key
|
||||
import com.maddyhome.idea.vim.group.IjOptionConstants
|
||||
@@ -39,7 +38,6 @@ import com.maddyhome.idea.vim.newapi.actionStartedFromVim
|
||||
import com.maddyhome.idea.vim.newapi.globalIjOptions
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
import com.maddyhome.idea.vim.state.mode.mode
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
@@ -339,8 +337,9 @@ internal abstract class VimKeyHandler(nextHandler: EditorActionHandler?) : Octop
|
||||
|
||||
override fun executeHandler(editor: Editor, caret: Caret?, dataContext: DataContext?) {
|
||||
val enterKey = key(key)
|
||||
val context = injector.executionContextManager.onEditor(editor.vim, dataContext?.vim)
|
||||
KeyHandler.getInstance().handleKey(editor.vim, enterKey, context)
|
||||
val context = dataContext?.vim ?: injector.executionContextManager.getEditorExecutionContext(editor.vim)
|
||||
val keyHandler = KeyHandler.getInstance()
|
||||
keyHandler.handleKey(editor.vim, enterKey, context, keyHandler.keyHandlerState)
|
||||
}
|
||||
|
||||
override fun isHandlerEnabled(editor: Editor, dataContext: DataContext?): Boolean {
|
||||
@@ -362,4 +361,4 @@ internal fun isOctopusEnabled(s: KeyStroke, editor: Editor): Boolean {
|
||||
}
|
||||
|
||||
internal val enableOctopus: Boolean
|
||||
get() = injector.globalOptions().octopushandler
|
||||
get() = injector.application.isOctopusEnabled()
|
||||
|
@@ -8,6 +8,7 @@
|
||||
|
||||
package com.maddyhome.idea.vim.helper
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.diagnostic.thisLogger
|
||||
import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.CaretVisualAttributes
|
||||
@@ -18,14 +19,17 @@ import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.globalOptions
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.common.IsReplaceCharListener
|
||||
import com.maddyhome.idea.vim.common.ModeChangeListener
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.options.EffectiveOptionValueChangeListener
|
||||
import com.maddyhome.idea.vim.options.helpers.GuiCursorMode
|
||||
import com.maddyhome.idea.vim.options.helpers.GuiCursorOptionHelper
|
||||
import com.maddyhome.idea.vim.options.helpers.GuiCursorType
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
import com.maddyhome.idea.vim.state.mode.inBlockSelection
|
||||
import com.maddyhome.idea.vim.state.mode.mode
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import java.awt.Color
|
||||
|
||||
@@ -85,7 +89,12 @@ private fun Editor.updatePrimaryCaretVisualAttributes() {
|
||||
caretModel.primaryCaret.visualAttributes = AttributesCache.getCaretVisualAttributes(this)
|
||||
|
||||
// Make sure the caret is visible as soon as it's set. It might be invisible while blinking
|
||||
(this as? EditorEx)?.setCaretVisible(true)
|
||||
// NOTE: At the moment, this causes project leak in tests
|
||||
// IJPL-928 - this will be fixed in 2024.2
|
||||
// [VERSION UPDATE] 2024.2 - remove if wrapping
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode) {
|
||||
(this as? EditorEx)?.setCaretVisible(true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Editor.updateSecondaryCaretsVisualAttributes() {
|
||||
@@ -134,3 +143,31 @@ private object AttributesCache {
|
||||
|
||||
@TestOnly
|
||||
internal fun getGuiCursorMode(editor: Editor) = editor.guicursorMode()
|
||||
|
||||
public class CaretVisualAttributesListener : IsReplaceCharListener, ModeChangeListener {
|
||||
override fun isReplaceCharChanged(editor: VimEditor) {
|
||||
updateCaretsVisual(editor)
|
||||
}
|
||||
|
||||
override fun modeChanged(editor: VimEditor, oldMode: Mode) {
|
||||
updateCaretsVisual(editor)
|
||||
}
|
||||
|
||||
private fun updateCaretsVisual(editor: VimEditor) {
|
||||
if (injector.globalOptions().ideaglobalmode) {
|
||||
updateAllEditorsCaretsVisual()
|
||||
} else {
|
||||
val ijEditor = (editor as IjVimEditor).editor
|
||||
ijEditor.updateCaretsVisualAttributes()
|
||||
ijEditor.updateCaretsVisualPosition()
|
||||
}
|
||||
}
|
||||
|
||||
public fun updateAllEditorsCaretsVisual() {
|
||||
injector.editorGroup.getEditors().forEach { editor ->
|
||||
val ijEditor = (editor as IjVimEditor).editor
|
||||
ijEditor.updateCaretsVisualAttributes()
|
||||
ijEditor.updateCaretsVisualPosition()
|
||||
}
|
||||
}
|
||||
}
|
@@ -20,7 +20,6 @@ import com.maddyhome.idea.vim.options.OptionAccessScope
|
||||
import com.maddyhome.idea.vim.options.OptionConstants
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
import com.maddyhome.idea.vim.state.mode.inVisualMode
|
||||
import com.maddyhome.idea.vim.state.mode.mode
|
||||
|
||||
internal val Mode.hasVisualSelection
|
||||
get() = when (this) {
|
||||
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2023 The IdeaVim authors
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE.txt file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim.helper
|
||||
|
||||
import com.intellij.openapi.editor.Document
|
||||
import com.intellij.openapi.editor.event.DocumentListener
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.maddyhome.idea.vim.EventFacade
|
||||
import com.maddyhome.idea.vim.group.SearchGroup
|
||||
import com.maddyhome.idea.vim.group.VimMarkServiceImpl
|
||||
|
||||
internal object DocumentManager {
|
||||
private val docListeners = mutableSetOf<DocumentListener>()
|
||||
private val LISTENER_MARKER = Key<String>("VimlistenerMarker")
|
||||
|
||||
init {
|
||||
docListeners += VimMarkServiceImpl.MarkUpdater
|
||||
docListeners += SearchGroup.DocumentSearchListener.INSTANCE
|
||||
}
|
||||
|
||||
fun addListeners(doc: Document) {
|
||||
val marker = doc.getUserData(LISTENER_MARKER)
|
||||
if (marker != null) return
|
||||
|
||||
doc.putUserData(LISTENER_MARKER, "foo")
|
||||
for (docListener in docListeners) {
|
||||
EventFacade.getInstance().addDocumentListener(doc, docListener)
|
||||
}
|
||||
}
|
||||
|
||||
fun removeListeners(doc: Document) {
|
||||
doc.getUserData(LISTENER_MARKER) ?: return
|
||||
|
||||
doc.putUserData(LISTENER_MARKER, null)
|
||||
for (docListener in docListeners) {
|
||||
EventFacade.getInstance().removeDocumentListener(doc, docListener)
|
||||
}
|
||||
}
|
||||
}
|
@@ -14,6 +14,7 @@ import com.intellij.openapi.editor.ex.util.EditorUtil
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.openapi.util.UserDataHolder
|
||||
|
||||
@Deprecated("Do not use context wrappers, use existing provided contexts. If no context available, use `injector.getExecutionContextManager().getEditorExecutionContext(editor)`")
|
||||
internal class EditorDataContext @Deprecated("Please use `init` method") constructor(
|
||||
private val editor: Editor,
|
||||
private val editorContext: DataContext,
|
||||
|
@@ -8,15 +8,18 @@
|
||||
|
||||
package com.maddyhome.idea.vim.helper;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.editor.ex.util.EditorUtil;
|
||||
import com.intellij.openapi.editor.impl.EditorImpl;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import com.maddyhome.idea.vim.api.EngineEditorHelperKt;
|
||||
import com.maddyhome.idea.vim.api.VimEditor;
|
||||
import com.maddyhome.idea.vim.common.IndentConfig;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimDocument;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel;
|
||||
import kotlin.Pair;
|
||||
@@ -29,6 +32,7 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static com.maddyhome.idea.vim.api.VimInjectorKt.injector;
|
||||
import static java.lang.Integer.max;
|
||||
import static java.lang.Integer.min;
|
||||
|
||||
@@ -50,6 +54,10 @@ public class EditorHelper {
|
||||
final ScrollingModel scrollingModel = editor.getScrollingModel();
|
||||
final Rectangle area = scrollingModel.getVisibleAreaOnScrollingFinished();
|
||||
scrollingModel.scroll(area.x, verticalOffset);
|
||||
// Simulate Vim's redraw (essentially to clear messages) if the screen is scrolled
|
||||
if (area.y != verticalOffset && area.y >= 0) {
|
||||
injector.getRedrawService().redraw();
|
||||
}
|
||||
return scrollingModel.getVisibleAreaOnScrollingFinished().y != area.y;
|
||||
}
|
||||
|
||||
@@ -57,6 +65,10 @@ public class EditorHelper {
|
||||
final ScrollingModel scrollingModel = editor.getScrollingModel();
|
||||
final Rectangle area = scrollingModel.getVisibleAreaOnScrollingFinished();
|
||||
scrollingModel.scroll(horizontalOffset, area.y);
|
||||
// Simulate Vim's redraw (essentially to clear messages) if the screen is scrolled
|
||||
if (area.x != horizontalOffset && area.x >= 0) {
|
||||
injector.getRedrawService().redraw();
|
||||
}
|
||||
}
|
||||
|
||||
public static int getVisualLineAtTopOfScreen(final @NotNull Editor editor) {
|
||||
@@ -75,10 +87,12 @@ public class EditorHelper {
|
||||
|
||||
public static int getNonNormalizedVisualLineAtBottomOfScreen(final @NotNull Editor editor) {
|
||||
// The editor will return line numbers of virtual space if the text doesn't reach the end of the visible area
|
||||
// (either because it's too short, or it's been scrolled up)
|
||||
// (either because it's too short, or it's been scrolled up).
|
||||
// Adjust available height if the ex entry text field is visible
|
||||
final Rectangle visibleArea = getVisibleArea(editor);
|
||||
return getFullVisualLine(editor, visibleArea.y + visibleArea.height, visibleArea.y,
|
||||
visibleArea.y + visibleArea.height);
|
||||
final int height = visibleArea.height - getExEntryHeight() - getHorizontalScrollbarHeight(editor);
|
||||
return getFullVisualLine(editor, visibleArea.y + height, visibleArea.y,
|
||||
visibleArea.y + height);
|
||||
}
|
||||
|
||||
public static int getVisualLineAtBottomOfScreen(final @NotNull Editor editor) {
|
||||
@@ -197,7 +211,7 @@ public class EditorHelper {
|
||||
* @param file The virtual file get the editor for
|
||||
* @return The matching editor or null if no match was found
|
||||
*/
|
||||
public static @Nullable Editor getEditor(final @Nullable VirtualFile file) {
|
||||
public static @Nullable VimEditor getEditor(final @Nullable VirtualFile file) {
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -206,23 +220,15 @@ public class EditorHelper {
|
||||
if (doc == null) {
|
||||
return null;
|
||||
}
|
||||
final List<Editor> editors = HelperKt.localEditors(doc);
|
||||
if (editors.size() > 0) {
|
||||
return editors.get(0);
|
||||
}
|
||||
|
||||
return null;
|
||||
return injector.getEditorGroup().getEditors(new IjVimDocument(doc)).stream().findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public static @NotNull String pad(final @NotNull Editor editor,
|
||||
@NotNull DataContext context,
|
||||
int line,
|
||||
final int to) {
|
||||
public static @NotNull String pad(final @NotNull Editor editor, int line, final int to) {
|
||||
final int len = EngineEditorHelperKt.lineLength(new IjVimEditor(editor), line);
|
||||
if (len >= to) return "";
|
||||
|
||||
final int limit = to - len;
|
||||
return IndentConfig.create(editor, context).createIndentBySize(limit);
|
||||
return IndentConfig.create(editor).createIndentBySize(limit);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -361,24 +367,40 @@ public class EditorHelper {
|
||||
}
|
||||
|
||||
private static int getOffsetToScrollVisualLineToBottomOfScreen(@NotNull Editor editor, int nonNormalisedVisualLine) {
|
||||
int exPanelHeight = 0;
|
||||
if (ExEntryPanel.getInstance().isActive()) {
|
||||
exPanelHeight = ExEntryPanel.getInstance().getHeight();
|
||||
}
|
||||
if (ExEntryPanel.getInstanceWithoutShortcuts().isActive()) {
|
||||
exPanelHeight += ExEntryPanel.getInstanceWithoutShortcuts().getHeight();
|
||||
}
|
||||
|
||||
// Note that we explicitly do not normalise the visual line, as we might be trying to scroll a virtual line, at the
|
||||
// end of the file
|
||||
// end of the file.
|
||||
// Adjust available height if the ex entry text field is visible
|
||||
final int lineHeight = editor.getLineHeight();
|
||||
final int screenHeight = getVisibleArea(editor).height - exPanelHeight;
|
||||
final int screenHeight = getVisibleArea(editor).height - getExEntryHeight() - getHorizontalScrollbarHeight(editor);
|
||||
final int inlayHeight = EditorUtil.getInlaysHeight(editor, nonNormalisedVisualLine, false);
|
||||
final int maxInlayHeight = BLOCK_INLAY_MAX_LINE_HEIGHT * lineHeight;
|
||||
final int y = editor.visualLineToY(nonNormalisedVisualLine) + lineHeight + min(inlayHeight, maxInlayHeight);
|
||||
return max(0, y - screenHeight);
|
||||
}
|
||||
|
||||
private static int getExEntryHeight() {
|
||||
if (ExEntryPanel.getInstance().isActive()) {
|
||||
return ExEntryPanel.getInstance().getHeight();
|
||||
}
|
||||
if (ExEntryPanel.getInstanceWithoutShortcuts().isActive()) {
|
||||
return ExEntryPanel.getInstanceWithoutShortcuts().getHeight();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int getHorizontalScrollbarHeight(@NotNull final Editor editor) {
|
||||
// Horizontal scrollbars on macOS are either transparent AND auto-hide, so we don't need to worry about obscured
|
||||
// text, or always visible, opaque and outside the content area, so we don't need to adjust for them
|
||||
// Transparent scrollbars on Windows and Linux are overlays on the editor content area, and always visible. That
|
||||
// means they can obscure text, so we want to adjust by the scrollbar height. If they are not transparent, then they
|
||||
// are not overlays and are outside the content area. We don't need to adjust
|
||||
if (!SystemInfo.isMac && editor instanceof EditorImpl editorImpl && Registry.is("editor.transparent.scrollbar")) {
|
||||
return editorImpl.getScrollPane().getHorizontalScrollBar().getHeight();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void scrollColumnToLeftOfScreen(@NotNull Editor editor, int visualLine, int visualColumn) {
|
||||
int targetVisualColumn = visualColumn;
|
||||
|
||||
|
@@ -17,6 +17,7 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.ex.util.EditorUtil
|
||||
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
|
||||
import com.intellij.util.ui.table.JBTableRowEditor
|
||||
import com.maddyhome.idea.vim.api.StringListOptionValue
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.group.IjOptionConstants
|
||||
import com.maddyhome.idea.vim.newapi.globalIjOptions
|
||||
@@ -37,25 +38,27 @@ public val Editor.fileSize: Int
|
||||
internal val Editor.isIdeaVimDisabledHere: Boolean
|
||||
get() {
|
||||
val ideaVimSupportValue = injector.globalIjOptions().ideavimsupport
|
||||
return disabledInDialog ||
|
||||
(!ClientId.isCurrentlyUnderLocalId) || // CWM-927
|
||||
(!ideaVimSupportValue.contains(IjOptionConstants.ideavimsupport_singleline) && isDatabaseCell()) ||
|
||||
(!ideaVimSupportValue.contains(IjOptionConstants.ideavimsupport_singleline) && isOneLineMode)
|
||||
return (ideaVimDisabledInDialog(ideaVimSupportValue) && isInDialog()) ||
|
||||
!ClientId.isCurrentlyUnderLocalId || // CWM-927
|
||||
(ideaVimDisabledForSingleLine(ideaVimSupportValue) && isSingleLine())
|
||||
}
|
||||
|
||||
private fun Editor.isDatabaseCell(): Boolean {
|
||||
return isTableCellEditor(this.component)
|
||||
private fun ideaVimDisabledInDialog(ideaVimSupportValue: StringListOptionValue): Boolean {
|
||||
return !ideaVimSupportValue.contains(IjOptionConstants.ideavimsupport_dialog)
|
||||
&& !ideaVimSupportValue.contains(IjOptionConstants.ideavimsupport_dialoglegacy)
|
||||
}
|
||||
|
||||
private val Editor.disabledInDialog: Boolean
|
||||
get() {
|
||||
val ideaVimSupportValue = injector.globalIjOptions().ideavimsupport
|
||||
return (
|
||||
!ideaVimSupportValue.contains(IjOptionConstants.ideavimsupport_dialog) &&
|
||||
!ideaVimSupportValue.contains(IjOptionConstants.ideavimsupport_dialoglegacy)
|
||||
) &&
|
||||
(!this.isPrimaryEditor() && !EditorHelper.isFileEditor(this))
|
||||
}
|
||||
private fun ideaVimDisabledForSingleLine(ideaVimSupportValue: StringListOptionValue): Boolean {
|
||||
return !ideaVimSupportValue.contains(IjOptionConstants.ideavimsupport_singleline)
|
||||
}
|
||||
|
||||
private fun Editor.isInDialog(): Boolean {
|
||||
return !this.isPrimaryEditor() && !EditorHelper.isFileEditor(this)
|
||||
}
|
||||
|
||||
private fun Editor.isSingleLine(): Boolean {
|
||||
return isTableCellEditor(this.component) || isOneLineMode
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the editor is a primary editor in the main editing area.
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user