mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-17 16:31:45 +02:00
Compare commits
13 Commits
customized
...
customized
Author | SHA1 | Date | |
---|---|---|---|
0c3544c1fe
|
|||
29813f12fb
|
|||
0bb5739adc
|
|||
4e5e94cd98
|
|||
8b6925e5e4
|
|||
e451ebf361
|
|||
056d704297
|
|||
dbb0f79113
|
|||
1bc6dfac1c
|
|||
de449adcb9
|
|||
2ef9742b71
|
|||
a2833aa088
|
|||
13ebac83c6
|
87
.github/workflows/runUiOctopusTests.yml
vendored
87
.github/workflows/runUiOctopusTests.yml
vendored
@@ -1,87 +0,0 @@
|
||||
name: Run Non Octopus UI Tests
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 12 * * *'
|
||||
jobs:
|
||||
build-for-ui-test-mac-os:
|
||||
if: github.repository == 'JetBrains/ideavim'
|
||||
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 }}
|
||||
- name: Setup Gradle
|
||||
uses: gradle/gradle-build-action@v2.4.2
|
||||
- name: Build Plugin
|
||||
run: gradle :buildPlugin
|
||||
- name: Run Idea
|
||||
run: |
|
||||
mkdir -p build/reports
|
||||
gradle runIdeForUiTests > build/reports/idea.log &
|
||||
- name: Wait for Idea started
|
||||
uses: jtalk/url-health-check-action@v3
|
||||
with:
|
||||
url: http://127.0.0.1:8082
|
||||
max-attempts: 20
|
||||
retry-delay: 10s
|
||||
- name: Tests
|
||||
run: gradle :tests:ui-ij-tests:testUi
|
||||
- name: Move video
|
||||
if: always()
|
||||
run: mv tests/ui-ij-tests/video build/reports
|
||||
- name: Move sandbox logs
|
||||
if: always()
|
||||
run: mv build/idea-sandbox/system/log sandbox-idea-log
|
||||
- name: Save report
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ui-test-fails-report-mac
|
||||
path: |
|
||||
build/reports
|
||||
sandbox-idea-log
|
||||
# build-for-ui-test-linux:
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - uses: actions/checkout@v2
|
||||
# - name: Setup Java
|
||||
# uses: actions/setup-java@v2.1.0
|
||||
# with:
|
||||
# distribution: zulu
|
||||
# java-version: 11
|
||||
# - name: Build Plugin
|
||||
# run: gradle :buildPlugin
|
||||
# - name: Run Idea
|
||||
# run: |
|
||||
# export DISPLAY=:99.0
|
||||
# Xvfb -ac :99 -screen 0 1920x1080x16 &
|
||||
# mkdir -p build/reports
|
||||
# gradle :runIdeForUiTests #> build/reports/idea.log
|
||||
# - name: Wait for Idea started
|
||||
# uses: jtalk/url-health-check-action@1.5
|
||||
# with:
|
||||
# url: http://127.0.0.1:8082
|
||||
# max-attempts: 15
|
||||
# retry-delay: 30s
|
||||
# - name: Tests
|
||||
# run: gradle :testUi
|
||||
# - name: Save fails report
|
||||
# if: ${{ failure() }}
|
||||
# uses: actions/upload-artifact@v2
|
||||
# with:
|
||||
# name: ui-test-fails-report-linux
|
||||
# path: |
|
||||
# ui-test-example/build/reports
|
55
.github/workflows/runUiPyTests.yml
vendored
55
.github/workflows/runUiPyTests.yml
vendored
@@ -1,55 +0,0 @@
|
||||
name: Run UI PyCharm Tests
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 12 * * *'
|
||||
jobs:
|
||||
build-for-ui-test-mac-os:
|
||||
if: github.repository == 'JetBrains/ideavim'
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: zulu
|
||||
java-version: 17
|
||||
- uses: actions/setup-python@v5
|
||||
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 }}
|
||||
- name: Setup Gradle
|
||||
uses: gradle/gradle-build-action@v2.4.2
|
||||
- name: Build Plugin
|
||||
run: gradle :buildPlugin
|
||||
- name: Run Idea
|
||||
run: |
|
||||
mkdir -p build/reports
|
||||
gradle :runIdeForUiTests -PideaType=PC > build/reports/idea.log &
|
||||
- name: Wait for Idea started
|
||||
uses: jtalk/url-health-check-action@v3
|
||||
with:
|
||||
url: http://127.0.0.1:8082
|
||||
max-attempts: 20
|
||||
retry-delay: 10s
|
||||
- name: Tests
|
||||
run: gradle :tests:ui-py-tests:testUi
|
||||
- name: Move video
|
||||
if: always()
|
||||
run: mv tests/ui-py-tests/video build/reports
|
||||
- name: Move sandbox logs
|
||||
if: always()
|
||||
run: mv build/idea-sandbox/system/log sandbox-idea-log
|
||||
- name: Save report
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ui-test-fails-report-mac
|
||||
path: |
|
||||
build/reports
|
||||
sandbox-idea-log
|
32
.github/workflows/runUiTests.yml
vendored
32
.github/workflows/runUiTests.yml
vendored
@@ -8,48 +8,42 @@ jobs:
|
||||
if: github.repository == 'JetBrains/ideavim'
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v2
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v2.1.0
|
||||
with:
|
||||
distribution: zulu
|
||||
java-version: 17
|
||||
java-version: 11
|
||||
- name: Setup FFmpeg
|
||||
uses: FedericoCarboni/setup-ffmpeg@v3
|
||||
uses: FedericoCarboni/setup-ffmpeg@v1
|
||||
with:
|
||||
# Not strictly necessary, but it may prevent rate limit
|
||||
# errors especially on GitHub-hosted macos machines.
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Setup Gradle
|
||||
uses: gradle/gradle-build-action@v2.4.2
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Build Plugin
|
||||
run: gradle :buildPlugin
|
||||
- name: Run Idea
|
||||
run: |
|
||||
mkdir -p build/reports
|
||||
gradle runIdeForUiTests > build/reports/idea.log &
|
||||
gradle :runIdeForUiTests > build/reports/idea.log &
|
||||
- name: Wait for Idea started
|
||||
uses: jtalk/url-health-check-action@v3
|
||||
uses: jtalk/url-health-check-action@1.5
|
||||
with:
|
||||
url: http://127.0.0.1:8082
|
||||
max-attempts: 20
|
||||
retry-delay: 10s
|
||||
- name: Tests
|
||||
run: gradle :tests:ui-ij-tests:testUi
|
||||
run: gradle :testUi
|
||||
- name: Move video
|
||||
if: always()
|
||||
run: mv tests/ui-ij-tests/video build/reports
|
||||
- name: Move sandbox logs
|
||||
if: always()
|
||||
run: mv build/idea-sandbox/system/log sandbox-idea-log
|
||||
- name: Save report
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
if: ${{ failure() }}
|
||||
run: mv video build/reports
|
||||
- name: Save fails report
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: ui-test-fails-report-mac
|
||||
path: |
|
||||
build/reports
|
||||
sandbox-idea-log
|
||||
# build-for-ui-test-linux:
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -23,7 +23,6 @@
|
||||
|
||||
# Generated by gradle task "generateGrammarSource"
|
||||
src/main/java/com/maddyhome/idea/vim/vimscript/parser/generated
|
||||
vim-engine/src/main/java/com/maddyhome/idea/vim/regexp/parser/generated
|
||||
# Generated JSONs for lazy classloading
|
||||
/vim-engine/src/main/resources/ksp-generated
|
||||
/src/main/resources/ksp-generated
|
||||
|
2
.idea/copyright/IdeaVim.xml
generated
2
.idea/copyright/IdeaVim.xml
generated
@@ -1,6 +1,6 @@
|
||||
<component name="CopyrightManager">
|
||||
<copyright>
|
||||
<option name="notice" value="Copyright 2003-&#36;today.year 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." />
|
||||
<option name="notice" value="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." />
|
||||
<option name="myName" value="IdeaVim" />
|
||||
</copyright>
|
||||
</component>
|
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 = "2023.1.2"
|
||||
const val NVIM_TESTS = "2023.1.2"
|
||||
const val PROPERTY_TESTS = "2023.1.2"
|
||||
const val LONG_RUNNING_TESTS = "2023.1.2"
|
||||
const val QODANA_TESTS = "2023.1.2"
|
||||
const val RELEASE = "2023.1.2"
|
||||
|
||||
const val RELEASE_DEV = "2023.3.2"
|
||||
const val RELEASE_EAP = "2023.3.2"
|
||||
const val RELEASE_DEV = "2023.1.2"
|
||||
const val RELEASE_EAP = "2023.1.2"
|
||||
}
|
||||
|
10
.teamcity/_Self/Project.kt
vendored
10
.teamcity/_Self/Project.kt
vendored
@@ -15,7 +15,7 @@ import jetbrains.buildServer.configs.kotlin.v2019_2.BuildType
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.Project
|
||||
|
||||
object Project : Project({
|
||||
description = "Vim engine for JetBrains IDEs"
|
||||
description = "Vim engine for IDEs based on the IntelliJ platform"
|
||||
|
||||
subProjects(Releases, OldTests, GitHub)
|
||||
|
||||
@@ -23,8 +23,9 @@ object Project : Project({
|
||||
vcsRoot(GitHubPullRequest)
|
||||
|
||||
// Active tests
|
||||
buildType(TestingBuildType("2023.2", "<default>", version = "2023.2.3"))
|
||||
buildType(TestingBuildType("2023.1", "<default>", version = "2023.1.5"))
|
||||
buildType(TestingBuildType("Latest EAP", "<default>", version = "LATEST-EAP-SNAPSHOT"))
|
||||
buildType(TestingBuildType("2023.3", "<default>", version = "2023.3"))
|
||||
buildType(TestingBuildType("Latest EAP With Xorg", "<default>", version = "LATEST-EAP-SNAPSHOT"))
|
||||
|
||||
buildType(PropertyBased)
|
||||
@@ -39,11 +40,6 @@ object Project : Project({
|
||||
|
||||
// Common build type for all configurations
|
||||
abstract class IdeaVimBuildType(init: BuildType.() -> Unit) : BuildType({
|
||||
artifactRules = """
|
||||
+:build/reports => build/reports
|
||||
+:/mnt/agent/temp/buildTmp/ => /mnt/agent/temp/buildTmp/
|
||||
""".trimIndent()
|
||||
|
||||
init()
|
||||
|
||||
requirements {
|
||||
|
1
.teamcity/_Self/buildTypes/Compatibility.kt
vendored
1
.teamcity/_Self/buildTypes/Compatibility.kt
vendored
@@ -34,6 +34,7 @@ object Compatibility : IdeaVimBuildType({
|
||||
|
||||
java --version
|
||||
java -jar verifier1/verifier-cli-dev-all-1.jar check-plugin '${'$'}org.jetbrains.IdeaVim-EasyMotion' [latest-IU] -team-city
|
||||
java -jar verifier1/verifier-cli-dev-all-1.jar check-plugin '${'$'}io.github.mishkun.ideavimsneak' [latest-IU] -team-city
|
||||
java -jar verifier1/verifier-cli-dev-all-1.jar check-plugin '${'$'}eu.theblob42.idea.whichkey' [latest-IU] -team-city
|
||||
java -jar verifier1/verifier-cli-dev-all-1.jar check-plugin '${'$'}IdeaVimExtension' [latest-IU] -team-city
|
||||
# Outdated java -jar verifier/verifier-cli-dev-all.jar check-plugin '${'$'}github.zgqq.intellij-enhance' [latest-IU] -team-city
|
||||
|
2
.teamcity/_Self/buildTypes/LongRunning.kt
vendored
2
.teamcity/_Self/buildTypes/LongRunning.kt
vendored
@@ -25,7 +25,7 @@ object LongRunning : IdeaVimBuildType({
|
||||
|
||||
steps {
|
||||
gradle {
|
||||
tasks = "clean :tests:long-running-tests:testLongRunning"
|
||||
tasks = "clean testLongRunning"
|
||||
buildFile = ""
|
||||
enableStacktrace = true
|
||||
}
|
||||
|
2
.teamcity/_Self/buildTypes/Nvim.kt
vendored
2
.teamcity/_Self/buildTypes/Nvim.kt
vendored
@@ -39,7 +39,7 @@ object Nvim : IdeaVimBuildType({
|
||||
""".trimIndent()
|
||||
}
|
||||
gradle {
|
||||
tasks = "clean test -Dnvim"
|
||||
tasks = "clean testWithNeovim"
|
||||
buildFile = ""
|
||||
enableStacktrace = true
|
||||
}
|
||||
|
2
.teamcity/_Self/buildTypes/PropertyBased.kt
vendored
2
.teamcity/_Self/buildTypes/PropertyBased.kt
vendored
@@ -24,7 +24,7 @@ object PropertyBased : IdeaVimBuildType({
|
||||
|
||||
steps {
|
||||
gradle {
|
||||
tasks = "clean :tests:property-tests:testPropertyBased"
|
||||
tasks = "clean testPropertyBased"
|
||||
buildFile = ""
|
||||
enableStacktrace = true
|
||||
}
|
||||
|
@@ -20,8 +20,8 @@ object PublishVimEngine : IdeaVimBuildType({
|
||||
params {
|
||||
param("env.ORG_GRADLE_PROJECT_engineVersion", "%build.number%")
|
||||
param("env.ORG_GRADLE_PROJECT_uploadUrl", "https://packages.jetbrains.team/maven/p/ij/intellij-dependencies")
|
||||
password("env.ORG_GRADLE_PROJECT_spacePassword", "credentialsJSON:5ea56f8c-efe7-4e1e-83de-0c02bcc39d0b", display = ParameterDisplay.HIDDEN)
|
||||
param("env.ORG_GRADLE_PROJECT_spaceUsername", "a121c67e-39ac-40e6-bf82-649855ec27b6")
|
||||
password("env.ORG_GRADLE_PROJECT_spacePassword", "credentialsJSON:790b4e43-ee83-4184-b81b-678afab60409", display = ParameterDisplay.HIDDEN)
|
||||
param("env.ORG_GRADLE_PROJECT_spaceUsername", "Aleksei.Plate")
|
||||
}
|
||||
|
||||
vcs {
|
||||
|
20
.teamcity/_Self/buildTypes/ReleaseEap.kt
vendored
20
.teamcity/_Self/buildTypes/ReleaseEap.kt
vendored
@@ -5,7 +5,6 @@ import _Self.Constants.RELEASE_EAP
|
||||
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.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
|
||||
@@ -31,11 +30,6 @@ object ReleaseEap : IdeaVimBuildType({
|
||||
"credentialsJSON:a8ab8150-e6f8-4eaf-987c-bcd65eac50b5",
|
||||
label = "Slack Token"
|
||||
)
|
||||
password(
|
||||
"env.YOUTRACK_TOKEN",
|
||||
"credentialsJSON:2479995b-7b60-4fbb-b095-f0bafae7f622",
|
||||
display = ParameterDisplay.HIDDEN
|
||||
)
|
||||
}
|
||||
|
||||
vcs {
|
||||
@@ -67,26 +61,26 @@ object ReleaseEap : IdeaVimBuildType({
|
||||
tasks = "scripts:addReleaseTag"
|
||||
}
|
||||
gradle {
|
||||
name = "Publish plugin"
|
||||
tasks = "publishPlugin"
|
||||
}
|
||||
// Same as the script below. However, jgit can't find ssh keys on TeamCity
|
||||
// gradle {
|
||||
// name = "Push changes to the repo"
|
||||
// tasks = "scripts:pushChanges"
|
||||
// }
|
||||
script {
|
||||
name = "Push changes to the repo"
|
||||
scriptContent = """
|
||||
branch=$(git branch --show-current)
|
||||
branch=$(git branch --show-current)
|
||||
echo current branch is ${'$'}branch
|
||||
if [ "master" != "${'$'}branch" ];
|
||||
then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
git push origin %build.number%
|
||||
""".trimIndent()
|
||||
}
|
||||
gradle {
|
||||
name = "YouTrack post release actions"
|
||||
tasks = "scripts:eapReleaseActions"
|
||||
}
|
||||
}
|
||||
|
||||
features {
|
||||
|
72
.teamcity/_Self/buildTypes/ReleasePlugin.kt
vendored
72
.teamcity/_Self/buildTypes/ReleasePlugin.kt
vendored
@@ -45,11 +45,7 @@ sealed class ReleasePlugin(private val releaseType: String) : IdeaVimBuildType({
|
||||
"credentialsJSON:a8ab8150-e6f8-4eaf-987c-bcd65eac50b5",
|
||||
label = "Slack Token"
|
||||
)
|
||||
password(
|
||||
"env.ORG_GRADLE_PROJECT_youtrackToken",
|
||||
"credentialsJSON:7bc0eb3a-b86a-4ebd-b622-d4ef12d7e1d3",
|
||||
display = ParameterDisplay.HIDDEN
|
||||
)
|
||||
password("env.ORG_GRADLE_PROJECT_youtrackToken", "credentialsJSON:3cd3e867-282c-451f-b958-bc95d56a8450", display = ParameterDisplay.HIDDEN)
|
||||
param("env.ORG_GRADLE_PROJECT_releaseType", releaseType)
|
||||
}
|
||||
|
||||
@@ -69,25 +65,9 @@ sealed class ReleasePlugin(private val releaseType: String) : IdeaVimBuildType({
|
||||
name = "Pull git history"
|
||||
scriptContent = "git fetch --unshallow"
|
||||
}
|
||||
script {
|
||||
name = "Reset release branch"
|
||||
scriptContent = """
|
||||
if [ "major" = "$releaseType" ] || [ "minor" = "$releaseType" ]
|
||||
then
|
||||
echo Resetting the release branch because the release type is $releaseType
|
||||
git checkout master
|
||||
latest_eap=${'$'}(git describe --tags --match="[0-9].[0-9]*.[0-9]-eap.[0-9]*" --abbrev=0 HEAD)
|
||||
echo Latest EAP: ${'$'}latest_eap
|
||||
commit_of_latest_eap=${'$'}(git rev-list -n 1 ${'$'}latest_eap)
|
||||
echo Commit of latest EAP: ${'$'}commit_of_latest_eap
|
||||
git checkout release
|
||||
git reset --hard ${'$'}commit_of_latest_eap
|
||||
else
|
||||
git checkout release
|
||||
echo Do not reset the release branch because the release type is $releaseType
|
||||
fi
|
||||
echo Checked out release branch
|
||||
""".trimIndent()
|
||||
gradle {
|
||||
name = "Select branch"
|
||||
tasks = "scripts:selectBranch"
|
||||
}
|
||||
gradle {
|
||||
name = "Calculate new version"
|
||||
@@ -109,47 +89,41 @@ sealed class ReleasePlugin(private val releaseType: String) : IdeaVimBuildType({
|
||||
name = "Add release tag"
|
||||
tasks = "scripts:addReleaseTag"
|
||||
}
|
||||
script {
|
||||
name = "Run tests"
|
||||
scriptContent = "./gradlew test"
|
||||
gradle {
|
||||
name = "Reset release branch"
|
||||
tasks = "scripts:resetReleaseBranch"
|
||||
}
|
||||
gradle {
|
||||
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"
|
||||
}
|
||||
// gradle {
|
||||
// name = "Push changes to the repo"
|
||||
// tasks = "scripts:pushChangesWithReleaseBranch"
|
||||
// }
|
||||
script {
|
||||
name = "Push changes to the repo"
|
||||
scriptContent = """
|
||||
branch=$(git branch --show-current)
|
||||
echo Current branch is ${'$'}branch
|
||||
echo current branch is ${'$'}branch
|
||||
if [ "master" != "${'$'}branch" ];
|
||||
then
|
||||
git checkout master
|
||||
fi
|
||||
|
||||
git push origin --tags
|
||||
git push origin
|
||||
|
||||
git checkout release
|
||||
echo checkout release branch
|
||||
git branch --set-upstream-to=origin/release release
|
||||
git push origin --force
|
||||
# Push tag
|
||||
git push origin %build.number%
|
||||
if [ "patch" != $releaseType ];
|
||||
then
|
||||
git checkout release
|
||||
echo checkout release branch
|
||||
git branch --set-upstream-to=origin/release release
|
||||
git push --tags
|
||||
git push origin --force
|
||||
fi
|
||||
|
||||
git checkout ${'$'}branch
|
||||
""".trimIndent()
|
||||
}
|
||||
gradle {
|
||||
|
2
.teamcity/_Self/subprojects/OldTests.kt
vendored
2
.teamcity/_Self/subprojects/OldTests.kt
vendored
@@ -20,6 +20,4 @@ object OldTests : Project({
|
||||
buildType(TestingBuildType("IC-2021.2.2", "203-212", javaVersion = "1.8", javaPlugin = false))
|
||||
buildType(TestingBuildType("IC-2021.3.2", "213-221", javaVersion = "1.8", javaPlugin = false))
|
||||
buildType(TestingBuildType("IC-2022.2.3", branch = "222", javaPlugin = false))
|
||||
buildType(TestingBuildType("IC-2023.1", "231-232", javaPlugin = false))
|
||||
buildType(TestingBuildType("IC-2023.2", "231-232", javaPlugin = false))
|
||||
})
|
||||
|
@@ -1,29 +0,0 @@
|
||||
package patches.buildTypes
|
||||
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.RelativeId
|
||||
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
|
||||
|
||||
/*
|
||||
This patch script was generated by TeamCity on settings change in UI.
|
||||
To apply the patch, change the buildType with id = 'IdeaVimTests_Latest_EAP'
|
||||
accordingly, and delete the patch script.
|
||||
*/
|
||||
changeBuildType(RelativeId("IdeaVimTests_Latest_EAP")) {
|
||||
expectSteps {
|
||||
gradle {
|
||||
tasks = "clean test"
|
||||
buildFile = ""
|
||||
enableStacktrace = true
|
||||
}
|
||||
}
|
||||
steps {
|
||||
update<GradleBuildStep>(0) {
|
||||
clearConditions()
|
||||
jdkHome = "/usr/lib/jvm/java-17-amazon-corretto"
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,19 +0,0 @@
|
||||
package patches.buildTypes
|
||||
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.*
|
||||
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'
|
||||
accordingly, and delete the patch script.
|
||||
*/
|
||||
changeBuildType(RelativeId("PublishVimEngine")) {
|
||||
vcs {
|
||||
|
||||
check(branchFilter == "+:<default>") {
|
||||
"Unexpected option value: branchFilter = $branchFilter"
|
||||
}
|
||||
branchFilter = "+:fleet"
|
||||
}
|
||||
}
|
20
.teamcity/patches/buildTypes/ReleaseMinor.kts
vendored
Normal file
20
.teamcity/patches/buildTypes/ReleaseMinor.kts
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
package patches.buildTypes
|
||||
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.*
|
||||
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 = 'ReleaseMinor'
|
||||
accordingly, and delete the patch script.
|
||||
*/
|
||||
changeBuildType(RelativeId("ReleaseMinor")) {
|
||||
params {
|
||||
expect {
|
||||
password("env.ORG_GRADLE_PROJECT_youtrackToken", "credentialsJSON:3cd3e867-282c-451f-b958-bc95d56a8450", display = ParameterDisplay.HIDDEN)
|
||||
}
|
||||
update {
|
||||
password("env.ORG_GRADLE_PROJECT_youtrackToken", "credentialsJSON:7bc0eb3a-b86a-4ebd-b622-d4ef12d7e1d3", display = ParameterDisplay.HIDDEN)
|
||||
}
|
||||
}
|
||||
}
|
20
.teamcity/patches/buildTypes/ReleasePatch.kts
vendored
Normal file
20
.teamcity/patches/buildTypes/ReleasePatch.kts
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
package patches.buildTypes
|
||||
|
||||
import jetbrains.buildServer.configs.kotlin.v2019_2.*
|
||||
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 = 'ReleasePatch'
|
||||
accordingly, and delete the patch script.
|
||||
*/
|
||||
changeBuildType(RelativeId("ReleasePatch")) {
|
||||
params {
|
||||
expect {
|
||||
password("env.ORG_GRADLE_PROJECT_youtrackToken", "credentialsJSON:3cd3e867-282c-451f-b958-bc95d56a8450", display = ParameterDisplay.HIDDEN)
|
||||
}
|
||||
update {
|
||||
password("env.ORG_GRADLE_PROJECT_youtrackToken", "credentialsJSON:7bc0eb3a-b86a-4ebd-b622-d4ef12d7e1d3", display = ParameterDisplay.HIDDEN)
|
||||
}
|
||||
}
|
||||
}
|
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 = "2023.05"
|
||||
project(_Self.Project)
|
||||
|
@@ -487,14 +487,6 @@ Contributors:
|
||||
[![icon][github]](https://github.com/pWydmuch)
|
||||
|
||||
pWydmuch
|
||||
* [![icon][mail]](mailto:leonid989@gmail.com)
|
||||
[![icon][github]](https://github.com/Infonautica)
|
||||
|
||||
Leonid Danilov
|
||||
* [![icon][mail]](mailto:emanuel-367@hotmail.com)
|
||||
[![icon][github]](https://github.com/emanuelgestosa)
|
||||
|
||||
Emanuel Gestosa
|
||||
|
||||
Previous contributors:
|
||||
|
||||
|
33
CHANGES.md
33
CHANGES.md
@@ -25,45 +25,12 @@ usual beta standards.
|
||||
|
||||
## To Be Released
|
||||
|
||||
### 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
|
||||
|
||||
### Fixes:
|
||||
* [VIM-3130](https://youtrack.jetbrains.com/issue/VIM-3130) Change the build version to 2023.1.2
|
||||
* [VIM-3168](https://youtrack.jetbrains.com/issue/VIM-3168) Do not switch to block caret after enter if the IdeaVim is disabled
|
||||
* [VIM-3165](https://youtrack.jetbrains.com/issue/VIM-3165) Do not process enter key as IdeaVim shortcut if it's not an actual keypress
|
||||
* [VIM-3159](https://youtrack.jetbrains.com/issue/VIM-3159) Shift-enter now works in normal mode again
|
||||
* [VIM-3157](https://youtrack.jetbrains.com/issue/VIM-3157) Do not invoke enter in invokeLater for python console
|
||||
* [VIM-3195](https://youtrack.jetbrains.com/issue/VIM-3195) Fix escape in injected editor
|
||||
* [VIM-3190](https://youtrack.jetbrains.com/issue/VIM-3190) Do not use octopus handler if the enter key is used with modifiers like shift or control
|
||||
* [VIM-3203](https://youtrack.jetbrains.com/issue/VIM-3203) Split action not works in normal mode
|
||||
* [VIM-3184](https://youtrack.jetbrains.com/issue/VIM-3184) Revert "VIM-3184: Temporally disable new handlers for the thin client"
|
||||
* [VIM-3186](https://youtrack.jetbrains.com/issue/VIM-3186) Do not multiply the enter action by the amount of carets
|
||||
* [VIM-3177](https://youtrack.jetbrains.com/issue/VIM-3177) Formatting of commit message works again
|
||||
* [VIM-1611](https://youtrack.jetbrains.com/issue/VIM-1611) actions related to resolving conflicts doesn't seem to work
|
||||
* [VIM-3204](https://youtrack.jetbrains.com/issue/VIM-3204) Add checker that verifies the configuratin of the keymap
|
||||
* [VIM-3084](https://youtrack.jetbrains.com/issue/VIM-3084) Double update for the status bar icon
|
||||
* [VIM-3176](https://youtrack.jetbrains.com/issue/VIM-3176) Reselecting visual selection after pasting above it select wrong lines
|
||||
* [VIM-3206](https://youtrack.jetbrains.com/issue/VIM-3206) Disable both copilot suggestion and insert mode on a single escape
|
||||
* [VIM-3090](https://youtrack.jetbrains.com/issue/VIM-3090) Cmd line mode saves the visual mode
|
||||
* [VIM-3085](https://youtrack.jetbrains.com/issue/VIM-3085) Open access to VimTypedActionHandler and VimShortcutKeyAction
|
||||
* [VIM-3260](https://youtrack.jetbrains.com/issue/VIM-3260) Processing the offsets at the file end
|
||||
* [VIM-3183](https://youtrack.jetbrains.com/issue/VIM-3183) Execute .ideavimrc on pooled thread
|
||||
|
||||
### Merged PRs:
|
||||
* [763](https://github.com/JetBrains/ideavim/pull/763) by [Sam Ng](https://github.com/samabcde): Fix(VIM-3176) add test for restore selection after pasting in/below s…
|
||||
* [772](https://github.com/JetBrains/ideavim/pull/772) by [chylex](https://github.com/chylex): Prevent code completion popup from appearing after running a macro
|
||||
* [787](https://github.com/JetBrains/ideavim/pull/787) by [Leonid Danilov](https://github.com/Infonautica): Added "Which-Key" to Plugins
|
||||
* [778](https://github.com/JetBrains/ideavim/pull/778) by [lippfi](https://github.com/lippfi): Showmode
|
||||
* [788](https://github.com/JetBrains/ideavim/pull/788) by [Matt Ellis](https://github.com/citizenmatt): Refactor VimOptionGroupBase
|
||||
|
||||
## 2.7.0, 2023-11-07
|
||||
|
||||
|
@@ -324,7 +324,7 @@ IdeaVim tips and tricks
|
||||
- Use the power of IJ and Vim:
|
||||
- `set ideajoin` to enable join via the IDE. See the [examples](https://jb.gg/f9zji9).
|
||||
- Make sure `ideaput` is enabled for `clipboard` to enable native IJ insertion in Vim.
|
||||
- Sync IJ bookmarks and IdeaVim global marks: `set ideamarks` (works for marks with capital letters only)
|
||||
- Sync IJ bookmarks and Vim marks: `set ideamarks`
|
||||
- Check out more [ex commands](https://github.com/JetBrains/ideavim/wiki/%22set%22-commands).
|
||||
|
||||
- Use your vim settings with IdeaVim. Put `source ~/.vimrc` in `~/.ideavimrc`.
|
||||
|
@@ -84,8 +84,3 @@ IV) It is not allowed to remove this license from the distribution of the Vim
|
||||
license for previous Vim releases instead of the license that they came
|
||||
with, at your option.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
File [sneakIcon.png](doc/images/sneakIcon.svg), which is originally an icon of the ideavim-sneak plugin,
|
||||
is merged icons of IdeaVim plugin and a random sneaker by FreePic from flaticon.com.
|
||||
|
@@ -8,11 +8,9 @@
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
kotlin("plugin.serialization") version "1.9.22"
|
||||
kotlin("plugin.serialization") version "1.8.21"
|
||||
}
|
||||
|
||||
val kotlinxSerializationVersion: String by project
|
||||
|
||||
group = "com.intellij"
|
||||
version = "SNAPSHOT"
|
||||
|
||||
@@ -21,10 +19,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.google.devtools.ksp:symbol-processing-api:1.9.22-1.0.17")
|
||||
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")
|
||||
exclude("org.jetbrains.kotlin", "kotlin-stdlib-common")
|
||||
}
|
||||
compileOnly("com.google.devtools.ksp:symbol-processing-api:1.9.20-1.0.14")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.6.0")
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ enum class Mode(val abbrev: Char) {
|
||||
OP_PENDING('O'),
|
||||
|
||||
/**
|
||||
* Indicates this key mapping applies to Insert or Replace modes
|
||||
* Indicates this key mapping applies to Insert mode
|
||||
*/
|
||||
INSERT('I'),
|
||||
|
||||
|
1349
build.gradle.kts
1349
build.gradle.kts
File diff suppressed because it is too large
Load Diff
@@ -44,21 +44,16 @@ All commands with the mappings are supported. See the [full list of supported co
|
||||
|
||||
<details>
|
||||
<summary><h2>sneak</h2></summary>
|
||||
|
||||
<img src="images/sneakIcon.svg" width="80" height="80" alt="icon"/>
|
||||
|
||||
By [Mikhail Levchenko](https://github.com/Mishkun)
|
||||
Original repository with the plugin: https://github.com/Mishkun/ideavim-sneak
|
||||
|
||||
Original plugin: [vim-sneak](https://github.com/justinmk/vim-sneak).
|
||||
|
||||
### Setup:
|
||||
- Add the following command to `~/.ideavimrc`: `Plug 'justinmk/vim-sneak'`
|
||||
- Install [IdeaVim-sneak](https://plugins.jetbrains.com/plugin/15348-ideavim-sneak) plugin.
|
||||
- Add the following command to `~/.ideavimrc`: `set sneak`
|
||||
|
||||
### Instructions
|
||||
|
||||
* Type `s` and two chars to start sneaking in forward direction
|
||||
* Type `S` and two chars to start sneaking in backward direction
|
||||
* Type `;` or `,` to proceed with sneaking just as if you were using `f` or `t` commands
|
||||
|
||||
See the [docs](https://github.com/Mishkun/ideavim-sneak#usage)
|
||||
|
||||
</details>
|
||||
|
||||
@@ -401,19 +396,3 @@ Original plugin: [quick-scope](https://github.com/unblevable/quick-scope).
|
||||
https://plugins.jetbrains.com/plugin/19417-ideavim-quickscope
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
<details>
|
||||
<summary><h2>Which-Key</h2></summary>
|
||||
|
||||
Original plugin: [vim-which-key](https://github.com/liuchengxu/vim-which-key).
|
||||
|
||||
### Setup:
|
||||
- Install [Which-Key](https://plugins.jetbrains.com/plugin/15976-which-key) plugin.
|
||||
- Add the following command to `~/.ideavimrc`: `set which-key`
|
||||
|
||||
### Instructions
|
||||
|
||||
https://github.com/TheBlob42/idea-which-key?tab=readme-ov-file#installation
|
||||
|
||||
</details>
|
||||
|
@@ -3,11 +3,6 @@ Put `set ideajoin` to your `~/.ideavimrc` to enable this functionality.
|
||||
|
||||
Now, you can press `J` (`shift+j`) on a line or a selected block of text to join the lines together.
|
||||
|
||||
:warning: This feature is language-specific. This means that the IDE should implement this feature for a particular
|
||||
language in order for the IDE to work as described below. If any of the examples provided below don't match your case,
|
||||
please file an issue in the project related to your IDE: https://youtrack.jetbrains.com/.
|
||||
Here is a list of known requests: https://youtrack.jetbrains.com/issues?q=links:VIM-3214.
|
||||
|
||||
* Automatic join concatenated lines:
|
||||
|
||||
```
|
||||
|
@@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg viewBox="386.498 234 32 32" xmlns="http://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient id="ideavim_plugin-a" x1="-6.748%" x2="47.286%" y1="33.61%" y2="85.907%">
|
||||
<stop offset="0" stop-color="#3BEA62"/>
|
||||
<stop offset="1" stop-color="#087CFA"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<g transform="matrix(1.238978, 0.90017, -0.90017, 1.238978, 131.776901, -422.953003)" style="">
|
||||
<path d="M 399.962 247.648 C 399.207 246.894 399.147 246.318 399.692 245.453 C 400.237 244.588 401.955 245.886 401.955 245.886 L 401.955 250.737" style="fill: rgb(248, 245, 231);"/>
|
||||
<path d="M 413.846 253.602 C 413.846 255.077 411.827 256.134 409.392 256.134 L 396.381 256.134 C 395.211 256.134 394.232 256.003 393.433 255.817 C 391.496 255.367 390.613 254.596 390.613 254.596 L 391.478 252.513 L 393.607 252.617 Z M 413.846 253.602" fill="#cce6f6" style=""/>
|
||||
<path d="M 413.846 253.602 C 413.846 253.602 411.475 254.468 408.27 254.468 C 405.94 254.468 398.116 253.433 394.023 252.869 C 392.488 252.658 391.478 252.512 391.478 252.512 C 390.864 251.662 392.078 248.741 392.758 247.263 C 393.118 246.484 393.85 245.929 394.703 245.83 C 394.782 245.82 394.861 245.815 394.939 245.815 C 395.369 245.815 395.645 246.532 396.059 247.225 C 396.446 247.877 396.955 248.507 397.823 248.507 C 399.617 248.507 401.955 245.886 401.955 245.886 C 406.544 249.03 410.097 250.43 410.097 250.43 C 410.097 250.43 413.061 250.446 413.782 251.167 C 414.503 251.888 414.422 253.218 413.846 253.602 Z M 413.846 253.602" style="fill: rgb(8, 124, 250);"/>
|
||||
<path d="M 394.023 252.869 L 393.433 255.817 C 391.496 255.367 390.613 254.596 390.613 254.596 L 391.478 252.513 L 393.607 252.617 Z M 394.023 252.869" fill="#9dcae0" style=""/>
|
||||
<path d="M 396.059 247.225 C 395.073 245.986 393.193 250.255 394.023 252.869 C 392.488 252.658 391.478 252.513 391.478 252.513 C 390.864 251.662 392.078 248.741 392.758 247.263 C 393.118 246.484 393.85 245.929 394.703 245.83 C 394.782 245.82 394.861 245.815 394.939 245.815 C 395.369 245.815 395.645 246.532 396.059 247.225 Z M 396.059 247.225" style="fill: rgb(14, 112, 142);"/>
|
||||
<path d="M 403.527 246.924 L 399.174 251.768 C 397.7 250.892 395.578 250.174 394.016 249.717 C 392.843 249.372 391.985 249.174 391.959 249.168 C 392.108 248.769 392.268 248.379 392.421 248.022 L 394.341 248.65 L 394.884 248.827 C 395.509 249.031 396.192 248.95 396.753 248.608 L 397.153 248.363 C 397.35 248.454 397.572 248.507 397.823 248.507 C 399.617 248.507 401.955 245.886 401.955 245.886 C 402.494 246.256 403.02 246.601 403.527 246.924 Z M 403.527 246.924" style="fill: rgb(59, 234, 98);"/>
|
||||
<path d="M 413.847 253.602 C 413.847 253.602 411.475 254.468 408.27 254.468 C 407.586 254.468 406.426 254.378 405.025 254.238 L 405.025 254.237 C 405.025 253.495 406.924 251.743 408.366 251.616 C 408.623 252.865 410.097 252.512 411.219 252.128 C 412.341 251.743 413.783 251.167 413.783 251.167 C 414.503 251.888 414.422 253.218 413.847 253.602 Z M 413.847 253.602" style="fill: rgb(8, 124, 250);"/>
|
||||
<path d="M 394.341 248.65 C 394.214 248.978 394.103 249.339 394.016 249.717 C 392.843 249.372 391.985 249.174 391.959 249.168 C 392.108 248.769 392.268 248.379 392.421 248.022 Z M 394.341 248.65" style="fill: rgb(37, 187, 163);"/>
|
||||
<path d="M 408.366 251.616 C 406.924 251.743 405.025 253.495 405.025 254.237 L 405.025 254.238 C 403.784 254.113 402.355 253.948 400.899 253.77 C 400.899 253.051 400.191 252.372 399.174 251.768 L 399.174 251.768 L 403.528 246.924 C 407.331 249.34 410.097 250.43 410.097 250.43 C 410.77 251.102 409.809 251.487 408.366 251.616 Z M 408.366 251.616" style="fill: rgb(248, 245, 231);"/>
|
||||
<polygon fill="url(#ideavim_plugin-a)" fill-rule="evenodd" points="406.356 248.463 403.261 252.616 402.183 248.212 400.984 249.899 401.999 254.236 403.927 254.176 407.639 249.062" style="" transform="matrix(0.994522, 0.104529, -0.104529, 0.994522, 28.475005, -40.88594)"/>
|
||||
<g fill="#fb6572" transform="matrix(0.046265, 0, 0, 0.046265, 390.612823, 245.155533)" style="">
|
||||
<path d="m288.839844 72.65625c-2.007813 0-4.011719-.761719-5.542969-2.292969-3.058594-3.0625-3.058594-8.023437 0-11.082031l20.089844-20.089844c3.0625-3.058594 8.023437-3.058594 11.082031 0 3.058594 3.0625 3.0625 8.023438 0 11.082032l-20.089844 20.089843c-1.527344 1.53125-3.535156 2.292969-5.539062 2.292969zm0 0" style="fill: rgb(56, 228, 105);"/>
|
||||
<path d="m314.589844 87.082031c-2.007813 0-4.011719-.765625-5.542969-2.296875-3.0625-3.058594-3.0625-8.019531 0-11.082031l20.089844-20.085937c3.0625-3.058594 8.023437-3.058594 11.082031 0 3.058594 3.0625 3.058594 8.023437 0 11.082031l-20.089844 20.085937c-1.527344 1.53125-3.535156 2.296875-5.539062 2.296875zm0 0" style="fill: rgb(59, 233, 100);"/>
|
||||
<path d="m340.339844 101.507812c-2.007813 0-4.011719-.765624-5.542969-2.296874-3.058594-3.058594-3.058594-8.023438 0-11.082032l20.089844-20.085937c3.0625-3.0625 8.023437-3.0625 11.082031 0 3.058594 3.058593 3.0625 8.023437 0 11.082031l-20.089844 20.085938c-1.527344 1.53125-3.535156 2.296874-5.539062 2.296874zm0 0" style="fill: rgb(59, 233, 100);"/>
|
||||
<path d="m366.089844 115.929688c-2.003906 0-4.011719-.761719-5.539063-2.292969-3.0625-3.0625-3.0625-8.023438 0-11.082031l20.085938-20.089844c3.0625-3.058594 8.023437-3.058594 11.082031 0 3.0625 3.0625 3.0625 8.023437 0 11.082031l-20.085938 20.089844c-1.53125 1.53125-3.535156 2.292969-5.542968 2.292969zm0 0" style="fill: rgb(59, 233, 100);"/>
|
||||
</g>
|
||||
<path d="M 401.925 247.748 C 401.761 247.748 401.611 247.629 401.573 247.469 C 401.536 247.312 401.611 247.144 401.753 247.067 C 402 246.933 402.318 247.147 402.286 247.426 C 402.265 247.606 402.107 247.748 401.925 247.748 Z M 401.925 247.748" fill="#1e2628" style=""/>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 5.6 KiB |
@@ -8,28 +8,21 @@
|
||||
|
||||
# suppress inspection "UnusedProperty" for whole file
|
||||
|
||||
ideaVersion=2023.3.3
|
||||
# Values for type: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#intellij-extension-type
|
||||
ideaType=IC
|
||||
ideaVersion=2023.2
|
||||
downloadIdeaSources=true
|
||||
instrumentPluginCode=true
|
||||
version=chylex-28
|
||||
version=chylex-20
|
||||
javaVersion=17
|
||||
remoteRobotVersion=0.11.22
|
||||
remoteRobotVersion=0.11.17
|
||||
antlrVersion=4.10.1
|
||||
|
||||
kotlin.incremental.useClasspathSnapshot=false
|
||||
|
||||
# Please don't forget to update kotlin version in buildscript section
|
||||
# Also update kotlinxSerializationVersion version
|
||||
kotlinVersion=1.9.22
|
||||
kotlinVersion=1.8.21
|
||||
publishToken=token
|
||||
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
|
||||
|
||||
slackUrl=
|
||||
youtrackToken=
|
||||
|
||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,7 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
5
gradlew
vendored
5
gradlew
vendored
@@ -130,13 +130,10 @@ location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
|
@@ -20,17 +20,17 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.9.22")
|
||||
compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.9.20")
|
||||
|
||||
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.6")
|
||||
implementation("io.ktor:ktor-client-cio:2.3.5")
|
||||
implementation("io.ktor:ktor-client-content-negotiation:2.3.6")
|
||||
implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.6")
|
||||
implementation("io.ktor:ktor-client-auth:2.3.6")
|
||||
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.7.0.202309050840-r")
|
||||
implementation("com.vdurmont:semver4j:3.1.0")
|
||||
}
|
||||
|
||||
@@ -93,16 +93,28 @@ tasks.register("addReleaseTag", JavaExec::class) {
|
||||
args = listOf(project.version.toString(), rootProject.rootDir.toString(), releaseType ?: "")
|
||||
}
|
||||
|
||||
tasks.register("selectBranch", JavaExec::class) {
|
||||
tasks.register("resetReleaseBranch", JavaExec::class) {
|
||||
group = "release"
|
||||
mainClass.set("scripts.release.SelectBranchKt")
|
||||
mainClass.set("scripts.release.ResetReleaseBranchKt")
|
||||
classpath = sourceSets["main"].runtimeClasspath
|
||||
args = listOf(project.version.toString(), rootProject.rootDir.toString(), releaseType ?: "")
|
||||
}
|
||||
|
||||
tasks.register("eapReleaseActions", JavaExec::class) {
|
||||
tasks.register("pushChanges", JavaExec::class) {
|
||||
mainClass.set("scripts.PushChangesKt")
|
||||
classpath = sourceSets["main"].runtimeClasspath
|
||||
args = listOf(rootProject.rootDir.toString())
|
||||
}
|
||||
|
||||
tasks.register("pushChangesWithReleaseBranch", JavaExec::class) {
|
||||
mainClass.set("scripts.PushChangesWithReleaseBranchKt")
|
||||
classpath = sourceSets["main"].runtimeClasspath
|
||||
args = listOf(rootProject.rootDir.toString(), releaseType ?: "")
|
||||
}
|
||||
|
||||
tasks.register("selectBranch", JavaExec::class) {
|
||||
group = "release"
|
||||
mainClass.set("scripts.releaseEap.EapReleaseActionsKt")
|
||||
mainClass.set("scripts.release.SelectBranchKt")
|
||||
classpath = sourceSets["main"].runtimeClasspath
|
||||
args = listOf(project.version.toString(), rootProject.rootDir.toString(), releaseType ?: "")
|
||||
}
|
||||
|
@@ -32,7 +32,6 @@ val knownPlugins = listOf(
|
||||
"com.github.dankinsoid.multicursor",
|
||||
"com.joshestein.ideavim-quickscope",
|
||||
"ca.alexgirard.HarpoonIJ",
|
||||
"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
|
||||
)
|
||||
|
@@ -32,7 +32,7 @@ fun httpClient(): HttpClient {
|
||||
install(Auth) {
|
||||
bearer {
|
||||
loadTokens {
|
||||
val accessToken = System.getenv("YOUTRACK_TOKEN") ?: error("Missing YOUTRACK_TOKEN")
|
||||
val accessToken = System.getenv("YOUTRACK_TOKEN")!!
|
||||
BearerTokens(accessToken, "")
|
||||
}
|
||||
}
|
||||
|
37
scripts/src/main/kotlin/scripts/pushChanges.kt
Normal file
37
scripts/src/main/kotlin/scripts/pushChanges.kt
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 scripts.release.checkoutBranch
|
||||
import scripts.release.withGit
|
||||
import scripts.release.withRepo
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val rootDir = args[0]
|
||||
println("root dir: $rootDir")
|
||||
|
||||
val currentBranch = withRepo(rootDir) { it.branch }
|
||||
println("Current branch is $currentBranch")
|
||||
|
||||
|
||||
withGit(rootDir) { git ->
|
||||
if (currentBranch != "master") {
|
||||
git.checkoutBranch("master")
|
||||
println("Check out master branch")
|
||||
}
|
||||
|
||||
git.push()
|
||||
.setPushTags()
|
||||
.call()
|
||||
println("Master pushed with tags")
|
||||
|
||||
git.checkoutBranch(currentBranch)
|
||||
println("Checked out $currentBranch branch")
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 scripts.release.checkoutBranch
|
||||
import scripts.release.withGit
|
||||
import scripts.release.withRepo
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val rootDir = args[0]
|
||||
val releaseType = args[1]
|
||||
println("root dir: $rootDir")
|
||||
println("releaseType: $releaseType")
|
||||
|
||||
val currentBranch = withRepo(rootDir) { it.branch }
|
||||
println("Current branch is $currentBranch")
|
||||
|
||||
|
||||
withGit(rootDir) { git ->
|
||||
if (currentBranch != "master") {
|
||||
git.checkoutBranch("master")
|
||||
println("Check out master branch")
|
||||
}
|
||||
|
||||
git.push()
|
||||
.setPushTags()
|
||||
.call()
|
||||
println("Master pushed with tags")
|
||||
|
||||
if (releaseType != "patch") {
|
||||
git.checkoutBranch("release")
|
||||
println("Checked out release")
|
||||
|
||||
git
|
||||
.push()
|
||||
.setForce(true)
|
||||
.setPushTags()
|
||||
.call()
|
||||
println("Pushed release branch with tags")
|
||||
}
|
||||
else {
|
||||
println("Do not push release branch because type of release is $releaseType")
|
||||
}
|
||||
|
||||
git.checkoutBranch(currentBranch)
|
||||
println("Checked out $currentBranch branch")
|
||||
}
|
||||
}
|
@@ -12,7 +12,7 @@ fun main(args: Array<String>) {
|
||||
println("HI!")
|
||||
val projectDir = args[0]
|
||||
println("Working directory: $projectDir")
|
||||
val (lastVersion, objectId) = getVersion(projectDir, ReleaseType.STABLE_NO_PATCH)
|
||||
val (lastVersion, objectId) = getVersion(projectDir, onlyStable = true)
|
||||
println("Last version: $lastVersion, hash: ${objectId.name}")
|
||||
|
||||
val branch = withRepo(projectDir) { it.branch }
|
||||
|
@@ -12,7 +12,7 @@ fun main(args: Array<String>) {
|
||||
println("HI!")
|
||||
val projectDir = args[0]
|
||||
println("Working directory: $projectDir")
|
||||
val (lastVersion, _) = getVersion(projectDir, ReleaseType.ANY)
|
||||
val (lastVersion, _) = getVersion(projectDir, onlyStable = false)
|
||||
|
||||
val nextVersion = if (lastVersion.suffixTokens.isEmpty()) {
|
||||
lastVersion.nextMinor().withSuffix("eap.1").value
|
||||
|
@@ -14,7 +14,7 @@ fun main(args: Array<String>) {
|
||||
val releaseType = args[1]
|
||||
println("Working directory: $projectDir")
|
||||
println("Release type: $releaseType")
|
||||
val (lastVersion, _) = getVersion(projectDir, ReleaseType.ONLY_STABLE)
|
||||
val (lastVersion, _) = getVersion(projectDir, onlyStable = true)
|
||||
|
||||
val nextVersion = when (releaseType) {
|
||||
"major" -> lastVersion.nextMajor()
|
||||
|
@@ -8,45 +8,28 @@
|
||||
|
||||
package scripts.release
|
||||
|
||||
import com.vdurmont.semver4j.Semver
|
||||
import java.time.LocalDate
|
||||
import java.time.format.DateTimeFormatter
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.readText
|
||||
import kotlin.io.path.writeText
|
||||
|
||||
private const val toBeReleased = "## To Be Released"
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println("Start updating unreleased section")
|
||||
val (newVersion, rootDir, releaseType) = readArgs(args)
|
||||
|
||||
checkReleaseType(releaseType)
|
||||
|
||||
if (releaseType == "patch") {
|
||||
println("Skip updating the changelog because release type is 'patch'")
|
||||
return
|
||||
}
|
||||
|
||||
val currentDate = LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE)
|
||||
val newItem = "## $newVersion, $currentDate"
|
||||
|
||||
val changelogPath = Path("$rootDir/CHANGES.md")
|
||||
val changelog = changelogPath.readText()
|
||||
val newChangelog = if (releaseType == "patch") {
|
||||
val decreasedVersion = Semver(newVersion).withIncPatch(-1)
|
||||
val firstEntry = changelog.indexOf("## $decreasedVersion")
|
||||
if (firstEntry != -1) {
|
||||
val newLog = StringBuilder(changelog)
|
||||
newLog.insert(firstEntry, newItem + "\n")
|
||||
newLog.toString()
|
||||
} else {
|
||||
changelog
|
||||
}
|
||||
} else {
|
||||
if (toBeReleased in changelog) {
|
||||
changelog.replace(toBeReleased, newItem)
|
||||
} else {
|
||||
val firstEntry = changelog.indexOf("##")
|
||||
val newLog = StringBuilder(changelog)
|
||||
newLog.insert(firstEntry, newItem + "\n")
|
||||
newLog.toString()
|
||||
}
|
||||
}
|
||||
val newChangelog = changelog.replace("## To Be Released", newItem)
|
||||
changelogPath.writeText(newChangelog)
|
||||
}
|
@@ -13,20 +13,21 @@ fun main(args: Array<String>) {
|
||||
|
||||
checkReleaseType(releaseType)
|
||||
|
||||
withGit(rootDir) { git ->
|
||||
if (git.diff().call().isNotEmpty()) {
|
||||
git
|
||||
.commit()
|
||||
.setAll(true)
|
||||
.setAuthor("IdeaVim Bot", "maintainers@ideavim.dev")
|
||||
.setMessage("Preparation to $newVersion release")
|
||||
.setSign(false)
|
||||
.call()
|
||||
if (releaseType == "patch") {
|
||||
println("Skip committing changes because release type is 'patch'")
|
||||
return
|
||||
}
|
||||
|
||||
val lastGitMessage = git.log().call().first().shortMessage
|
||||
println("Changes committed. Last gitlog message: $lastGitMessage")
|
||||
} else {
|
||||
println("No Changes")
|
||||
}
|
||||
withGit(rootDir) { git ->
|
||||
git
|
||||
.commit()
|
||||
.setAll(true)
|
||||
.setAuthor("IdeaVim Bot", "maintainers@ideavim.dev")
|
||||
.setMessage("Preparation to $newVersion release")
|
||||
.setSign(false)
|
||||
.call()
|
||||
|
||||
val lastGitMessage = git.log().call().first().shortMessage
|
||||
println("Changes committed. Last gitlog message: $lastGitMessage")
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 (_, rootDir, releaseType) = readArgs(args)
|
||||
|
||||
checkReleaseType(releaseType)
|
||||
|
||||
checkBranch(rootDir, releaseType)
|
||||
|
||||
if (releaseType == "patch") {
|
||||
println("Skip release branch reset because release type is 'patch'")
|
||||
return
|
||||
}
|
||||
|
||||
withGit(rootDir) { git ->
|
||||
val currentCommit = git.log().setMaxCount(1).call().first()
|
||||
println("Current commit id: ${currentCommit.id.name}")
|
||||
|
||||
git.checkoutBranch("release")
|
||||
println("Checked out release branch")
|
||||
|
||||
git.reset()
|
||||
.setRef(currentCommit.id.name)
|
||||
.call()
|
||||
println("release branch reset")
|
||||
|
||||
git.checkoutBranch("master")
|
||||
println("Checked out master branch")
|
||||
}
|
||||
}
|
@@ -15,7 +15,8 @@ fun main(args: Array<String>) {
|
||||
|
||||
withGit(rootDir) { git ->
|
||||
val branchName = when (releaseType) {
|
||||
"major", "minor", "patch" -> "release"
|
||||
"major", "minor" -> "master"
|
||||
"patch" -> "release"
|
||||
else -> error("Unsupported release type: $releaseType")
|
||||
}
|
||||
|
||||
|
@@ -58,13 +58,7 @@ internal fun checkBranch(rootDir: String, releaseType: String) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class ReleaseType {
|
||||
ANY,
|
||||
ONLY_STABLE,
|
||||
STABLE_NO_PATCH, // Version that ends on 0. Like 2.5.0
|
||||
}
|
||||
|
||||
internal fun getVersion(projectDir: String, releaseType: ReleaseType): Pair<Semver, ObjectId> {
|
||||
internal fun getVersion(projectDir: String, onlyStable: Boolean): Pair<Semver, ObjectId> {
|
||||
val repository = RepositoryBuilder().setGitDir(File("$projectDir/.git")).build()
|
||||
val git = Git(repository)
|
||||
println(git.log().call().first())
|
||||
@@ -81,10 +75,10 @@ internal fun getVersion(projectDir: String, releaseType: ReleaseType): Pair<Semv
|
||||
}
|
||||
.sortedBy { it.first }
|
||||
|
||||
val version = when (releaseType) {
|
||||
ReleaseType.ANY -> versions.last()
|
||||
ReleaseType.ONLY_STABLE -> versions.last { it.first.isStable }
|
||||
ReleaseType.STABLE_NO_PATCH -> versions.last { it.first.isStable && it.first.patch == 0 }
|
||||
val version = if (onlyStable) {
|
||||
versions.last { it.first.isStable }
|
||||
} else {
|
||||
versions.last()
|
||||
}
|
||||
|
||||
return version
|
||||
|
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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 scripts.releaseEap
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import scripts.addComment
|
||||
import scripts.getYoutrackTicketsByQuery
|
||||
import scripts.release.readArgs
|
||||
import scripts.releasedInEapTagId
|
||||
import scripts.setTag
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
runBlocking {
|
||||
val (newVersion, _, _) = readArgs(args)
|
||||
|
||||
// Search for Ready to release, but without "IdeaVim Released In EAP" tag
|
||||
val ticketsToUpdate =
|
||||
getYoutrackTicketsByQuery("%23%7BReady%20To%20Release%7D%20tag:%20-%7BIdeaVim%20Released%20In%20EAP%7D%20")
|
||||
println("Have to update the following tickets: $ticketsToUpdate")
|
||||
|
||||
ticketsToUpdate.forEach { ticketId ->
|
||||
setTag(ticketId, releasedInEapTagId)
|
||||
addComment(
|
||||
ticketId, """
|
||||
The fix is available in the IdeaVim $newVersion. See https://jb.gg/ideavim-eap for the instructions on how to get EAP builds as updates within the IDE. You can also wait till the next stable release with this fix, you’ll get it automatically.
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@@ -11,8 +11,6 @@ package scripts
|
||||
import io.ktor.client.call.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.http.*
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.serialization.json.JsonArray
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.addJsonObject
|
||||
import kotlinx.serialization.json.buildJsonObject
|
||||
@@ -23,10 +21,6 @@ import kotlinx.serialization.json.put
|
||||
import kotlinx.serialization.json.putJsonArray
|
||||
import kotlinx.serialization.json.putJsonObject
|
||||
|
||||
|
||||
// YouTrack tag "IdeaVim Released In EAP"
|
||||
const val releasedInEapTagId = "68-385032"
|
||||
|
||||
suspend fun setYoutrackStatus(tickets: Collection<String>, status: String) {
|
||||
val client = httpClient()
|
||||
|
||||
@@ -65,59 +59,3 @@ suspend fun setYoutrackStatus(tickets: Collection<String>, status: String) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getYoutrackTicketsByQuery(query: String): Set<String> {
|
||||
val client = httpClient()
|
||||
|
||||
return runBlocking {
|
||||
val response = client.get("https://youtrack.jetbrains.com/api/issues/?fields=idReadable&query=project:VIM+$query")
|
||||
response.body<JsonArray>().mapTo(HashSet()) { it.jsonObject.getValue("idReadable").jsonPrimitive.content }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 68-385032
|
||||
* [issueHumanId] is like VIM-123
|
||||
* [tagId] is like "145-23"
|
||||
*/
|
||||
suspend fun setTag(issueHumanId: String, tagId: String) {
|
||||
val client = httpClient()
|
||||
|
||||
println("Try to add tag $tagId to $issueHumanId")
|
||||
val response =
|
||||
// I've updated default url in client, so this may be broken now
|
||||
client.post("https://youtrack.jetbrains.com/api/issues/$issueHumanId/tags?fields=customFields(id,name,value(id,name))") {
|
||||
contentType(ContentType.Application.Json)
|
||||
accept(ContentType.Application.Json)
|
||||
val request = buildJsonObject {
|
||||
put("id", tagId)
|
||||
}
|
||||
setBody(request)
|
||||
}
|
||||
println(response)
|
||||
println(response.body<String>())
|
||||
if (!response.status.isSuccess()) {
|
||||
error("Request failed. $issueHumanId, ${response.body<String>()}")
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun addComment(issueHumanId: String, text: String) {
|
||||
val client = httpClient()
|
||||
|
||||
println("Try to add comment to $issueHumanId")
|
||||
val response =
|
||||
// I've updated default url in client, so this may be broken now
|
||||
client.post("https://youtrack.jetbrains.com/api/issues/$issueHumanId/comments?fields=customFields(id,name,value(id,name))") {
|
||||
contentType(ContentType.Application.Json)
|
||||
accept(ContentType.Application.Json)
|
||||
val request = buildJsonObject {
|
||||
put("text", text)
|
||||
}
|
||||
setBody(request)
|
||||
}
|
||||
println(response)
|
||||
println(response.body<String>())
|
||||
if (!response.status.isSuccess()) {
|
||||
error("Request failed. $issueHumanId, ${response.body<String>()}")
|
||||
}
|
||||
}
|
||||
|
@@ -12,9 +12,4 @@ rootProject.name = 'IdeaVIM'
|
||||
include 'vim-engine'
|
||||
include 'scripts'
|
||||
include 'annotation-processors'
|
||||
include 'tests:java-tests'
|
||||
include 'tests:property-tests'
|
||||
include 'tests:long-running-tests'
|
||||
include 'tests:ui-ij-tests'
|
||||
include 'tests:ui-py-tests'
|
||||
include 'tests:ui-fixtures'
|
||||
|
||||
|
@@ -11,7 +11,7 @@ package com.maddyhome.idea.vim
|
||||
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.ProjectManagerListener
|
||||
import com.intellij.openapi.startup.ProjectActivity
|
||||
import com.intellij.openapi.startup.StartupActivity
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.localEditors
|
||||
@@ -20,11 +20,16 @@ import com.maddyhome.idea.vim.newapi.globalIjOptions
|
||||
/**
|
||||
* @author Alex Plate
|
||||
*/
|
||||
internal class PluginStartup : ProjectActivity/*, LightEditCompatible*/ {
|
||||
// This service should be migrated to ProjectActivity. But we should cariful because simple replacement
|
||||
// leads to deadlock in tests. I'm not sure about the exact reasons, but "invokeAndWait" inside "initialize" function
|
||||
// causes this deadlock. Good new: it's easy reproducible in tests.
|
||||
// Previous migration: fc7efd5484a13b40ba9bf86a1d5429e215d973f3
|
||||
// Revert: 24dd84b31cffb99eb6114524859a46d02717d33f
|
||||
internal class PluginStartup : StartupActivity.DumbAware/*, LightEditCompatible*/ {
|
||||
|
||||
private var firstInitializationOccurred = false
|
||||
|
||||
override suspend fun execute(project: Project) {
|
||||
override fun runActivity(project: Project) {
|
||||
if (firstInitializationOccurred) return
|
||||
firstInitializationOccurred = true
|
||||
|
||||
|
@@ -7,27 +7,56 @@
|
||||
*/
|
||||
package com.maddyhome.idea.vim
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
import com.maddyhome.idea.vim.action.EngineCommandProvider
|
||||
import com.maddyhome.idea.vim.action.IntellijCommandProvider
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.handler.ActionBeanClass
|
||||
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase
|
||||
import com.maddyhome.idea.vim.key.MappingOwner
|
||||
import com.maddyhome.idea.vim.newapi.IjVimActionsInitiator
|
||||
import com.maddyhome.idea.vim.newapi.globalIjOptions
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
public object RegisterActions {
|
||||
@Deprecated("Please use @CommandOrMotion annotation instead")
|
||||
internal val VIM_ACTIONS_EP: ExtensionPointName<ActionBeanClass> = ExtensionPointName.create("IdeaVIM.vimAction")
|
||||
|
||||
/**
|
||||
* Register all the key/action mappings for the plugin.
|
||||
*/
|
||||
@JvmStatic
|
||||
public fun registerActions() {
|
||||
registerVimCommandActions()
|
||||
registerEmptyShortcuts() // todo most likely it is not needed
|
||||
if (!injector.globalIjOptions().commandOrMotionAnnotation) {
|
||||
registerEmptyShortcuts()
|
||||
registerEpListener()
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Moving to annotations approach instead of xml")
|
||||
private fun registerEpListener() {
|
||||
// IdeaVim doesn't support contribution to VIM_ACTIONS_EP extension point, so technically we can skip this update,
|
||||
// but let's support dynamic plugins in a more classic way and reload actions on every EP change.
|
||||
VIM_ACTIONS_EP.addChangeListener({
|
||||
unregisterActions()
|
||||
registerActions()
|
||||
}, VimPlugin.getInstance())
|
||||
}
|
||||
|
||||
public fun findAction(id: String): EditorActionHandlerBase? {
|
||||
val commandBean = EngineCommandProvider.getCommands().firstOrNull { it.actionId == id }
|
||||
?: IntellijCommandProvider.getCommands().firstOrNull { it.actionId == id } ?: return null
|
||||
return commandBean.instance
|
||||
if (injector.globalIjOptions().commandOrMotionAnnotation) {
|
||||
val commandBean = EngineCommandProvider.getCommands().firstOrNull { it.actionId == id }
|
||||
?: IntellijCommandProvider.getCommands().firstOrNull { it.actionId == id } ?: return null
|
||||
return commandBean.instance
|
||||
} else {
|
||||
return VIM_ACTIONS_EP.getExtensionList(ApplicationManager.getApplication()).stream()
|
||||
.filter { vimActionBean: ActionBeanClass -> vimActionBean.actionId == id }
|
||||
.findFirst().map { obj: ActionBeanClass -> obj.instance }
|
||||
.orElse(null)
|
||||
}
|
||||
}
|
||||
|
||||
public fun findActionOrDie(id: String): EditorActionHandlerBase {
|
||||
@@ -42,10 +71,24 @@ public object RegisterActions {
|
||||
|
||||
private fun registerVimCommandActions() {
|
||||
val parser = VimPlugin.getKey()
|
||||
EngineCommandProvider.getCommands().forEach { parser.registerCommandAction(it) }
|
||||
IntellijCommandProvider.getCommands().forEach { parser.registerCommandAction(it) }
|
||||
if (injector.globalIjOptions().commandOrMotionAnnotation) {
|
||||
EngineCommandProvider.getCommands().forEach { parser.registerCommandAction(it) }
|
||||
IntellijCommandProvider.getCommands().forEach { parser.registerCommandAction(it) }
|
||||
} else {
|
||||
VIM_ACTIONS_EP.getExtensionList(ApplicationManager.getApplication()).stream().map { bean: ActionBeanClass? ->
|
||||
IjVimActionsInitiator(
|
||||
bean!!
|
||||
)
|
||||
}
|
||||
.forEach { actionHolder: IjVimActionsInitiator? ->
|
||||
parser.registerCommandAction(
|
||||
actionHolder!!
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// todo do we really need this?
|
||||
private fun registerEmptyShortcuts() {
|
||||
val parser = VimPlugin.getKey()
|
||||
|
||||
|
@@ -39,9 +39,11 @@ import com.maddyhome.idea.vim.listener.VimListenerManager;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimInjector;
|
||||
import com.maddyhome.idea.vim.ui.StatusBarIconFactory;
|
||||
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel;
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionService;
|
||||
import com.maddyhome.idea.vim.vimscript.services.VariableService;
|
||||
import com.maddyhome.idea.vim.yank.YankGroupBase;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -115,6 +117,12 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
|
||||
return ApplicationManager.getApplication().getService(CommandGroup.class);
|
||||
}
|
||||
|
||||
@Deprecated // "Please use `injector.markService` instead"
|
||||
@ApiStatus.ScheduledForRemoval(inVersion = "2.3")
|
||||
public static @NotNull MarkGroup getMark() {
|
||||
return ApplicationManager.getApplication().getService(MarkGroup.class);
|
||||
}
|
||||
|
||||
public static @NotNull RegisterGroup getRegister() {
|
||||
return ((RegisterGroup)VimInjectorKt.getInjector().getRegisterGroup());
|
||||
}
|
||||
@@ -187,6 +195,13 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
|
||||
return VimInjectorKt.getInjector().getOptionGroup();
|
||||
}
|
||||
|
||||
/** Deprecated: Use getOptionGroup */
|
||||
@Deprecated
|
||||
// Used by which-key 0.8.0, IdeaVimExtension 1.6.5 + 1.6.8
|
||||
public static @NotNull OptionService getOptionService() {
|
||||
return VimInjectorKt.getInjector().getOptionService();
|
||||
}
|
||||
|
||||
private static @NotNull NotificationService getNotifications() {
|
||||
return getNotifications(null);
|
||||
}
|
||||
@@ -204,10 +219,6 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
|
||||
return getInstance().enabled;
|
||||
}
|
||||
|
||||
public static boolean isNotEnabled() {
|
||||
return !isEnabled();
|
||||
}
|
||||
|
||||
public static void setEnabled(final boolean enabled) {
|
||||
if (isEnabled() == enabled) return;
|
||||
|
||||
@@ -221,13 +232,7 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
|
||||
getInstance().turnOnPlugin();
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
VimInjectorKt.getInjector().getListenersNotifier().notifyPluginTurnedOn();
|
||||
} else {
|
||||
VimInjectorKt.getInjector().getListenersNotifier().notifyPluginTurnedOff();
|
||||
}
|
||||
|
||||
StatusBarIconFactory.Util.INSTANCE.updateIcon();
|
||||
StatusBarIconFactory.Companion.updateIcon();
|
||||
}
|
||||
|
||||
public static String getMessage() {
|
||||
@@ -259,8 +264,7 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
|
||||
if (enabled) {
|
||||
Application application = ApplicationManager.getApplication();
|
||||
if (application.isUnitTestMode()) {
|
||||
turnOnPlugin();
|
||||
//application.invokeAndWait(this::turnOnPlugin);
|
||||
application.invokeAndWait(this::turnOnPlugin);
|
||||
}
|
||||
else {
|
||||
application.invokeLater(this::turnOnPlugin);
|
||||
|
@@ -28,11 +28,8 @@ import javax.swing.KeyStroke
|
||||
* Accepts all regular keystrokes and passes them on to the Vim key handler.
|
||||
*
|
||||
* IDE shortcut keys used by Vim commands are handled by [com.maddyhome.idea.vim.action.VimShortcutKeyAction].
|
||||
*
|
||||
* This class is used in Which-Key plugin, so don't make it internal. Generally, we should provide a proper
|
||||
* way to get ideavim keys for this plugin. See VIM-3085
|
||||
*/
|
||||
public class VimTypedActionHandler(origHandler: TypedActionHandler) : TypedActionHandlerEx {
|
||||
internal class VimTypedActionHandler(origHandler: TypedActionHandler) : TypedActionHandlerEx {
|
||||
private val handler = KeyHandler.getInstance()
|
||||
private val traceTime = injector.globalOptions().ideatracetime
|
||||
|
||||
@@ -89,7 +86,7 @@ public class VimTypedActionHandler(origHandler: TypedActionHandler) : TypedActio
|
||||
}
|
||||
}
|
||||
|
||||
internal companion object {
|
||||
companion object {
|
||||
private val LOG = logger<VimTypedActionHandler>()
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
import com.intellij.codeInsight.hint.HintManagerImpl
|
||||
import com.intellij.openapi.actionSystem.ActionManager
|
||||
import com.intellij.openapi.actionSystem.ActionUpdateThread
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys
|
||||
import com.intellij.openapi.actionSystem.PerformWithDocumentsCommitted
|
||||
import com.intellij.openapi.actionSystem.PopupAction
|
||||
import com.intellij.openapi.actionSystem.impl.ActionConfigurationCustomizer
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.EditorMouseHoverPopupManager
|
||||
import com.intellij.openapi.editor.event.EditorMouseEvent
|
||||
import com.intellij.openapi.editor.event.EditorMouseEventArea
|
||||
import com.intellij.openapi.project.DumbAware
|
||||
import java.awt.event.MouseEvent
|
||||
|
||||
// [VERSION UPDATE] 233+ Remove class
|
||||
// The ShowHoverInfo action is built into the platform (using a nicer EditorMouseHoverPopupManager API)
|
||||
public class VimActionConfigurationCustomizer : ActionConfigurationCustomizer {
|
||||
public override fun customize(actionManager: ActionManager) {
|
||||
// If the ShowHoverInfo action doesn't exist in the platform, add our own implementation
|
||||
if (actionManager.getAction("ShowHoverInfo") == null) {
|
||||
actionManager.registerAction("ShowHoverInfo", VimShowHoverInfoAction())
|
||||
}
|
||||
}
|
||||
|
||||
private class VimShowHoverInfoAction : AnAction(), HintManagerImpl.ActionToIgnore, PopupAction, DumbAware,
|
||||
PerformWithDocumentsCommitted {
|
||||
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
|
||||
|
||||
override fun update(e: AnActionEvent) {
|
||||
val dataContext = e.dataContext
|
||||
val editor = CommonDataKeys.EDITOR.getData(dataContext)
|
||||
if (editor == null) {
|
||||
e.presentation.isEnabledAndVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val editor = CommonDataKeys.EDITOR.getData(e.dataContext) ?: return
|
||||
|
||||
val editorMouseEvent = createFakeEditorMouseEvent(editor)
|
||||
EditorMouseHoverPopupManager.getInstance().showInfoTooltip(editorMouseEvent)
|
||||
}
|
||||
|
||||
private fun createFakeEditorMouseEvent(editor: Editor): EditorMouseEvent {
|
||||
val xy = editor.offsetToXY(editor.caretModel.offset)
|
||||
val mouseEvent =
|
||||
MouseEvent(editor.component, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, xy.x, xy.y, 0, false)
|
||||
val editorMouseEvent = EditorMouseEvent(
|
||||
editor,
|
||||
mouseEvent,
|
||||
EditorMouseEventArea.EDITING_AREA,
|
||||
editor.caretModel.offset,
|
||||
editor.caretModel.logicalPosition,
|
||||
editor.caretModel.visualPosition,
|
||||
true,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
)
|
||||
return editorMouseEvent
|
||||
}
|
||||
}
|
||||
}
|
@@ -14,10 +14,14 @@ import com.intellij.openapi.actionSystem.ActionUpdateThread
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.actionSystem.AnActionWrapper
|
||||
import com.intellij.openapi.actionSystem.IdeActions
|
||||
import com.intellij.openapi.actionSystem.KeyboardShortcut
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys
|
||||
import com.intellij.openapi.application.invokeLater
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionManager
|
||||
import com.intellij.openapi.keymap.KeymapManager
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
import com.intellij.openapi.project.DumbAware
|
||||
import com.intellij.openapi.util.Key
|
||||
@@ -28,7 +32,6 @@ import com.maddyhome.idea.vim.api.globalOptions
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.group.IjOptionConstants
|
||||
import com.maddyhome.idea.vim.group.IjOptions
|
||||
import com.maddyhome.idea.vim.handler.enableOctopus
|
||||
import com.maddyhome.idea.vim.handler.isOctopusEnabled
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.HandlerInjector
|
||||
@@ -55,17 +58,9 @@ import javax.swing.KeyStroke
|
||||
*
|
||||
*
|
||||
* These keys are not passed to [com.maddyhome.idea.vim.VimTypedActionHandler] and should be handled by actions.
|
||||
*
|
||||
* This class is used in Which-Key plugin, so don't make it internal. Generally, we should provide a proper
|
||||
* way to get ideavim keys for this plugin. See VIM-3085
|
||||
*/
|
||||
public class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible*/ {
|
||||
private val traceTime: Boolean
|
||||
get() {
|
||||
// Make sure the injector is initialized
|
||||
VimPlugin.getInstance()
|
||||
return injector.globalOptions().ideatracetime
|
||||
}
|
||||
internal class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible*/ {
|
||||
private val traceTime = injector.globalOptions().ideatracetime
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
LOG.trace("Executing shortcut key action")
|
||||
@@ -99,7 +94,7 @@ public class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible
|
||||
|
||||
// There is a chance that we can use BGT, but we call for isCell inside the update.
|
||||
// Not sure if can can use BGT with this call. Let's use EDT for now.
|
||||
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT
|
||||
override fun getActionUpdateThread() = ActionUpdateThread.EDT
|
||||
|
||||
override fun update(e: AnActionEvent) {
|
||||
val start = if (traceTime) System.currentTimeMillis() else null
|
||||
@@ -114,16 +109,14 @@ public class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible
|
||||
}
|
||||
|
||||
private fun isEnabled(e: AnActionEvent, keyStroke: KeyStroke?): ActionEnableStatus {
|
||||
if (VimPlugin.isNotEnabled()) return ActionEnableStatus.no("IdeaVim is disabled", LogLevel.DEBUG)
|
||||
if (!VimPlugin.isEnabled()) return ActionEnableStatus.no("IdeaVim is disabled", LogLevel.DEBUG)
|
||||
val editor = getEditor(e)
|
||||
if (editor != null && keyStroke != null) {
|
||||
if (enableOctopus) {
|
||||
if (isOctopusEnabled(keyStroke, editor)) {
|
||||
return ActionEnableStatus.no(
|
||||
"Processing VimShortcutKeyAction for the key that is used in the octopus handler",
|
||||
LogLevel.ERROR
|
||||
)
|
||||
}
|
||||
if (isOctopusEnabled(keyStroke, editor)) {
|
||||
return ActionEnableStatus.no(
|
||||
"Processing VimShortcutKeyAction for the key that is used in the octopus handler",
|
||||
LogLevel.ERROR
|
||||
)
|
||||
}
|
||||
if (editor.isIdeaVimDisabledHere) {
|
||||
return ActionEnableStatus.no("IdeaVim is disabled in this place", LogLevel.INFO)
|
||||
@@ -170,6 +163,14 @@ public class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible
|
||||
return ActionEnableStatus.no("App code template is active", LogLevel.INFO)
|
||||
}
|
||||
|
||||
val nextTemplateVariableShortcuts = KeymapManager.getInstance().activeKeymap.getShortcuts(IdeActions.ACTION_EDITOR_NEXT_TEMPLATE_VARIABLE)
|
||||
if (nextTemplateVariableShortcuts.any { it is KeyboardShortcut && it.firstKeyStroke == keyStroke }) {
|
||||
val handler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_NEXT_TEMPLATE_VARIABLE)
|
||||
if (handler.isEnabled(editor, null, e.dataContext)) {
|
||||
return ActionEnableStatus.no("Next template variable or finish in-place refactoring", LogLevel.INFO)
|
||||
}
|
||||
}
|
||||
|
||||
if (editor.inInsertMode) {
|
||||
if (keyCode == KeyEvent.VK_TAB) {
|
||||
// TODO: This stops VimEditorTab seeing <Tab> in insert mode and correctly scrolling the view
|
||||
@@ -235,9 +236,9 @@ public class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible
|
||||
/**
|
||||
* getDefaultKeyStroke is needed for NEO layout keyboard VIM-987
|
||||
* but we should cache the value because on the second call (isEnabled -> actionPerformed)
|
||||
* the event is already consumed and getDefaultKeyStroke returns null
|
||||
* the event is already consumed
|
||||
*/
|
||||
private var keyStrokeCache: Pair<Long?, KeyStroke?> = null to null
|
||||
private var keyStrokeCache: Pair<KeyEvent?, KeyStroke?> = null to null
|
||||
|
||||
private fun getKeyStroke(e: AnActionEvent): KeyStroke? {
|
||||
val inputEvent = e.inputEvent
|
||||
@@ -245,9 +246,9 @@ public class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible
|
||||
val defaultKeyStroke = KeyStrokeAdapter.getDefaultKeyStroke(inputEvent)
|
||||
val strokeCache = keyStrokeCache
|
||||
if (defaultKeyStroke != null) {
|
||||
keyStrokeCache = inputEvent.`when` to defaultKeyStroke
|
||||
keyStrokeCache = inputEvent to defaultKeyStroke
|
||||
return defaultKeyStroke
|
||||
} else if (strokeCache.first == inputEvent.`when`) {
|
||||
} else if (strokeCache.first === inputEvent) {
|
||||
keyStrokeCache = null to null
|
||||
return strokeCache.second
|
||||
}
|
||||
@@ -280,7 +281,7 @@ public class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible
|
||||
.toSet()
|
||||
}
|
||||
|
||||
internal companion object {
|
||||
companion object {
|
||||
@JvmField
|
||||
val VIM_ONLY_EDITOR_KEYS: Set<KeyStroke> =
|
||||
ImmutableSet.builder<KeyStroke>().addAll(getKeyStrokes(KeyEvent.VK_ENTER, 0))
|
||||
|
@@ -18,7 +18,9 @@ import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.api.setChangeMarks
|
||||
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.OperatorArguments
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.common.argumentCaptured
|
||||
import com.maddyhome.idea.vim.group.MotionGroup
|
||||
@@ -26,9 +28,10 @@ import com.maddyhome.idea.vim.group.visual.VimSelection
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler
|
||||
import com.maddyhome.idea.vim.helper.MessageHelper
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import com.maddyhome.idea.vim.helper.vimStateMachine
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
import java.util.*
|
||||
|
||||
// todo make it multicaret
|
||||
private fun doOperatorAction(editor: VimEditor, context: ExecutionContext, textRange: TextRange, selectionType: SelectionType): Boolean {
|
||||
@@ -101,6 +104,8 @@ internal class OperatorAction : VimActionHandler.SingleExecution() {
|
||||
internal class VisualOperatorAction : VisualOperatorActionHandler.ForEachCaret() {
|
||||
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_EXIT_VISUAL)
|
||||
|
||||
override fun executeAction(
|
||||
editor: VimEditor,
|
||||
caret: VimCaret,
|
||||
|
@@ -14,10 +14,13 @@ 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.Command
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.group.visual.VimSelection
|
||||
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import com.maddyhome.idea.vim.newapi.ijOptions
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
@@ -26,6 +29,8 @@ import com.maddyhome.idea.vim.newapi.ijOptions
|
||||
public class DeleteJoinVisualLinesAction : VisualOperatorActionHandler.SingleExecution() {
|
||||
override val type: Command.Type = Command.Type.DELETE
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_EXIT_VISUAL)
|
||||
|
||||
override fun executeForAllCarets(
|
||||
editor: VimEditor,
|
||||
context: ExecutionContext,
|
||||
|
@@ -14,10 +14,13 @@ 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.Command
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.group.visual.VimSelection
|
||||
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import com.maddyhome.idea.vim.newapi.ijOptions
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
@@ -26,6 +29,8 @@ import com.maddyhome.idea.vim.newapi.ijOptions
|
||||
public class DeleteJoinVisualLinesSpacesAction : VisualOperatorActionHandler.SingleExecution() {
|
||||
override val type: Command.Type = Command.Type.DELETE
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_EXIT_VISUAL)
|
||||
|
||||
override fun executeForAllCarets(
|
||||
editor: VimEditor,
|
||||
context: ExecutionContext,
|
||||
|
@@ -8,9 +8,10 @@
|
||||
|
||||
package com.maddyhome.idea.vim.action.editor
|
||||
|
||||
import com.intellij.openapi.actionSystem.IdeActions
|
||||
import com.intellij.vim.annotations.CommandOrMotion
|
||||
import com.intellij.vim.annotations.Mode
|
||||
import com.intellij.openapi.actionSystem.IdeActions
|
||||
import com.maddyhome.idea.vim.action.ComplicatedKeysAction
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
@@ -20,32 +21,54 @@ import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.handler.IdeActionHandler
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import java.awt.event.KeyEvent
|
||||
import java.util.*
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
@CommandOrMotion(keys = ["<C-H>", "<BS>"], modes = [Mode.INSERT])
|
||||
internal class VimEditorBackSpace : IdeActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE) {
|
||||
internal class VimEditorBackSpace : IdeActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE), ComplicatedKeysAction {
|
||||
override val keyStrokesSet: Set<List<KeyStroke>> = setOf(
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.CTRL_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0)),
|
||||
)
|
||||
override val type: Command.Type = Command.Type.DELETE
|
||||
}
|
||||
|
||||
@CommandOrMotion(keys = ["<Del>"], modes = [Mode.INSERT])
|
||||
internal class VimEditorDelete : IdeActionHandler(IdeActions.ACTION_EDITOR_DELETE) {
|
||||
internal class VimEditorDelete : IdeActionHandler(IdeActions.ACTION_EDITOR_DELETE), ComplicatedKeysAction {
|
||||
override val keyStrokesSet: Set<List<KeyStroke>> = setOf(
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)),
|
||||
)
|
||||
override val type: Command.Type = Command.Type.DELETE
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_SAVE_STROKE)
|
||||
}
|
||||
|
||||
@CommandOrMotion(keys = ["<Down>", "<kDown>"], modes = [Mode.INSERT])
|
||||
internal class VimEditorDown : IdeActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN) {
|
||||
internal class VimEditorDown : IdeActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN), ComplicatedKeysAction {
|
||||
override val keyStrokesSet: Set<List<KeyStroke>> = setOf(
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_DOWN, 0)),
|
||||
)
|
||||
override val type: Command.Type = Command.Type.MOTION
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_CLEAR_STROKES)
|
||||
}
|
||||
|
||||
@CommandOrMotion(keys = ["<Tab>", "<C-I>"], modes = [Mode.INSERT])
|
||||
internal class VimEditorTab : IdeActionHandler(IdeActions.ACTION_EDITOR_TAB) {
|
||||
internal class VimEditorTab : IdeActionHandler(IdeActions.ACTION_EDITOR_TAB), ComplicatedKeysAction {
|
||||
override val keyStrokesSet: Set<List<KeyStroke>> = setOf(
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.CTRL_DOWN_MASK)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)),
|
||||
)
|
||||
override val type: Command.Type = Command.Type.INSERT
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_SAVE_STROKE)
|
||||
}
|
||||
|
||||
@CommandOrMotion(keys = ["<Up>", "<kUp>"], modes = [Mode.INSERT])
|
||||
internal class VimEditorUp : IdeActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_UP) {
|
||||
internal class VimEditorUp : IdeActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_UP), ComplicatedKeysAction {
|
||||
override val keyStrokesSet: Set<List<KeyStroke>> = setOf(
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)),
|
||||
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_KP_UP, 0)),
|
||||
)
|
||||
override val type: Command.Type = Command.Type.MOTION
|
||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_CLEAR_STROKES)
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ 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.action.ComplicatedKeysAction
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
@@ -17,6 +18,7 @@ import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
import java.util.*
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
/**
|
||||
* Called by KeyHandler to process the contents of the ex entry panel
|
||||
@@ -24,7 +26,10 @@ import java.util.*
|
||||
* 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() {
|
||||
public class ProcessExEntryAction : VimActionHandler.SingleExecution(), ComplicatedKeysAction {
|
||||
override val keyStrokesSet: Set<List<KeyStroke>> =
|
||||
parseKeysSet("<CR>", "<C-M>", 0x0a.toChar().toString(), 0x0d.toChar().toString())
|
||||
|
||||
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
||||
|
||||
override val flags: EnumSet<CommandFlags> = EnumSet.of(CommandFlags.FLAG_COMPLETE_EX)
|
||||
|
@@ -27,7 +27,7 @@ public class CommandState(private val machine: VimStateMachine) {
|
||||
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.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
|
||||
|
@@ -9,7 +9,6 @@ package com.maddyhome.idea.vim.extension
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
@@ -18,6 +17,7 @@ import com.maddyhome.idea.vim.api.ImmutableVimCaret
|
||||
import com.maddyhome.idea.vim.api.VimCaret
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.command.MappingMode
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
import com.maddyhome.idea.vim.common.CommandAlias
|
||||
import com.maddyhome.idea.vim.common.CommandAliasHandler
|
||||
import com.maddyhome.idea.vim.helper.CommandLineHelper
|
||||
@@ -26,7 +26,6 @@ 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 java.awt.event.KeyEvent
|
||||
import javax.swing.KeyStroke
|
||||
@@ -39,9 +38,6 @@ import javax.swing.KeyStroke
|
||||
* @author vlan
|
||||
*/
|
||||
public object VimExtensionFacade {
|
||||
|
||||
private val LOG = logger<VimExtensionFacade>()
|
||||
|
||||
/** The 'map' command for mapping keys to handlers defined in extensions. */
|
||||
@JvmStatic
|
||||
public fun putExtensionHandlerMapping(
|
||||
@@ -144,12 +140,10 @@ public object VimExtensionFacade {
|
||||
public fun inputKeyStroke(editor: Editor): KeyStroke {
|
||||
if (editor.vim.vimStateMachine.isDotRepeatInProgress) {
|
||||
val input = Extension.consumeKeystroke()
|
||||
LOG.trace("inputKeyStroke: dot repeat in progress. Input: $input")
|
||||
return input ?: error("Not enough keystrokes saved: ${Extension.lastExtensionHandler}")
|
||||
}
|
||||
|
||||
val key: KeyStroke? = if (ApplicationManager.getApplication().isUnitTestMode) {
|
||||
LOG.trace("Unit test mode is active")
|
||||
val mappingStack = KeyHandler.getInstance().keyStack
|
||||
mappingStack.feedSomeStroke() ?: TestInputModel.getInstance(editor).nextKeyStroke()?.also {
|
||||
if (editor.vim.vimStateMachine.isRecording) {
|
||||
@@ -157,13 +151,11 @@ public object VimExtensionFacade {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LOG.trace("Getting char from the modal entry...")
|
||||
var ref: KeyStroke? = null
|
||||
ModalEntry.activate(editor.vim) { stroke: KeyStroke? ->
|
||||
ref = stroke
|
||||
false
|
||||
}
|
||||
LOG.trace("Got char $ref")
|
||||
ref
|
||||
}
|
||||
val result = key ?: KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE.toChar())
|
||||
|
@@ -53,11 +53,6 @@ internal object VimExtensionRegistrar : VimExtensionRegistrator {
|
||||
@Synchronized
|
||||
private fun registerExtension(extensionBean: ExtensionBeanClass) {
|
||||
val name = extensionBean.name ?: extensionBean.instance.name
|
||||
if (name == "sneak" && extensionBean.name == null) {
|
||||
// Filter out the old ideavim-sneak extension that used to be a separate plugin
|
||||
// https://github.com/Mishkun/ideavim-sneak
|
||||
return
|
||||
}
|
||||
if (name in registeredExtensions) return
|
||||
|
||||
registeredExtensions.add(name)
|
||||
|
@@ -156,6 +156,11 @@ internal class CommentaryExtension : VimExtension {
|
||||
private class CommentaryOperatorHandler : OperatorFunction, ExtensionHandler {
|
||||
override val isRepeatable = true
|
||||
|
||||
// In this operator we process selection by ourselves. This is necessary for rider, VIM-1758
|
||||
override fun postProcessSelection(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
|
||||
setOperatorFunction(this)
|
||||
executeNormalWithoutMapping(injector.parser.parseKeys("g@"), editor.ij)
|
||||
|
@@ -217,8 +217,6 @@ private object FileTypePatterns {
|
||||
|
||||
return if (fileTypeName in htmlLikeFileTypes) {
|
||||
this.htmlPatterns
|
||||
} else if (fileTypeName == "JAVA" || fileExtension == "java") {
|
||||
this.javaPatterns
|
||||
} else if (fileTypeName == "Ruby" || fileExtension == "rb") {
|
||||
this.rubyPatterns
|
||||
} else if (fileTypeName == "RHTML" || fileExtension == "erb") {
|
||||
@@ -244,7 +242,6 @@ private object FileTypePatterns {
|
||||
)
|
||||
|
||||
private val htmlPatterns = createHtmlPatterns()
|
||||
private val javaPatterns = createJavaPatterns()
|
||||
private val rubyPatterns = createRubyPatterns()
|
||||
private val rubyAndHtmlPatterns = rubyPatterns + htmlPatterns
|
||||
private val phpPatterns = createPhpPatterns()
|
||||
@@ -273,14 +270,6 @@ private object FileTypePatterns {
|
||||
LanguagePatterns(linkedMapOf(openingTagPattern to htmlSearchPair), linkedMapOf(closingTagPattern to htmlSearchPair))
|
||||
)
|
||||
}
|
||||
|
||||
private fun createJavaPatterns(): LanguagePatterns {
|
||||
return (
|
||||
LanguagePatterns("\\b(?<!else\\s+)if\\b", "\\belse\\s+if\\b", "\\belse(?!\\s+if)\\b") +
|
||||
LanguagePatterns("\\bdo\\b", "\\bwhile\\b") +
|
||||
LanguagePatterns("\\btry\\b", "\\bcatch\\b", "\\bfinally\\b")
|
||||
)
|
||||
}
|
||||
|
||||
private fun createRubyPatterns(): LanguagePatterns {
|
||||
// Original patterns: https://github.com/vim/vim/blob/master/runtime/ftplugin/ruby.vim
|
||||
|
@@ -246,7 +246,7 @@ internal class VimMultipleCursorsExtension : VimExtension {
|
||||
|
||||
// Note that ignoreCase is not overridden by the `\C` in the pattern
|
||||
val pattern = makePattern(text, whole)
|
||||
val matches = injector.searchHelper.findAll(IjVimEditor(editor), pattern, 0, -1, false)
|
||||
val matches = SearchHelper.findAll(editor, pattern, 0, -1, false)
|
||||
for (match in matches) {
|
||||
if (match.contains(primaryCaret.offset)) {
|
||||
primaryCaret.vim.moveToOffset(match.startOffset)
|
||||
@@ -322,7 +322,7 @@ internal class VimMultipleCursorsExtension : VimExtension {
|
||||
searchOptions.add(SearchOptions.WRAP)
|
||||
}
|
||||
|
||||
return injector.searchHelper.findPattern(IjVimEditor(editor), makePattern(text, whole), startOffset, 1, searchOptions)?.startOffset ?: -1
|
||||
return SearchHelper.findPattern(editor, makePattern(text, whole), startOffset, 1, searchOptions)?.startOffset ?: -1
|
||||
}
|
||||
|
||||
private fun makePattern(text: String, whole: Boolean): String {
|
||||
|
@@ -502,13 +502,6 @@ 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 {
|
||||
|
@@ -11,8 +11,8 @@ package com.maddyhome.idea.vim.extension.paragraphmotion
|
||||
import com.intellij.openapi.editor.Caret
|
||||
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
|
||||
@@ -45,7 +45,8 @@ 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) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,321 +0,0 @@
|
||||
/*
|
||||
* 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.extension.sneak
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.ScrollType
|
||||
import com.intellij.openapi.editor.colors.EditorColors
|
||||
import com.intellij.openapi.editor.markup.EffectType
|
||||
import com.intellij.openapi.editor.markup.HighlighterLayer
|
||||
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.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.VimProjectService
|
||||
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.api.options
|
||||
import com.maddyhome.idea.vim.command.MappingMode
|
||||
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.putKeyMapping
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionHandler
|
||||
import com.maddyhome.idea.vim.helper.StrictMode
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import java.awt.Font
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.Timer
|
||||
|
||||
|
||||
private const val DEFAULT_HIGHLIGHT_DURATION_SNEAK = 300
|
||||
|
||||
// By [Mikhail Levchenko](https://github.com/Mishkun)
|
||||
// Original repository with the plugin: https://github.com/Mishkun/ideavim-sneak
|
||||
internal class IdeaVimSneakExtension : VimExtension {
|
||||
override fun getName(): String = "sneak"
|
||||
|
||||
override fun init() {
|
||||
val highlightHandler = HighlightHandler()
|
||||
mapToFunctionAndProvideKeys("s", SneakHandler(highlightHandler, Direction.FORWARD))
|
||||
mapToFunctionAndProvideKeys("S", SneakHandler(highlightHandler, Direction.BACKWARD))
|
||||
|
||||
// workaround to support ; and , commands
|
||||
mapToFunctionAndProvideKeys("f", SneakMemoryHandler("f"))
|
||||
mapToFunctionAndProvideKeys("F", SneakMemoryHandler("F"))
|
||||
mapToFunctionAndProvideKeys("t", SneakMemoryHandler("t"))
|
||||
mapToFunctionAndProvideKeys("T", SneakMemoryHandler("T"))
|
||||
|
||||
mapToFunctionAndProvideKeys(";", SneakRepeatHandler(highlightHandler, RepeatDirection.IDENTICAL))
|
||||
mapToFunctionAndProvideKeys(",", SneakRepeatHandler(highlightHandler, RepeatDirection.REVERSE))
|
||||
}
|
||||
|
||||
private class SneakHandler(
|
||||
private val highlightHandler: HighlightHandler,
|
||||
private val direction: Direction,
|
||||
) : ExtensionHandler {
|
||||
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
|
||||
val charone = getChar(editor) ?: return
|
||||
val chartwo = getChar(editor) ?: return
|
||||
val range = Util.jumpTo(editor, charone, chartwo, direction)
|
||||
range?.let { highlightHandler.highlightSneakRange(editor.ij, range) }
|
||||
Util.lastSymbols = "${charone}${chartwo}"
|
||||
Util.lastSDirection = direction
|
||||
}
|
||||
|
||||
private fun getChar(editor: VimEditor): Char? {
|
||||
val key = VimExtensionFacade.inputKeyStroke(editor.ij)
|
||||
return when {
|
||||
key.keyChar == KeyEvent.CHAR_UNDEFINED || key.keyCode == KeyEvent.VK_ESCAPE -> null
|
||||
else -> key.keyChar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class acts as proxy for normal find commands because we need to update [Util.lastSDirection]
|
||||
*/
|
||||
private class SneakMemoryHandler(private val char: String) : VimExtensionHandler {
|
||||
override fun execute(editor: Editor, context: DataContext) {
|
||||
Util.lastSDirection = null
|
||||
VimExtensionFacade.executeNormalWithoutMapping(injector.parser.parseKeys(char), editor)
|
||||
}
|
||||
}
|
||||
|
||||
private class SneakRepeatHandler(
|
||||
private val highlightHandler: HighlightHandler,
|
||||
private val direction: RepeatDirection,
|
||||
) : ExtensionHandler {
|
||||
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
|
||||
val lastSDirection = Util.lastSDirection
|
||||
if (lastSDirection != null) {
|
||||
val (charone, chartwo) = Util.lastSymbols.toList()
|
||||
val jumpRange = Util.jumpTo(editor, charone, chartwo, direction.map(lastSDirection))
|
||||
jumpRange?.let { highlightHandler.highlightSneakRange(editor.ij, jumpRange) }
|
||||
} else {
|
||||
VimExtensionFacade.executeNormalWithoutMapping(injector.parser.parseKeys(direction.symb), editor.ij)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private object Util {
|
||||
var lastSDirection: Direction? = null
|
||||
var lastSymbols: String = ""
|
||||
fun jumpTo(editor: VimEditor, charone: Char, chartwo: Char, sneakDirection: Direction): TextRange? {
|
||||
val caret = editor.primaryCaret()
|
||||
val position = caret.offset.point
|
||||
val chars = editor.text()
|
||||
val foundPosition = sneakDirection.findBiChar(editor, chars, position, charone, chartwo)
|
||||
if (foundPosition != null) {
|
||||
editor.primaryCaret().moveToOffset(foundPosition)
|
||||
}
|
||||
editor.ij.scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE)
|
||||
return foundPosition?.let { TextRange(foundPosition, foundPosition + 2) }
|
||||
}
|
||||
}
|
||||
|
||||
private enum class Direction(val offset: Int) {
|
||||
FORWARD(1) {
|
||||
override fun findBiChar(
|
||||
editor: VimEditor,
|
||||
charSequence: CharSequence,
|
||||
position: Int,
|
||||
charone: Char,
|
||||
chartwo: Char
|
||||
): Int? {
|
||||
for (i in (position + offset) until charSequence.length - 1) {
|
||||
if (matches(editor, charSequence, i, charone, chartwo)) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
},
|
||||
BACKWARD(-1) {
|
||||
override fun findBiChar(
|
||||
editor: VimEditor,
|
||||
charSequence: CharSequence,
|
||||
position: Int,
|
||||
charone: Char,
|
||||
chartwo: Char
|
||||
): Int? {
|
||||
for (i in (position + offset) downTo 0) {
|
||||
if (matches(editor, charSequence, i, charone, chartwo)) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
abstract fun findBiChar(
|
||||
editor: VimEditor,
|
||||
charSequence: CharSequence,
|
||||
position: Int,
|
||||
charone: Char,
|
||||
chartwo: Char,
|
||||
): Int?
|
||||
|
||||
fun matches(
|
||||
editor: VimEditor,
|
||||
charSequence: CharSequence,
|
||||
charPosition: Int,
|
||||
charOne: Char,
|
||||
charTwo: Char,
|
||||
): Boolean {
|
||||
var match = charSequence[charPosition].equals(charOne, ignoreCase = injector.options(editor).ignorecase) &&
|
||||
charSequence[charPosition + 1].equals(charTwo, ignoreCase = injector.options(editor).ignorecase)
|
||||
|
||||
if (injector.options(editor).ignorecase && injector.options(editor).smartcase) {
|
||||
if (charOne.isUpperCase() || charTwo.isUpperCase()) {
|
||||
match = charSequence[charPosition].equals(charOne, ignoreCase = false) &&
|
||||
charSequence[charPosition + 1].equals(charTwo, ignoreCase = false)
|
||||
}
|
||||
}
|
||||
return match
|
||||
}
|
||||
}
|
||||
|
||||
private enum class RepeatDirection(val symb: String) {
|
||||
IDENTICAL(";") {
|
||||
override fun map(direction: Direction): Direction = direction
|
||||
},
|
||||
REVERSE(",") {
|
||||
override fun map(direction: Direction): Direction = when (direction) {
|
||||
Direction.FORWARD -> Direction.BACKWARD
|
||||
Direction.BACKWARD -> Direction.FORWARD
|
||||
}
|
||||
};
|
||||
|
||||
abstract fun map(direction: Direction): Direction
|
||||
}
|
||||
|
||||
private class HighlightHandler {
|
||||
private var editor: Editor? = null
|
||||
private val sneakHighlighters: MutableSet<RangeHighlighter> = mutableSetOf()
|
||||
|
||||
fun highlightSneakRange(editor: Editor, range: TextRange) {
|
||||
clearAllSneakHighlighters()
|
||||
|
||||
this.editor = editor
|
||||
val project = editor.project
|
||||
if (project != null) {
|
||||
Disposer.register(VimProjectService.getInstance(project)) {
|
||||
this.editor = null
|
||||
sneakHighlighters.clear()
|
||||
}
|
||||
}
|
||||
|
||||
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 clearAllSneakHighlighters() {
|
||||
sneakHighlighters.forEach { highlighter ->
|
||||
editor?.markupModel?.removeHighlighter(highlighter) ?: StrictMode.fail("Highlighters without an editor")
|
||||
}
|
||||
|
||||
sneakHighlighters.clear()
|
||||
}
|
||||
|
||||
private fun highlightSingleRange(editor: Editor, range: ClosedRange<Int>) {
|
||||
val highlighter = editor.markupModel.addRangeHighlighter(
|
||||
range.start,
|
||||
range.endInclusive,
|
||||
HighlighterLayer.SELECTION,
|
||||
getHighlightTextAttributes(),
|
||||
HighlighterTargetArea.EXACT_RANGE
|
||||
)
|
||||
|
||||
sneakHighlighters.add(highlighter)
|
||||
|
||||
setClearHighlightRangeTimer(highlighter)
|
||||
}
|
||||
|
||||
private fun setClearHighlightRangeTimer(highlighter: RangeHighlighter) {
|
||||
val timer = Timer(DEFAULT_HIGHLIGHT_DURATION_SNEAK) {
|
||||
if (editor?.isDisposed != true) {
|
||||
editor?.markupModel?.removeHighlighter(highlighter)
|
||||
}
|
||||
}
|
||||
timer.isRepeats = false
|
||||
timer.start()
|
||||
}
|
||||
|
||||
private fun getHighlightTextAttributes() = TextAttributes(
|
||||
null,
|
||||
EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES.defaultAttributes.backgroundColor,
|
||||
editor?.colorsScheme?.getColor(EditorColors.CARET_COLOR),
|
||||
EffectType.SEARCH_MATCH,
|
||||
Font.PLAIN
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map some <Plug>(keys) command to given handler
|
||||
* and create mapping to <Plug>(prefix)[keys]
|
||||
*/
|
||||
private fun VimExtension.mapToFunctionAndProvideKeys(keys: String, handler: ExtensionHandler) {
|
||||
VimExtensionFacade.putExtensionHandlerMapping(
|
||||
MappingMode.NXO,
|
||||
injector.parser.parseKeys(command(keys)),
|
||||
owner,
|
||||
handler,
|
||||
false
|
||||
)
|
||||
VimExtensionFacade.putExtensionHandlerMapping(
|
||||
MappingMode.NXO,
|
||||
injector.parser.parseKeys(commandFromOriginalPlugin(keys)),
|
||||
owner,
|
||||
handler,
|
||||
false
|
||||
)
|
||||
|
||||
// This is a combination to meet the following requirements:
|
||||
// - Now we should support mappings from sneak `Sneak_s` and mappings from the previous version of the plugin `(sneak-s)`
|
||||
// - 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()) {
|
||||
VimPlugin.getKey().hasmapto(it, injector.parser.parseKeys(command(keys)))
|
||||
}
|
||||
val filteredModes2 = MappingMode.NXO.filterNotTo(HashSet()) {
|
||||
VimPlugin.getKey().hasmapto(it, injector.parser.parseKeys(commandFromOriginalPlugin(keys)))
|
||||
}
|
||||
val filteredFromModes = MappingMode.NXO.filterNotTo(HashSet()) {
|
||||
injector.keyGroup.hasmapfrom(it, fromKeys)
|
||||
}
|
||||
|
||||
val doubleFiltered = MappingMode.NXO
|
||||
.filter { it in filteredModes2 && it in filteredModes && it in filteredFromModes }
|
||||
.toSet()
|
||||
putKeyMapping(doubleFiltered, fromKeys, owner, injector.parser.parseKeys(command(keys)), true)
|
||||
putKeyMapping(
|
||||
doubleFiltered,
|
||||
fromKeys,
|
||||
owner,
|
||||
injector.parser.parseKeys(commandFromOriginalPlugin(keys)),
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
private fun command(keys: String) = "<Plug>(sneak-$keys)"
|
||||
private fun commandFromOriginalPlugin(keys: String) = "<Plug>Sneak_$keys"
|
@@ -8,7 +8,6 @@
|
||||
package com.maddyhome.idea.vim.extension.surround
|
||||
|
||||
import com.intellij.openapi.application.runWriteAction
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
@@ -256,7 +255,6 @@ internal class VimSurroundExtension : VimExtension {
|
||||
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
|
||||
// Deleting surround is just changing the surrounding to "nothing"
|
||||
val charFrom = getChar(editor.ij)
|
||||
LOG.debug("DSurroundHandler: charFrom = $charFrom")
|
||||
if (charFrom.code == 0) return
|
||||
|
||||
runWriteAction { CSurroundHandler.change(editor, context, charFrom, null) }
|
||||
@@ -309,101 +307,96 @@ internal class VimSurroundExtension : VimExtension {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val LOG = logger<VimSurroundExtension>()
|
||||
companion object {
|
||||
private const val REGISTER = '"'
|
||||
|
||||
private const val REGISTER = '"'
|
||||
private val tagNameAndAttributesCapturePattern = "(\\S+)([^>]*)>".toPattern()
|
||||
|
||||
private val tagNameAndAttributesCapturePattern = "(\\S+)([^>]*)>".toPattern()
|
||||
|
||||
private val SURROUND_PAIRS = mapOf(
|
||||
'b' to ("(" to ")"),
|
||||
'(' to ("( " to " )"),
|
||||
')' to ("(" to ")"),
|
||||
'B' to ("{" to "}"),
|
||||
'{' to ("{ " to " }"),
|
||||
'}' to ("{" to "}"),
|
||||
'r' to ("[" to "]"),
|
||||
'[' to ("[ " to " ]"),
|
||||
']' to ("[" to "]"),
|
||||
'a' to ("<" to ">"),
|
||||
'>' to ("<" to ">"),
|
||||
's' to (" " to ""),
|
||||
)
|
||||
|
||||
private fun getSurroundPair(c: Char): Pair<String, String>? = if (c in SURROUND_PAIRS) {
|
||||
SURROUND_PAIRS[c]
|
||||
} else if (!c.isLetter()) {
|
||||
val s = c.toString()
|
||||
s to s
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
private fun inputTagPair(editor: Editor): Pair<String, String>? {
|
||||
val tagInput = inputString(editor, "<", '>')
|
||||
val matcher = tagNameAndAttributesCapturePattern.matcher(tagInput)
|
||||
return if (matcher.find()) {
|
||||
val tagName = matcher.group(1)
|
||||
val tagAttributes = matcher.group(2)
|
||||
"<$tagName$tagAttributes>" to "</$tagName>"
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun inputFunctionName(
|
||||
editor: Editor,
|
||||
withInternalSpaces: Boolean,
|
||||
): Pair<String, String>? {
|
||||
val functionNameInput = inputString(editor, "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)
|
||||
else -> getSurroundPair(c)
|
||||
}
|
||||
|
||||
private fun getChar(editor: Editor): Char {
|
||||
val key = inputKeyStroke(editor)
|
||||
val keyChar = key.keyChar
|
||||
val res = if (keyChar == KeyEvent.CHAR_UNDEFINED || keyChar.code == KeyEvent.VK_ESCAPE) {
|
||||
0.toChar()
|
||||
} else {
|
||||
keyChar
|
||||
}
|
||||
LOG.trace("getChar: $res")
|
||||
return res
|
||||
}
|
||||
|
||||
private fun performSurround(pair: Pair<String, String>, range: TextRange, caret: VimCaret, count: Int, tagsOnNewLines: Boolean = false) {
|
||||
runWriteAction {
|
||||
val editor = caret.editor
|
||||
val change = VimPlugin.getChange()
|
||||
val leftSurround = RepeatedCharSequence.of(pair.first + if (tagsOnNewLines) "\n" else "", count)
|
||||
|
||||
val isEOF = range.endOffset == editor.text().length
|
||||
val hasNewLine = editor.endsWithNewLine()
|
||||
val rightSurround = (if (tagsOnNewLines) {
|
||||
if (isEOF && !hasNewLine) {
|
||||
"\n" + pair.second
|
||||
} else {
|
||||
pair.second + "\n"
|
||||
}
|
||||
} else {
|
||||
pair.second
|
||||
}).let { RepeatedCharSequence.of(it, count) }
|
||||
|
||||
change.insertText(editor, caret, range.startOffset, leftSurround)
|
||||
change.insertText(editor, caret, range.endOffset + leftSurround.length, rightSurround)
|
||||
injector.markService.setChangeMarks(
|
||||
caret,
|
||||
TextRange(range.startOffset, range.endOffset + leftSurround.length + rightSurround.length)
|
||||
private val SURROUND_PAIRS = mapOf(
|
||||
'b' to ("(" to ")"),
|
||||
'(' to ("( " to " )"),
|
||||
')' to ("(" to ")"),
|
||||
'B' to ("{" to "}"),
|
||||
'{' to ("{ " to " }"),
|
||||
'}' to ("{" to "}"),
|
||||
'r' to ("[" to "]"),
|
||||
'[' to ("[ " to " ]"),
|
||||
']' to ("[" to "]"),
|
||||
'a' to ("<" to ">"),
|
||||
'>' to ("<" to ">"),
|
||||
's' to (" " to ""),
|
||||
)
|
||||
|
||||
private fun getSurroundPair(c: Char): Pair<String, String>? = if (c in SURROUND_PAIRS) {
|
||||
SURROUND_PAIRS[c]
|
||||
} else if (!c.isLetter()) {
|
||||
val s = c.toString()
|
||||
s to s
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
private fun inputTagPair(editor: Editor): Pair<String, String>? {
|
||||
val tagInput = inputString(editor, "<", '>')
|
||||
val matcher = tagNameAndAttributesCapturePattern.matcher(tagInput)
|
||||
return if (matcher.find()) {
|
||||
val tagName = matcher.group(1)
|
||||
val tagAttributes = matcher.group(2)
|
||||
"<$tagName$tagAttributes>" to "</$tagName>"
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun inputFunctionName(
|
||||
editor: Editor,
|
||||
withInternalSpaces: Boolean,
|
||||
): Pair<String, String>? {
|
||||
val functionNameInput = inputString(editor, "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)
|
||||
else -> getSurroundPair(c)
|
||||
}
|
||||
|
||||
private fun getChar(editor: Editor): Char {
|
||||
val key = inputKeyStroke(editor)
|
||||
val keyChar = key.keyChar
|
||||
return if (keyChar == KeyEvent.CHAR_UNDEFINED || keyChar.code == KeyEvent.VK_ESCAPE) {
|
||||
0.toChar()
|
||||
} else {
|
||||
keyChar
|
||||
}
|
||||
}
|
||||
|
||||
private fun performSurround(pair: Pair<String, String>, range: TextRange, caret: VimCaret, count: Int, tagsOnNewLines: Boolean = false) {
|
||||
runWriteAction {
|
||||
val editor = caret.editor
|
||||
val change = VimPlugin.getChange()
|
||||
val leftSurround = RepeatedCharSequence.of(pair.first + if (tagsOnNewLines) "\n" else "", count)
|
||||
|
||||
val isEOF = range.endOffset == editor.text().length
|
||||
val hasNewLine = editor.endsWithNewLine()
|
||||
val rightSurround = (if (tagsOnNewLines) {
|
||||
if (isEOF && !hasNewLine) {
|
||||
"\n" + pair.second
|
||||
} else {
|
||||
pair.second + "\n"
|
||||
}
|
||||
} else {
|
||||
pair.second
|
||||
}).let { RepeatedCharSequence.of(it, count) }
|
||||
|
||||
change.insertText(editor, caret, range.startOffset, leftSurround)
|
||||
change.insertText(editor, caret, range.endOffset + leftSurround.length, rightSurround)
|
||||
injector.markService.setChangeMarks(caret, TextRange(range.startOffset, range.endOffset + leftSurround.length + rightSurround.length))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,9 @@ import com.intellij.openapi.editor.actions.EnterAction
|
||||
import com.intellij.openapi.editor.event.EditorMouseEvent
|
||||
import com.intellij.openapi.editor.event.EditorMouseListener
|
||||
import com.intellij.openapi.editor.impl.TextRangeInterval
|
||||
import com.intellij.openapi.ui.MessageType
|
||||
import com.intellij.openapi.ui.popup.Balloon
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory
|
||||
import com.intellij.openapi.util.UserDataHolder
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager
|
||||
@@ -62,6 +65,7 @@ import com.maddyhome.idea.vim.helper.endOffsetInclusive
|
||||
import com.maddyhome.idea.vim.helper.inInsertMode
|
||||
import com.maddyhome.idea.vim.helper.moveToInlayAwareLogicalPosition
|
||||
import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset
|
||||
import com.maddyhome.idea.vim.icons.VimIcons
|
||||
import com.maddyhome.idea.vim.key.KeyHandlerKeeper.Companion.getInstance
|
||||
import com.maddyhome.idea.vim.listener.VimInsertListener
|
||||
import com.maddyhome.idea.vim.newapi.IjEditorExecutionContext
|
||||
@@ -78,12 +82,14 @@ import java.math.BigInteger
|
||||
import java.util.*
|
||||
import java.util.function.Consumer
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
* Provides all the insert/replace related functionality
|
||||
*/
|
||||
public class ChangeGroup : VimChangeGroupBase() {
|
||||
private val insertListeners = ContainerUtil.createLockFreeCopyOnWriteList<VimInsertListener>()
|
||||
private var lastShownTime = 0L
|
||||
private val listener: EditorMouseListener = object : EditorMouseListener {
|
||||
override fun mouseClicked(event: EditorMouseEvent) {
|
||||
val editor = event.editor
|
||||
@@ -97,6 +103,10 @@ public class ChangeGroup : VimChangeGroupBase() {
|
||||
EventFacade.getInstance().addEditorMouseListener(editor!!, listener, disposable)
|
||||
}
|
||||
|
||||
public fun editorReleased(editor: Editor?) {
|
||||
EventFacade.getInstance().removeEditorMouseListener(editor!!, listener)
|
||||
}
|
||||
|
||||
override fun type(vimEditor: VimEditor, context: ExecutionContext, key: Char) {
|
||||
val editor = (vimEditor as IjVimEditor).editor
|
||||
val ijContext = context.ij
|
||||
@@ -394,7 +404,6 @@ public class ChangeGroup : VimChangeGroupBase() {
|
||||
context: ExecutionContext,
|
||||
range: TextRange,
|
||||
) {
|
||||
val startPos = editor.offsetToBufferPosition(caret.offset.point)
|
||||
val startOffset = editor.getLineStartForOffset(range.startOffset)
|
||||
val endOffset = editor.getLineEndForOffset(range.endOffset)
|
||||
val ijEditor = (editor as IjVimEditor).editor
|
||||
@@ -419,7 +428,11 @@ public class ChangeGroup : VimChangeGroupBase() {
|
||||
}
|
||||
}
|
||||
val afterAction = {
|
||||
caret.moveToOffset(injector.motion.moveCaretToLineStartSkipLeading(editor, startPos.line))
|
||||
val firstLine = editor.offsetToBufferPosition(
|
||||
min(startOffset.toDouble(), endOffset.toDouble()).toInt()
|
||||
).line
|
||||
val newOffset = injector.motion.moveCaretToLineStartSkipLeading(editor, firstLine)
|
||||
caret.moveToOffset(newOffset)
|
||||
restoreCursor(editor, caret, (caret as IjVimCaret).caret.logicalPosition.line)
|
||||
}
|
||||
if (project != null) {
|
||||
@@ -531,7 +544,7 @@ public class ChangeGroup : VimChangeGroupBase() {
|
||||
val soff = editor.getLineStartOffset(l)
|
||||
val eoff = editor.getLineEndOffset(l, true)
|
||||
val woff = injector.motion.moveCaretToLineStartSkipLeading(editor, l)
|
||||
val col = editor.offsetToBufferPosition(woff).column
|
||||
val col = editor.offsetToVisualPosition(woff).column
|
||||
val limit = max(0.0, (col + dir * indentConfig.getTotalIndent(count)).toDouble())
|
||||
.toInt()
|
||||
if (col > 0 || soff != eoff) {
|
||||
@@ -632,6 +645,25 @@ public class ChangeGroup : VimChangeGroupBase() {
|
||||
avalanche: Boolean,
|
||||
): Boolean {
|
||||
|
||||
// Just an easter egg
|
||||
if (avalanche) {
|
||||
val currentTime = System.currentTimeMillis()
|
||||
if (currentTime - lastShownTime > 60000) {
|
||||
lastShownTime = currentTime
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
val balloon = JBPopupFactory.getInstance()
|
||||
.createHtmlTextBalloonBuilder(
|
||||
"Wow, nice vim skills!", VimIcons.IDEAVIM,
|
||||
MessageType.INFO.titleForeground, MessageType.INFO.popupBackground,
|
||||
null
|
||||
).createBalloon()
|
||||
balloon.show(
|
||||
JBPopupFactory.getInstance().guessBestPopupLocation((editor as IjVimEditor).editor),
|
||||
Balloon.Position.below
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
val nf: List<String> = injector.options(editor).nrformats
|
||||
val alpha = nf.contains("alpha")
|
||||
val hex = nf.contains("hex")
|
||||
|
@@ -29,7 +29,6 @@ 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 oldundo: Boolean by optionProperty(IjOptions.oldundo)
|
||||
@@ -37,7 +36,6 @@ public open class GlobalIjOptions(scope: OptionAccessScope) : OptionsPropertiesB
|
||||
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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -86,8 +86,6 @@ public object IjOptions {
|
||||
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))
|
||||
|
||||
// This needs to be Option<out VimDataType> so that it can work with derived option types, such as NumberOption, which
|
||||
// derives from Option<VimInt>
|
||||
|
@@ -24,14 +24,17 @@ import com.intellij.openapi.keymap.KeymapManager;
|
||||
import com.intellij.openapi.keymap.ex.KeymapManagerEx;
|
||||
import com.maddyhome.idea.vim.EventFacade;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.action.ComplicatedKeysAction;
|
||||
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.command.MappingMode;
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel;
|
||||
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase;
|
||||
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.IjVimActionsInitiator;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import kotlin.Pair;
|
||||
import kotlin.text.StringsKt;
|
||||
@@ -46,7 +49,6 @@ import java.awt.event.KeyEvent;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import static com.maddyhome.idea.vim.api.VimInjectorKt.injector;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
/**
|
||||
@@ -219,20 +221,63 @@ public class KeyGroup extends VimKeyGroupBase implements PersistentStateComponen
|
||||
registerRequiredShortcut(keyStrokes, MappingOwner.IdeaVim.System.INSTANCE);
|
||||
|
||||
for (MappingMode mappingMode : command.getModes()) {
|
||||
Node<LazyVimCommand> node = getKeyRoot(mappingMode);
|
||||
Node<VimActionsInitiator> node = getKeyRoot(mappingMode);
|
||||
NodesKt.addLeafs(node, keyStrokes, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void registerCommandAction(@NotNull VimActionsInitiator actionHolder) {
|
||||
IjVimActionsInitiator holder = (IjVimActionsInitiator)actionHolder;
|
||||
|
||||
if (!VimPlugin.getPluginId().equals(holder.getBean().getPluginDescriptor().getPluginId())) {
|
||||
logger.error("IdeaVim doesn't accept contributions to `vimActions` extension points. " +
|
||||
"Please create a plugin using `VimExtension`. " +
|
||||
"Plugin to blame: " +
|
||||
holder.getBean().getPluginDescriptor().getPluginId());
|
||||
return;
|
||||
}
|
||||
|
||||
Set<List<KeyStroke>> actionKeys = holder.getBean().getParsedKeys();
|
||||
if (actionKeys == null) {
|
||||
final EditorActionHandlerBase action = actionHolder.getInstance();
|
||||
if (action instanceof ComplicatedKeysAction) {
|
||||
actionKeys = ((ComplicatedKeysAction)action).getKeyStrokesSet();
|
||||
}
|
||||
else {
|
||||
throw new RuntimeException("Cannot register action: " + action.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
Set<MappingMode> actionModes = holder.getBean().getParsedModes();
|
||||
if (actionModes == null) {
|
||||
throw new RuntimeException("Cannot register action: " + holder.getBean().getImplementation());
|
||||
}
|
||||
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
initIdentityChecker();
|
||||
for (List<KeyStroke> keys : actionKeys) {
|
||||
checkCommand(actionModes, actionHolder.getInstance(), keys);
|
||||
}
|
||||
}
|
||||
|
||||
for (List<KeyStroke> keyStrokes : actionKeys) {
|
||||
registerRequiredShortcut(keyStrokes, MappingOwner.IdeaVim.System.INSTANCE);
|
||||
|
||||
for (MappingMode mappingMode : actionModes) {
|
||||
Node<VimActionsInitiator> node = getKeyRoot(mappingMode);
|
||||
NodesKt.addLeafs(node, keyStrokes, actionHolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void registerRequiredShortcut(@NotNull List<KeyStroke> keys, MappingOwner owner) {
|
||||
for (KeyStroke key : keys) {
|
||||
if (key.getKeyChar() == KeyEvent.CHAR_UNDEFINED) {
|
||||
if (!injector.getOptionGroup().getGlobalOptions().getOctopushandler() ||
|
||||
!(key.getKeyCode() == KeyEvent.VK_ESCAPE && key.getModifiers() == 0) &&
|
||||
!(key.getKeyCode() == KeyEvent.VK_ENTER && key.getModifiers() == 0)) {
|
||||
getRequiredShortcutKeys().add(new RequiredShortcut(key, owner));
|
||||
}
|
||||
if (key.getKeyChar() == KeyEvent.CHAR_UNDEFINED &&
|
||||
key.getKeyCode() != KeyEvent.VK_ESCAPE &&
|
||||
key.getKeyCode() != KeyEvent.VK_ENTER) {
|
||||
getRequiredShortcutKeys().add(new RequiredShortcut(key, owner));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,68 +0,0 @@
|
||||
package com.maddyhome.idea.vim.group
|
||||
|
||||
import com.intellij.codeInsight.daemon.ReferenceImporter
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.ReadAction
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||
import com.intellij.openapi.progress.ProgressIndicator
|
||||
import com.intellij.openapi.progress.ProgressManager
|
||||
import com.intellij.openapi.progress.Task
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiRecursiveElementWalkingVisitor
|
||||
import java.util.function.BooleanSupplier
|
||||
|
||||
internal object MacroAutoImport {
|
||||
fun run(editor: Editor, dataContext: DataContext) {
|
||||
val project = CommonDataKeys.PROJECT.getData(dataContext) ?: return
|
||||
val file = PsiDocumentManager.getInstance(project).getPsiFile(editor.document) ?: return
|
||||
|
||||
if (!FileDocumentManager.getInstance().requestWriting(editor.document, project)) {
|
||||
return
|
||||
}
|
||||
|
||||
val importers = ReferenceImporter.EP_NAME.extensionList
|
||||
if (importers.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
ProgressManager.getInstance().run(object : Task.Backgroundable(project, "Auto import", true) {
|
||||
override fun run(indicator: ProgressIndicator) {
|
||||
val fixes = ReadAction.nonBlocking<List<BooleanSupplier>> {
|
||||
val fixes = mutableListOf<BooleanSupplier>()
|
||||
|
||||
file.accept(object : PsiRecursiveElementWalkingVisitor() {
|
||||
override fun visitElement(element: PsiElement) {
|
||||
for (reference in element.references) {
|
||||
if (reference.resolve() != null) {
|
||||
continue
|
||||
}
|
||||
for (importer in importers) {
|
||||
importer.computeAutoImportAtOffset(editor, file, element.textRange.startOffset, true)
|
||||
?.let(fixes::add)
|
||||
}
|
||||
}
|
||||
super.visitElement(element)
|
||||
}
|
||||
})
|
||||
|
||||
return@nonBlocking fixes
|
||||
}.executeSynchronously()
|
||||
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
WriteCommandAction.writeCommandAction(project)
|
||||
.withName("Auto Import")
|
||||
.withGroupId("IdeaVimAutoImportAfterMacro")
|
||||
.shouldRecordActionForActiveDocument(true)
|
||||
.run<RuntimeException> {
|
||||
fixes.forEach { it.asBoolean }
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@@ -7,8 +7,6 @@
|
||||
*/
|
||||
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.diagnostic.logger
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
@@ -21,7 +19,6 @@ import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.helper.MessageHelper.message
|
||||
import com.maddyhome.idea.vim.macro.VimMacroBase
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
|
||||
/**
|
||||
* Used to handle playback of macros
|
||||
@@ -64,36 +61,22 @@ internal class MacroGroup : VimMacroBase() {
|
||||
try {
|
||||
myPotemkinProgress.text2 = if (isInternalMacro) "Executing internal macro" else ""
|
||||
val runnable = runnable@{
|
||||
try {
|
||||
// Handle one keystroke then queue up the next key
|
||||
for (i in 0 until total) {
|
||||
// Handle one keystroke then queue up the next key
|
||||
for (i in 0 until total) {
|
||||
myPotemkinProgress.fraction = (i + 1).toDouble() / total
|
||||
while (keyStack.hasStroke()) {
|
||||
val key = keyStack.feedStroke()
|
||||
try {
|
||||
myPotemkinProgress.fraction = (i + 1).toDouble() / total
|
||||
while (keyStack.hasStroke()) {
|
||||
val key = keyStack.feedStroke()
|
||||
try {
|
||||
myPotemkinProgress.checkCanceled()
|
||||
} catch (e: ProcessCanceledException) {
|
||||
return@runnable
|
||||
}
|
||||
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)
|
||||
}
|
||||
if (injector.messages.isError()) return@runnable
|
||||
}
|
||||
} finally {
|
||||
keyStack.resetFirst()
|
||||
myPotemkinProgress.checkCanceled()
|
||||
} catch (e: ProcessCanceledException) {
|
||||
return@runnable
|
||||
}
|
||||
ProgressManager.getInstance().executeNonCancelableSection { getInstance().handleKey(editor, key, context) }
|
||||
if (injector.messages.isError()) return@runnable
|
||||
}
|
||||
} finally {
|
||||
keyStack.removeFirst()
|
||||
}
|
||||
if (!isInternalMacro) {
|
||||
MacroAutoImport.run(editor.ij, context.ij)
|
||||
keyStack.resetFirst()
|
||||
}
|
||||
keyStack.removeFirst()
|
||||
}
|
||||
|
||||
if (isInternalMacro) {
|
||||
|
138
src/main/java/com/maddyhome/idea/vim/group/MarkGroup.java
Executable file
138
src/main/java/com/maddyhome/idea/vim/group/MarkGroup.java
Executable file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* 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.group;
|
||||
|
||||
import com.intellij.ide.bookmark.LineBookmark;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.maddyhome.idea.vim.api.*;
|
||||
import com.maddyhome.idea.vim.common.TextRange;
|
||||
import com.maddyhome.idea.vim.mark.IntellijMark;
|
||||
import com.maddyhome.idea.vim.mark.Jump;
|
||||
import com.maddyhome.idea.vim.mark.Mark;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Deprecated
|
||||
@ApiStatus.ScheduledForRemoval(inVersion = "2.3")
|
||||
public class MarkGroup {
|
||||
public List<Jump> jumps = VimInjectorKt.injector.getJumpService().getJumps("");
|
||||
|
||||
public void saveJumpLocation(@NotNull Editor editor) {
|
||||
VimInjectorKt.injector.getJumpService().saveJumpLocation(new IjVimEditor(editor));
|
||||
}
|
||||
|
||||
public void saveJumpLocation(@NotNull VimEditor editor) {
|
||||
VimInjectorKt.injector.getJumpService().saveJumpLocation(editor);
|
||||
}
|
||||
|
||||
public void setChangeMarks(@NotNull VimEditor vimEditor, @NotNull TextRange range) {
|
||||
VimMarkService markService = VimInjectorKt.injector.getMarkService();
|
||||
VimMarkServiceKt.setChangeMarks(markService, vimEditor.primaryCaret(), range);
|
||||
}
|
||||
|
||||
public void addJump(@NotNull VimEditor editor, boolean reset) {
|
||||
VimJumpServiceKt.addJump(VimInjectorKt.injector.getJumpService(), editor, reset);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Mark getMark(@NotNull VimEditor editor, char ch) {
|
||||
return VimInjectorKt.injector.getMarkService().getMark(editor.primaryCaret(), ch);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Jump getJump(int count) {
|
||||
return VimInjectorKt.injector.getJumpService().getJump("", count);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Mark createSystemMark(char ch, int line, int col, @NotNull VimEditor editor) {
|
||||
Editor ijEditor = ((IjVimEditor)editor).getEditor();
|
||||
@Nullable LineBookmark systemMark = SystemMarks.createOrGetSystemMark(ch, line, ijEditor);
|
||||
if (systemMark == null) {
|
||||
return null;
|
||||
}
|
||||
return new IntellijMark(systemMark, col, ijEditor.getProject());
|
||||
}
|
||||
|
||||
public boolean setMark(@NotNull VimEditor editor, char ch, int offset) {
|
||||
return VimInjectorKt.injector.getMarkService().setMark(editor.primaryCaret(), ch, offset);
|
||||
}
|
||||
|
||||
public boolean setMark(@NotNull VimEditor editor, char ch) {
|
||||
return VimInjectorKt.injector.getMarkService().setMark(editor, ch);
|
||||
}
|
||||
|
||||
public void includeCurrentCommandAsNavigation(@NotNull VimEditor editor) {
|
||||
VimInjectorKt.injector.getJumpService().includeCurrentCommandAsNavigation(editor);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Mark getFileMark(@NotNull VimEditor editor, char ch) {
|
||||
return VimInjectorKt.injector.getMarkService().getMark(editor.primaryCaret(), ch);
|
||||
}
|
||||
|
||||
public void setVisualSelectionMarks(@NotNull VimEditor editor, @NotNull TextRange range) {
|
||||
VimMarkService markService = VimInjectorKt.injector.getMarkService();
|
||||
VimMarkServiceKt.setVisualSelectionMarks(markService, editor.primaryCaret(), range);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TextRange getChangeMarks(@NotNull VimEditor editor) {
|
||||
return VimInjectorKt.injector.getMarkService().getChangeMarks(editor.primaryCaret());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TextRange getVisualSelectionMarks(@NotNull VimEditor editor) {
|
||||
return VimInjectorKt.injector.getMarkService().getVisualSelectionMarks(editor.primaryCaret());
|
||||
}
|
||||
|
||||
public void resetAllMarks() {
|
||||
VimInjectorKt.injector.getMarkService().resetAllMarks();
|
||||
}
|
||||
|
||||
public void removeMark(char ch, @NotNull Mark mark) {
|
||||
VimInjectorKt.injector.getMarkService().removeMark(ch, mark);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<Mark> getMarks(@NotNull VimEditor editor) {
|
||||
Set<Mark> marks = VimInjectorKt.injector.getMarkService().getAllLocalMarks(editor.primaryCaret());
|
||||
marks.addAll(VimInjectorKt.injector.getMarkService().getGlobalMarks(editor));
|
||||
return new ArrayList<>(marks);
|
||||
}
|
||||
|
||||
public int getJumpSpot() {
|
||||
return VimInjectorKt.injector.getJumpService().getJumpSpot("");
|
||||
}
|
||||
|
||||
public void updateMarkFromDelete(@Nullable VimEditor editor,
|
||||
@Nullable HashMap<Character, Mark> marks,
|
||||
int delStartOff,
|
||||
int delLength) {
|
||||
VimInjectorKt.injector.getMarkService().updateMarksFromDelete(editor, delStartOff, delLength);
|
||||
}
|
||||
|
||||
public void updateMarkFromInsert(@Nullable VimEditor editor,
|
||||
@Nullable HashMap<Character, Mark> marks,
|
||||
int insStartOff,
|
||||
int insLength) {
|
||||
VimInjectorKt.injector.getMarkService().updateMarksFromInsert(editor, insStartOff, insLength);
|
||||
}
|
||||
|
||||
public void dropLastJump() {
|
||||
VimInjectorKt.injector.getJumpService().dropLastJump("");
|
||||
}
|
||||
}
|
@@ -48,7 +48,9 @@ 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
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.state.VimStateMachine
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel
|
||||
import com.maddyhome.idea.vim.handler.Motion
|
||||
@@ -72,8 +74,6 @@ 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
|
||||
@@ -461,13 +461,11 @@ internal class MotionGroup : VimMotionGroupBase() {
|
||||
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)
|
||||
}
|
||||
ExOutputModel.getInstance(editor).clear()
|
||||
editor.vim.let { vimEditor ->
|
||||
if (VimStateMachine.getInstance(vimEditor).mode is Mode.VISUAL) {
|
||||
vimEditor.exitVisualMode()
|
||||
KeyHandler.getInstance().reset(vimEditor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,11 +21,8 @@ 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.diagnostic.logger
|
||||
import com.intellij.openapi.ide.CopyPasteManager
|
||||
import com.intellij.openapi.keymap.KeymapUtil
|
||||
import com.intellij.openapi.keymap.ex.KeymapManagerEx
|
||||
import com.intellij.openapi.keymap.impl.ui.KeymapPanel
|
||||
import com.intellij.openapi.options.ShowSettingsUtil
|
||||
import com.intellij.openapi.project.DumbAwareAction
|
||||
import com.intellij.openapi.project.Project
|
||||
@@ -35,7 +32,6 @@ 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.handler.KeyMapIssue
|
||||
import com.maddyhome.idea.vim.helper.MessageHelper
|
||||
import com.maddyhome.idea.vim.key.ShortcutOwner
|
||||
import com.maddyhome.idea.vim.key.ShortcutOwnerInfo
|
||||
@@ -184,77 +180,6 @@ internal class NotificationService(private val project: Project?) {
|
||||
ActionIdNotifier.notifyActionId(id, project)
|
||||
}
|
||||
|
||||
fun notifyKeymapIssues(issues: ArrayList<KeyMapIssue>) {
|
||||
val keymapManager = KeymapManagerEx.getInstanceEx()
|
||||
val keymap = keymapManager.activeKeymap
|
||||
val message = buildString {
|
||||
appendLine("Current IDE keymap (${keymap.name}) has issues:<br/>")
|
||||
issues.forEach {
|
||||
when (it) {
|
||||
is KeyMapIssue.AddShortcut -> {
|
||||
appendLine("- ${it.key} key is not assigned to the ${it.action} action.<br/>")
|
||||
}
|
||||
is KeyMapIssue.RemoveShortcut -> {
|
||||
appendLine("- ${it.shortcut} key is incorrectly assigned to the ${it.action} action.<br/>")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val notification = IDEAVIM_STICKY_GROUP.createNotification(
|
||||
IDEAVIM_NOTIFICATION_TITLE,
|
||||
message,
|
||||
NotificationType.ERROR,
|
||||
)
|
||||
notification.subtitle = "IDE keymap misconfigured"
|
||||
notification.addAction(object : DumbAwareAction("Fix Keymap") {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
issues.forEach {
|
||||
when (it) {
|
||||
is KeyMapIssue.AddShortcut -> {
|
||||
keymap.addShortcut(it.actionId, KeyboardShortcut(it.keyStroke, null))
|
||||
}
|
||||
|
||||
is KeyMapIssue.RemoveShortcut -> {
|
||||
keymap.removeShortcut(it.actionId, it.shortcut)
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG.info("Shortcuts updated $issues")
|
||||
notification.expire()
|
||||
requiredShortcutsAssigned()
|
||||
}
|
||||
})
|
||||
notification.addAction(object : DumbAwareAction("Open Keymap Settings") {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
ShowSettingsUtil.getInstance().showSettingsDialog(e.project, KeymapPanel::class.java)
|
||||
notification.hideBalloon()
|
||||
}
|
||||
})
|
||||
notification.addAction(object : DumbAwareAction("Ignore") {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
LOG.info("Ignored to update shortcuts $issues")
|
||||
notification.hideBalloon()
|
||||
}
|
||||
})
|
||||
notification.notify(project)
|
||||
}
|
||||
|
||||
private fun requiredShortcutsAssigned() {
|
||||
val notification = Notification(
|
||||
IDEAVIM_NOTIFICATION_ID,
|
||||
IDEAVIM_NOTIFICATION_TITLE,
|
||||
"Keymap fixed",
|
||||
NotificationType.INFORMATION,
|
||||
)
|
||||
notification.addAction(object : DumbAwareAction("Open Keymap Settings") {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
ShowSettingsUtil.getInstance().showSettingsDialog(e.project, KeymapPanel::class.java)
|
||||
notification.hideBalloon()
|
||||
}
|
||||
})
|
||||
notification.notify(project)
|
||||
}
|
||||
|
||||
object ActionIdNotifier {
|
||||
private var notification: Notification? = null
|
||||
private const val NO_ID = "<i>Cannot detect action id</i>"
|
||||
@@ -389,8 +314,6 @@ internal class NotificationService(private val project: Project?) {
|
||||
const val IDEAVIM_NOTIFICATION_TITLE = "IdeaVim"
|
||||
const val ideajoinExamplesUrl = "https://jb.gg/f9zji9"
|
||||
|
||||
private val LOG = logger<NotificationService>()
|
||||
|
||||
private fun createIdeaVimRcManually(message: String, project: Project?) {
|
||||
val notification =
|
||||
Notification(IDEAVIM_NOTIFICATION_ID, IDEAVIM_NOTIFICATION_TITLE, message, NotificationType.WARNING)
|
||||
|
@@ -40,6 +40,10 @@ internal class OptionGroup : VimOptionGroupBase(), IjVimOptionGroup {
|
||||
override fun getGlobalIjOptions() = GlobalIjOptions(OptionAccessScope.GLOBAL(null))
|
||||
override fun getEffectiveIjOptions(editor: VimEditor) = EffectiveIjOptions(OptionAccessScope.EFFECTIVE(editor))
|
||||
|
||||
private fun updateFallbackWindow(fallbackWindow: VimEditor, targetEditor: VimEditor) {
|
||||
copyPerWindowGlobalValues(fallbackWindow, targetEditor)
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun fileEditorManagerSelectionChangedCallback(event: FileEditorManagerEvent) {
|
||||
// Vim only has one window, and it's not possible to close it. This means that editing a new file will always
|
||||
@@ -54,8 +58,6 @@ internal class OptionGroup : VimOptionGroupBase(), IjVimOptionGroup {
|
||||
// Unfortunately, we can't reliably know if a closing editor is the selected editor. Instead, we rely on selection
|
||||
// change events. If an editor is losing selection and there is no new selection, we can assume this means that
|
||||
// the last editor has been closed, and use the closed editor to update the fallback window
|
||||
//
|
||||
// XXX: event.oldEditor will must probably return a disposed editor. So, it should be treated with care
|
||||
if (event.newEditor == null) {
|
||||
(event.oldEditor as? TextEditor)?.editor?.let {
|
||||
(VimPlugin.getOptionGroup() as OptionGroup).updateFallbackWindow(injector.fallbackWindow, it.vim)
|
||||
@@ -65,28 +67,28 @@ internal class OptionGroup : VimOptionGroupBase(), IjVimOptionGroup {
|
||||
}
|
||||
}
|
||||
|
||||
public class IjOptionConstants {
|
||||
@Suppress("SpellCheckingInspection", "MemberVisibilityCanBePrivate", "ConstPropertyName")
|
||||
public companion object {
|
||||
internal class IjOptionConstants {
|
||||
@Suppress("SpellCheckingInspection", "MemberVisibilityCanBePrivate")
|
||||
companion object {
|
||||
|
||||
public const val idearefactormode_keep: String = "keep"
|
||||
public const val idearefactormode_select: String = "select"
|
||||
public const val idearefactormode_visual: String = "visual"
|
||||
const val idearefactormode_keep = "keep"
|
||||
const val idearefactormode_select = "select"
|
||||
const val idearefactormode_visual = "visual"
|
||||
|
||||
public const val ideastatusicon_enabled: String = "enabled"
|
||||
public const val ideastatusicon_gray: String = "gray"
|
||||
public const val ideastatusicon_disabled: String = "disabled"
|
||||
const val ideastatusicon_enabled = "enabled"
|
||||
const val ideastatusicon_gray = "gray"
|
||||
const val ideastatusicon_disabled = "disabled"
|
||||
|
||||
public const val ideavimsupport_dialog: String = "dialog"
|
||||
public const val ideavimsupport_singleline: String = "singleline"
|
||||
public const val ideavimsupport_dialoglegacy: String = "dialoglegacy"
|
||||
const val ideavimsupport_dialog = "dialog"
|
||||
const val ideavimsupport_singleline = "singleline"
|
||||
const val ideavimsupport_dialoglegacy = "dialoglegacy"
|
||||
|
||||
public const val ideawrite_all: String = "all"
|
||||
public const val ideawrite_file: String = "file"
|
||||
const val ideawrite_all = "all"
|
||||
const val ideawrite_file = "file"
|
||||
|
||||
public val ideaStatusIconValues: Set<String> = setOf(ideastatusicon_enabled, ideastatusicon_gray, ideastatusicon_disabled)
|
||||
public val ideaRefactorModeValues: Set<String> = setOf(idearefactormode_keep, idearefactormode_select, idearefactormode_visual)
|
||||
public val ideaWriteValues: Set<String> = setOf(ideawrite_all, ideawrite_file)
|
||||
public val ideavimsupportValues: Set<String> = setOf(ideavimsupport_dialog, ideavimsupport_singleline, ideavimsupport_dialoglegacy)
|
||||
val ideaStatusIconValues = setOf(ideastatusicon_enabled, ideastatusicon_gray, ideastatusicon_disabled)
|
||||
val ideaRefactorModeValues = setOf(idearefactormode_keep, idearefactormode_select, idearefactormode_visual)
|
||||
val ideaWriteValues = setOf(ideawrite_all, ideawrite_file)
|
||||
val ideavimsupportValues = setOf(ideavimsupport_dialog, ideavimsupport_singleline, ideavimsupport_dialoglegacy)
|
||||
}
|
||||
}
|
||||
|
285
src/main/java/com/maddyhome/idea/vim/group/ProcessGroup.java
Normal file
285
src/main/java/com/maddyhome/idea/vim/group/ProcessGroup.java
Normal file
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
* 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.group;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
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.execution.process.ProcessOutput;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressIndicatorProvider;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.util.execution.ParametersListUtil;
|
||||
import com.intellij.util.text.CharSequenceReader;
|
||||
import com.maddyhome.idea.vim.KeyHandler;
|
||||
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.VimInjectorKt;
|
||||
import com.maddyhome.idea.vim.api.VimProcessGroupBase;
|
||||
import com.maddyhome.idea.vim.command.Command;
|
||||
import com.maddyhome.idea.vim.state.mode.Mode;
|
||||
import com.maddyhome.idea.vim.state.VimStateMachine;
|
||||
import com.maddyhome.idea.vim.ex.ExException;
|
||||
import com.maddyhome.idea.vim.ex.InvalidCommandException;
|
||||
import com.maddyhome.idea.vim.helper.UiHelper;
|
||||
import com.maddyhome.idea.vim.newapi.IjEditorExecutionContext;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel;
|
||||
import com.maddyhome.idea.vim.vimscript.model.CommandLineVimLContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static com.maddyhome.idea.vim.api.VimInjectorKt.globalOptions;
|
||||
import static com.maddyhome.idea.vim.api.VimInjectorKt.injector;
|
||||
|
||||
|
||||
public class ProcessGroup extends VimProcessGroupBase {
|
||||
public String getLastCommand() {
|
||||
return lastCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startSearchCommand(@NotNull VimEditor editor, ExecutionContext context, int count, char leader) {
|
||||
if (((IjVimEditor)editor).getEditor().isOneLineMode()) // Don't allow searching in one line editors
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String initText = "";
|
||||
String label = String.valueOf(leader);
|
||||
|
||||
ExEntryPanel panel = ExEntryPanel.getInstance();
|
||||
panel.activate(((IjVimEditor)editor).getEditor(), ((DataContext)context.getContext()), label, initText, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String endSearchCommand() {
|
||||
ExEntryPanel panel = ExEntryPanel.getInstance();
|
||||
panel.deactivate(true);
|
||||
|
||||
return panel.getText();
|
||||
}
|
||||
|
||||
public void startExCommand(@NotNull VimEditor editor, ExecutionContext context, @NotNull Command cmd) {
|
||||
// Don't allow ex commands in one line editors
|
||||
if (editor.isOneLineMode()) return;
|
||||
|
||||
String initText = getRange(((IjVimEditor) editor).getEditor(), cmd);
|
||||
injector.getMarkService().setVisualSelectionMarks(editor);
|
||||
VimStateMachine.Companion.getInstance(editor).setMode(Mode.CMD_LINE.INSTANCE);
|
||||
ExEntryPanel panel = ExEntryPanel.getInstance();
|
||||
panel.activate(((IjVimEditor) editor).getEditor(), ((IjEditorExecutionContext) context).getContext(), ":", initText, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processExKey(@NotNull VimEditor editor, @NotNull KeyStroke stroke) {
|
||||
// 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.
|
||||
|
||||
ExEntryPanel panel = ExEntryPanel.getInstance();
|
||||
if (panel.isActive()) {
|
||||
UiHelper.requestFocus(panel.getEntry());
|
||||
panel.handleKey(stroke);
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
VimStateMachine.Companion.getInstance(editor).setMode(new Mode.NORMAL());
|
||||
KeyHandler.getInstance().reset(editor);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean processExEntry(final @NotNull VimEditor editor, final @NotNull ExecutionContext context) {
|
||||
ExEntryPanel panel = ExEntryPanel.getInstance();
|
||||
panel.deactivate(true);
|
||||
boolean res = true;
|
||||
try {
|
||||
VimStateMachine.Companion.getInstance(editor).setMode(new Mode.NORMAL());
|
||||
|
||||
logger.debug("processing command");
|
||||
|
||||
final String text = panel.getText();
|
||||
|
||||
if (!panel.getLabel().equals(":")) {
|
||||
// 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 new InvalidCommandException("Expected ':' command. Got '" + panel.getLabel() + "'", text);
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled()) logger.debug("swing=" + SwingUtilities.isEventDispatchThread());
|
||||
|
||||
VimInjectorKt.getInjector().getVimscriptExecutor().execute(text, editor, context, skipHistory(editor), true, CommandLineVimLContext.INSTANCE);
|
||||
}
|
||||
catch (ExException e) {
|
||||
VimPlugin.showMessage(e.getMessage());
|
||||
VimPlugin.indicateError();
|
||||
res = false;
|
||||
}
|
||||
catch (Exception bad) {
|
||||
ProcessGroup.logger.error(bad);
|
||||
VimPlugin.indicateError();
|
||||
res = false;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// commands executed from map command / macro should not be added to history
|
||||
private boolean skipHistory(VimEditor editor) {
|
||||
return VimStateMachine.Companion.getInstance(editor).getMappingState().isExecutingMap() || injector.getMacro().isExecutingMacro();
|
||||
}
|
||||
|
||||
public void cancelExEntry(final @NotNull VimEditor editor, boolean resetCaret) {
|
||||
VimStateMachine.Companion.getInstance(editor).setMode(new Mode.NORMAL());
|
||||
KeyHandler.getInstance().reset(editor);
|
||||
ExEntryPanel panel = ExEntryPanel.getInstance();
|
||||
panel.deactivate(true, resetCaret);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startFilterCommand(@NotNull VimEditor editor, ExecutionContext context, @NotNull Command cmd) {
|
||||
String initText = getRange(((IjVimEditor) editor).getEditor(), cmd) + "!";
|
||||
VimStateMachine.Companion.getInstance(editor).setMode(Mode.CMD_LINE.INSTANCE);
|
||||
ExEntryPanel panel = ExEntryPanel.getInstance();
|
||||
panel.activate(((IjVimEditor) editor).getEditor(), ((IjEditorExecutionContext) context).getContext(), ":", initText, 1);
|
||||
}
|
||||
|
||||
private @NotNull String getRange(Editor editor, @NotNull Command cmd) {
|
||||
String initText = "";
|
||||
if (VimStateMachine.Companion.getInstance(new IjVimEditor(editor)).getMode() instanceof Mode.VISUAL) {
|
||||
initText = "'<,'>";
|
||||
}
|
||||
else if (cmd.getRawCount() > 0) {
|
||||
if (cmd.getCount() == 1) {
|
||||
initText = ".";
|
||||
}
|
||||
else {
|
||||
initText = ".,.+" + (cmd.getCount() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
return initText;
|
||||
}
|
||||
|
||||
public @Nullable String executeCommand(@NotNull VimEditor editor, @NotNull String command, @Nullable CharSequence input, @Nullable String currentDirectoryPath)
|
||||
throws ExecutionException, ProcessCanceledException {
|
||||
|
||||
// This is a much simplified version of how Vim does this. We're using stdin/stdout directly, while Vim will
|
||||
// redirect to temp files ('shellredir' and 'shelltemp') or use pipes. We don't support 'shellquote', because we're
|
||||
// not handling redirection, but we do use 'shellxquote' and 'shellxescape', because these have defaults that work
|
||||
// better with Windows. We also don't bother using ShellExecute for Windows commands beginning with `start`.
|
||||
// Finally, we're also not bothering with the crazy space and backslash handling of the 'shell' options content.
|
||||
return ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
|
||||
|
||||
final String shell = globalOptions(injector).getShell();
|
||||
final String shellcmdflag = globalOptions(injector).getShellcmdflag();
|
||||
final String shellxescape = globalOptions(injector).getShellxescape();
|
||||
final String shellxquote = globalOptions(injector).getShellxquote();
|
||||
|
||||
// For Win32. See :help 'shellxescape'
|
||||
final String escapedCommand = shellxquote.equals("(")
|
||||
? doEscape(command, shellxescape, "^")
|
||||
: command;
|
||||
// Required for Win32+cmd.exe, defaults to "(". See :help 'shellxquote'
|
||||
final String quotedCommand = shellxquote.equals("(")
|
||||
? "(" + escapedCommand + ")"
|
||||
: (shellxquote.equals("\"(")
|
||||
? "\"(" + escapedCommand + ")\""
|
||||
: shellxquote + escapedCommand + shellxquote);
|
||||
|
||||
final ArrayList<String> commands = new ArrayList<>();
|
||||
commands.add(shell);
|
||||
if (!shellcmdflag.isEmpty()) {
|
||||
// Note that Vim also does a simple whitespace split for multiple parameters
|
||||
commands.addAll(ParametersListUtil.parse(shellcmdflag));
|
||||
}
|
||||
commands.add(quotedCommand);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("shell=%s shellcmdflag=%s command=%s", shell, shellcmdflag, quotedCommand));
|
||||
}
|
||||
|
||||
final GeneralCommandLine commandLine = new GeneralCommandLine(commands);
|
||||
if (currentDirectoryPath != null) {
|
||||
commandLine.setWorkDirectory(currentDirectoryPath);
|
||||
}
|
||||
final CapturingProcessHandler handler = new CapturingProcessHandler(commandLine);
|
||||
if (input != null) {
|
||||
handler.addProcessListener(new ProcessAdapter() {
|
||||
@Override
|
||||
public void startNotified(@NotNull ProcessEvent event) {
|
||||
try {
|
||||
final CharSequenceReader charSequenceReader = new CharSequenceReader(input);
|
||||
final BufferedWriter outputStreamWriter = new BufferedWriter(new OutputStreamWriter(handler.getProcessInput()));
|
||||
copy(charSequenceReader, outputStreamWriter);
|
||||
outputStreamWriter.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final ProgressIndicator progressIndicator = ProgressIndicatorProvider.getInstance().getProgressIndicator();
|
||||
final ProcessOutput output = handler.runProcessWithProgressIndicator(progressIndicator);
|
||||
|
||||
lastCommand = command;
|
||||
|
||||
if (output.isCancelled()) {
|
||||
// TODO: Vim will use whatever text has already been written to stdout
|
||||
// For whatever reason, we're not getting any here, so just throw an exception
|
||||
throw new ProcessCanceledException();
|
||||
}
|
||||
|
||||
final Integer exitCode = handler.getExitCode();
|
||||
if (exitCode != null && exitCode != 0) {
|
||||
VimPlugin.showMessage("shell returned " + exitCode);
|
||||
VimPlugin.indicateError();
|
||||
}
|
||||
|
||||
// Get stderr; stdout and strip colors, which are not handles properly.
|
||||
return (output.getStderr() + output.getStdout()).replaceAll("\u001B\\[[;\\d]*m", "");
|
||||
}, "IdeaVim - !" + command, true, ((IjVimEditor) editor).getEditor().getProject());
|
||||
}
|
||||
|
||||
private String doEscape(String original, String charsToEscape, String escapeChar) {
|
||||
String result = original;
|
||||
for (char c : charsToEscape.toCharArray()) {
|
||||
result = result.replace("" + c, escapeChar + c);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// TODO: Java 10 has a transferTo method we could use instead
|
||||
private void copy(@NotNull Reader from, @NotNull Writer to) throws IOException {
|
||||
char[] buf = new char[2048];
|
||||
int cnt;
|
||||
while ((cnt = from.read(buf)) != -1) {
|
||||
to.write(buf, 0, cnt);
|
||||
}
|
||||
}
|
||||
|
||||
private String lastCommand;
|
||||
|
||||
private static final Logger logger = Logger.getInstance(ProcessGroup.class.getName());
|
||||
}
|
@@ -1,288 +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.group
|
||||
|
||||
import com.intellij.execution.ExecutionException
|
||||
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
|
||||
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.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
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.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
|
||||
private set
|
||||
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) {
|
||||
// Don't allow ex commands in one line editors
|
||||
if (editor.isOneLineMode()) return
|
||||
|
||||
val currentMode = editor.vimStateMachine.mode
|
||||
check(currentMode is ReturnableFromCmd) {
|
||||
"Cannot enable cmd mode from current mode $currentMode"
|
||||
}
|
||||
|
||||
isCommandProcessing = true
|
||||
modeBeforeCommandProcessing = currentMode
|
||||
val initText = getRange(editor, cmd)
|
||||
injector.markService.setVisualSelectionMarks(editor)
|
||||
editor.vimStateMachine.mode = Mode.CMD_LINE(currentMode)
|
||||
val panel = ExEntryPanel.getInstance()
|
||||
panel.activate(editor.ij, context.ij, ":", initText, 1)
|
||||
}
|
||||
|
||||
public override fun processExKey(editor: VimEditor, stroke: KeyStroke): 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)
|
||||
|
||||
return true
|
||||
} else {
|
||||
getInstance(editor).mode = NORMAL()
|
||||
getInstance().reset(editor)
|
||||
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()
|
||||
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
|
||||
}
|
||||
|
||||
@Throws(ExecutionException::class, ProcessCanceledException::class)
|
||||
public override fun executeCommand(
|
||||
editor: VimEditor,
|
||||
command: String,
|
||||
input: CharSequence?,
|
||||
currentDirectoryPath: String?
|
||||
): String? {
|
||||
// This is a much simplified version of how Vim does this. We're using stdin/stdout directly, while Vim will
|
||||
// redirect to temp files ('shellredir' and 'shelltemp') or use pipes. We don't support 'shellquote', because we're
|
||||
// not handling redirection, but we do use 'shellxquote' and 'shellxescape', because these have defaults that work
|
||||
// better with Windows. We also don't bother using ShellExecute for Windows commands beginning with `start`.
|
||||
// Finally, we're also not bothering with the crazy space and backslash handling of the 'shell' options content.
|
||||
|
||||
return ProgressManager.getInstance().runProcessWithProgressSynchronously<String, ExecutionException>(
|
||||
{
|
||||
val shell = injector.globalOptions().shell
|
||||
val shellcmdflag = injector.globalOptions().shellcmdflag
|
||||
val shellxescape = injector.globalOptions().shellxescape
|
||||
val shellxquote = injector.globalOptions().shellxquote
|
||||
|
||||
// For Win32. See :help 'shellxescape'
|
||||
val escapedCommand = if (shellxquote == "(") doEscape(command, shellxescape, "^")
|
||||
else command
|
||||
// Required for Win32+cmd.exe, defaults to "(". See :help 'shellxquote'
|
||||
val quotedCommand = if (shellxquote == "(") "($escapedCommand)"
|
||||
else (if (shellxquote == "\"(") "\"($escapedCommand)\""
|
||||
else shellxquote + escapedCommand + shellxquote)
|
||||
|
||||
val commands = ArrayList<String>()
|
||||
commands.add(shell)
|
||||
if (shellcmdflag.isNotEmpty()) {
|
||||
// Note that Vim also does a simple whitespace split for multiple parameters
|
||||
commands.addAll(ParametersListUtil.parse(shellcmdflag))
|
||||
}
|
||||
commands.add(quotedCommand)
|
||||
|
||||
if (logger.isDebugEnabled) {
|
||||
logger.debug(String.format("shell=%s shellcmdflag=%s command=%s", shell, shellcmdflag, quotedCommand))
|
||||
}
|
||||
|
||||
val commandLine = GeneralCommandLine(commands)
|
||||
if (currentDirectoryPath != null) {
|
||||
commandLine.setWorkDirectory(currentDirectoryPath)
|
||||
}
|
||||
val handler = CapturingProcessHandler(commandLine)
|
||||
if (input != null) {
|
||||
handler.addProcessListener(object : ProcessAdapter() {
|
||||
override fun startNotified(event: ProcessEvent) {
|
||||
try {
|
||||
val charSequenceReader = CharSequenceReader(input)
|
||||
val outputStreamWriter = BufferedWriter(OutputStreamWriter(handler.processInput))
|
||||
copy(charSequenceReader, outputStreamWriter)
|
||||
outputStreamWriter.close()
|
||||
} catch (e: IOException) {
|
||||
logger.error(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
val progressIndicator = ProgressIndicatorProvider.getInstance().progressIndicator
|
||||
val output = handler.runProcessWithProgressIndicator(progressIndicator)
|
||||
|
||||
lastCommand = command
|
||||
|
||||
if (output.isCancelled) {
|
||||
// TODO: Vim will use whatever text has already been written to stdout
|
||||
// For whatever reason, we're not getting any here, so just throw an exception
|
||||
throw ProcessCanceledException()
|
||||
}
|
||||
|
||||
val exitCode = handler.exitCode
|
||||
if (exitCode != null && exitCode != 0) {
|
||||
VimPlugin.showMessage("shell returned $exitCode")
|
||||
VimPlugin.indicateError()
|
||||
}
|
||||
(output.stderr + output.stdout).replace("\u001B\\[[;\\d]*m".toRegex(), "")
|
||||
}, "IdeaVim - !$command", true, editor.ij.project
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("SameParameterValue")
|
||||
private fun doEscape(original: String, charsToEscape: String, escapeChar: String): String {
|
||||
var result = original
|
||||
for (c in charsToEscape.toCharArray()) {
|
||||
result = result.replace("" + c, escapeChar + c)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// TODO: Java 10 has a transferTo method we could use instead
|
||||
@Throws(IOException::class)
|
||||
private fun copy(from: Reader, to: Writer) {
|
||||
val buf = CharArray(2048)
|
||||
var cnt: Int
|
||||
while ((from.read(buf).also { cnt = it }) != -1) {
|
||||
to.write(buf, 0, cnt)
|
||||
}
|
||||
}
|
||||
|
||||
public companion object {
|
||||
private val logger = logger<ProcessGroup>()
|
||||
}
|
||||
}
|
@@ -36,9 +36,10 @@ 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.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;
|
||||
@@ -61,46 +62,34 @@ 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;
|
||||
|
||||
@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 class SearchGroup extends VimSearchGroupBase 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.
|
||||
VimPlugin.getOptionGroup().addGlobalOptionChangeListener(Options.hlsearch, () -> {
|
||||
resetShowSearchHighlight();
|
||||
forceUpdateSearchHighlights();
|
||||
});
|
||||
// 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.
|
||||
VimPlugin.getOptionGroup().addGlobalOptionChangeListener(Options.hlsearch, () -> {
|
||||
resetShowSearchHighlight();
|
||||
forceUpdateSearchHighlights();
|
||||
});
|
||||
|
||||
final GlobalOptionChangeListener updateHighlightsIfVisible = () -> {
|
||||
if (showSearchHighlight) {
|
||||
forceUpdateSearchHighlights();
|
||||
}
|
||||
};
|
||||
VimPlugin.getOptionGroup().addGlobalOptionChangeListener(Options.ignorecase, updateHighlightsIfVisible);
|
||||
VimPlugin.getOptionGroup().addGlobalOptionChangeListener(Options.smartcase, updateHighlightsIfVisible);
|
||||
}
|
||||
final GlobalOptionChangeListener updateHighlightsIfVisible = () -> {
|
||||
if (showSearchHighlight) {
|
||||
forceUpdateSearchHighlights();
|
||||
}
|
||||
};
|
||||
VimPlugin.getOptionGroup().addGlobalOptionChangeListener(Options.ignorecase, updateHighlightsIfVisible);
|
||||
VimPlugin.getOptionGroup().addGlobalOptionChangeListener(Options.smartcase, updateHighlightsIfVisible);
|
||||
}
|
||||
|
||||
public void turnOn() {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) {
|
||||
super.updateSearchHighlights(false);
|
||||
return;
|
||||
}
|
||||
updateSearchHighlights();
|
||||
}
|
||||
|
||||
@@ -111,12 +100,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
@Override
|
||||
public void resetState() {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) {
|
||||
super.resetState();
|
||||
return;
|
||||
}
|
||||
lastPatternIdx = RE_SEARCH;
|
||||
lastSearch = lastSubstitute = lastReplace = null;
|
||||
lastPatternOffset = "";
|
||||
@@ -130,9 +114,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
*
|
||||
* @return The pattern used for last search. Can be null
|
||||
*/
|
||||
@Override
|
||||
public @Nullable String getLastSearchPattern() {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) return super.getLastSearchPattern();
|
||||
return lastSearch;
|
||||
}
|
||||
|
||||
@@ -140,9 +122,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
* Get the last pattern used in substitution.
|
||||
* @return The pattern used for the last substitute command. Can be null
|
||||
*/
|
||||
@Override
|
||||
public @Nullable String getLastSubstitutePattern() {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) return super.getLastSubstitutePattern();
|
||||
return lastSubstitute;
|
||||
}
|
||||
|
||||
@@ -151,9 +131,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
*
|
||||
* @return The pattern last used for either searching or substitution. Can be null
|
||||
*/
|
||||
@Override
|
||||
protected @Nullable String getLastUsedPattern() {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) return super.getLastUsedPattern();
|
||||
public @Nullable String getLastUsedPattern() {
|
||||
switch (lastPatternIdx) {
|
||||
case RE_SEARCH: return lastSearch;
|
||||
case RE_SUBST: return lastSubstitute;
|
||||
@@ -214,13 +192,9 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
* @param patternOffset The pattern offset, e.g. `/{pattern}/{offset}`
|
||||
* @param direction The direction to search
|
||||
*/
|
||||
@Override
|
||||
public void setLastSearchState(@SuppressWarnings("unused") @NotNull VimEditor editor, @NotNull String pattern,
|
||||
@TestOnly
|
||||
public void setLastSearchState(@SuppressWarnings("unused") @NotNull Editor editor, @NotNull String pattern,
|
||||
@NotNull String patternOffset, Direction direction) {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) {
|
||||
super.setLastSearchState(pattern, patternOffset, direction);
|
||||
return;
|
||||
}
|
||||
setLastUsedPattern(pattern, RE_SEARCH, true);
|
||||
lastIgnoreSmartCase = false;
|
||||
lastPatternOffset = patternOffset;
|
||||
@@ -252,7 +226,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
int startLine,
|
||||
int endLine,
|
||||
boolean ignoreCase) {
|
||||
return injector.getSearchHelper().findAll(new IjVimEditor(editor), pattern, startLine, endLine, ignoreCase);
|
||||
return SearchHelper.findAll(editor, pattern, startLine, endLine, ignoreCase);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,8 +254,6 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
*/
|
||||
@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);
|
||||
|
||||
boolean isNewPattern = false;
|
||||
String pattern = null;
|
||||
String patternOffset = null;
|
||||
@@ -442,7 +414,6 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
*/
|
||||
@Override
|
||||
public int searchWord(@NotNull VimEditor editor, @NotNull ImmutableVimCaret caret, int count, boolean whole, @NotNull Direction dir) {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) return super.searchWord(editor, caret, count, whole, dir);
|
||||
TextRange range = SearchHelper.findWordUnderCursor(((IjVimEditor)editor).getEditor(), ((IjVimCaret)caret).getCaret());
|
||||
if (range == null) {
|
||||
logger.warn("No range was found");
|
||||
@@ -484,7 +455,6 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
*/
|
||||
@Override
|
||||
public int searchNext(@NotNull VimEditor editor, @NotNull ImmutableVimCaret caret, int count) {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) return super.searchNext(editor, caret, count);
|
||||
return searchNextWithDirection(((IjVimEditor)editor).getEditor(), ((IjVimCaret)caret).getCaret(), count, lastDir);
|
||||
}
|
||||
|
||||
@@ -501,7 +471,6 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
*/
|
||||
@Override
|
||||
public int searchPrevious(@NotNull VimEditor editor, @NotNull ImmutableVimCaret caret, int count) {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) return super.searchPrevious(editor, caret, count);
|
||||
return searchNextWithDirection(((IjVimEditor)editor).getEditor(), ((IjVimCaret)caret).getCaret(), count,
|
||||
lastDir.reverse());
|
||||
}
|
||||
@@ -555,8 +524,6 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
@NotNull @NonNls String excmd,
|
||||
@NotNull @NonNls String exarg,
|
||||
@NotNull VimLContext parent) {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) return super.processSubstituteCommand(editor, caret, 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<>();
|
||||
if (CommandStateHelper.inVisualMode(((IjVimEditor) editor).getEditor())) {
|
||||
@@ -720,7 +687,8 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
return false;
|
||||
}
|
||||
|
||||
Pair<Boolean, Triple<Object, String, Object>> booleanregmmatch_tPair = search_regcomp(pat, which_pat, RE_SUBST);
|
||||
Pair<Boolean, Triple<Object, String, Object>> booleanregmmatch_tPair = search_regcomp(pat, which_pat,
|
||||
RE_SUBST);
|
||||
if (!booleanregmmatch_tPair.getFirst()) {
|
||||
if (do_error) {
|
||||
VimPlugin.showMessage(MessageHelper.message(Msg.e_invcmd));
|
||||
@@ -728,9 +696,9 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
}
|
||||
return false;
|
||||
}
|
||||
RegExp.regmmatch_T regmatch = (RegExp.regmmatch_T)booleanregmmatch_tPair.getSecond().getFirst();
|
||||
RegExp.regmmatch_T regmatch = (RegExp.regmmatch_T) booleanregmmatch_tPair.getSecond().getFirst();
|
||||
String pattern = booleanregmmatch_tPair.getSecond().getSecond();
|
||||
RegExp sp = (RegExp)booleanregmmatch_tPair.getSecond().getThird();
|
||||
RegExp sp = (RegExp) booleanregmmatch_tPair.getSecond().getThird();
|
||||
|
||||
/* the 'i' or 'I' flag overrules 'ignorecase' and 'smartcase' */
|
||||
if (do_ic == 'i') {
|
||||
@@ -763,8 +731,8 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
resetShowSearchHighlight();
|
||||
forceUpdateSearchHighlights();
|
||||
|
||||
int start = ((IjVimEditor)editor).getEditor().getDocument().getLineStartOffset(line1);
|
||||
int end = ((IjVimEditor)editor).getEditor().getDocument().getLineEndOffset(line2);
|
||||
int start = ((IjVimEditor) editor).getEditor().getDocument().getLineStartOffset(line1);
|
||||
int end = ((IjVimEditor) editor).getEditor().getDocument().getLineEndOffset(line2);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("search range=[" + start + "," + end + "]");
|
||||
@@ -787,6 +755,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
firstMatch = false;
|
||||
}
|
||||
|
||||
|
||||
String match = sp.vim_regsub_multi(regmatch, lnum, sub, 1, false);
|
||||
if (sub.charAt(0) == '\\' && sub.charAt(1) == '=') {
|
||||
String exprString = sub.toString().substring(2);
|
||||
@@ -795,25 +764,22 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
exceptions.add(new ExException("E15: Invalid expression: " + exprString));
|
||||
expression = new SimpleExpression(new VimString(""));
|
||||
}
|
||||
}
|
||||
else if (match == null) {
|
||||
} else if (match == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int line = lnum + regmatch.startpos[0].lnum;
|
||||
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 startoff = startpos.toOffset(((IjVimEditor) editor).getEditor());
|
||||
int endoff = endpos.toOffset(((IjVimEditor) editor).getEditor());
|
||||
|
||||
if (do_all || line != lastLine) {
|
||||
boolean doReplace = true;
|
||||
if (do_ask) {
|
||||
RangeHighlighter hl =
|
||||
SearchHighlightsHelper.addSubstitutionConfirmationHighlight(((IjVimEditor)editor).getEditor(), startoff,
|
||||
endoff);
|
||||
final ReplaceConfirmationChoice choice = confirmChoice(((IjVimEditor)editor).getEditor(), match, ((IjVimCaret)caret).getCaret(), startoff);
|
||||
((IjVimEditor)editor).getEditor().getMarkupModel().removeHighlighter(hl);
|
||||
RangeHighlighter hl = SearchHighlightsHelper.addSubstitutionConfirmationHighlight(((IjVimEditor) editor).getEditor(), startoff, endoff);
|
||||
final ReplaceConfirmationChoice choice = confirmChoice(((IjVimEditor) editor).getEditor(), match, ((IjVimCaret) caret).getCaret(), startoff);
|
||||
((IjVimEditor) editor).getEditor().getMarkupModel().removeHighlighter(hl);
|
||||
switch (choice) {
|
||||
case SUBSTITUTE_THIS:
|
||||
doReplace = true;
|
||||
@@ -836,26 +802,25 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
}
|
||||
}
|
||||
if (doReplace) {
|
||||
SubmatchFunctionHandler.Companion.getInstance().setLatestMatch(
|
||||
((IjVimEditor)editor).getEditor().getDocument().getText(new com.intellij.openapi.util.TextRange(startoff, endoff)));
|
||||
SubmatchFunctionHandler.Companion.getInstance().setLatestMatch(((IjVimEditor) editor).getEditor().getDocument().getText(new com.intellij.openapi.util.TextRange(startoff, endoff)));
|
||||
caret.moveToOffset(startoff);
|
||||
if (expression != null) {
|
||||
try {
|
||||
match =
|
||||
expression.evaluate(editor, injector.getExecutionContextManager().onEditor(editor, null), parent).toInsertableString();
|
||||
}
|
||||
catch (Exception e) {
|
||||
exceptions.add((ExException)e);
|
||||
match = expression
|
||||
.evaluate(editor, injector.getExecutionContextManager().onEditor(editor, null), parent)
|
||||
.toInsertableString();
|
||||
} catch (Exception e) {
|
||||
exceptions.add((ExException) e);
|
||||
match = "";
|
||||
}
|
||||
}
|
||||
|
||||
String finalMatch = match;
|
||||
ApplicationManager.getApplication().runWriteAction(
|
||||
() -> ((IjVimEditor)editor).getEditor().getDocument().replaceString(startoff, endoff, finalMatch));
|
||||
ApplicationManager.getApplication().runWriteAction(() -> ((IjVimEditor) editor).getEditor().getDocument().replaceString(startoff, endoff,
|
||||
finalMatch));
|
||||
lastMatch = startoff;
|
||||
int newend = startoff + match.length();
|
||||
newpos = CharacterPosition.Companion.fromOffset(((IjVimEditor)editor).getEditor(), newend);
|
||||
newpos = CharacterPosition.Companion.fromOffset(((IjVimEditor) editor).getEditor(), newend);
|
||||
|
||||
lnum += newpos.line - endpos.line;
|
||||
line2 += newpos.line - endpos.line;
|
||||
@@ -910,10 +875,6 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
|
||||
@Override
|
||||
public void setLastSearchPattern(@Nullable String lastSearchPattern) {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) {
|
||||
super.setLastSearchPattern(lastSearchPattern);
|
||||
return;
|
||||
}
|
||||
this.lastSearch = lastSearchPattern;
|
||||
if (showSearchHighlight) {
|
||||
resetIncsearchHighlights();
|
||||
@@ -923,10 +884,6 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
|
||||
@Override
|
||||
public void setLastSubstitutePattern(@Nullable String lastSubstitutePattern) {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) {
|
||||
super.setLastSubstitutePattern(lastSubstitutePattern);
|
||||
return;
|
||||
}
|
||||
this.lastSubstitute = lastSubstitutePattern;
|
||||
}
|
||||
|
||||
@@ -936,7 +893,6 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
int patternOffset,
|
||||
int startOffset,
|
||||
@NotNull Direction direction) {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) return super.processSearchRange(editor, pattern, patternOffset, startOffset, direction);
|
||||
return processSearchRange(((IjVimEditor) editor).getEditor(), pattern, patternOffset, startOffset, direction);
|
||||
}
|
||||
|
||||
@@ -1059,7 +1015,6 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
*/
|
||||
@Override
|
||||
public @Nullable TextRange getNextSearchRange(@NotNull VimEditor editor, int count, boolean forwards) {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) return super.getNextSearchRange(editor, count, forwards);
|
||||
editor.removeSecondaryCarets();
|
||||
TextRange current = findUnderCaret(editor);
|
||||
|
||||
@@ -1091,10 +1046,17 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public TextRange findUnderCaret(@NotNull VimEditor editor) {
|
||||
final TextRange backSearch = searchBackward(editor, editor.primaryCaret().getOffset().getPoint() + 1, 1);
|
||||
if (backSearch == null) return null;
|
||||
return backSearch.contains(editor.primaryCaret().getOffset().getPoint()) ? backSearch : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public TextRange searchBackward(@NotNull VimEditor editor, int offset, int count) {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) return super.searchBackward(editor, offset, count);
|
||||
// Backward search returns wrongs end offset for some cases. That's why we should perform additional forward search
|
||||
final EnumSet<SearchOptions> searchOptions = EnumSet.of(SearchOptions.WRAP, SearchOptions.WHOLE_FILE, SearchOptions.BACKWARDS);
|
||||
final TextRange foundBackward = VimInjectorKt.getInjector().getSearchHelper().findPattern(editor, getLastUsedPattern(), offset, count, searchOptions);
|
||||
@@ -1112,12 +1074,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
//
|
||||
// *******************************************************************************************************************
|
||||
//region Search highlights
|
||||
@Override
|
||||
public void clearSearchHighlight() {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) {
|
||||
super.clearSearchHighlight();
|
||||
return;
|
||||
}
|
||||
showSearchHighlight = false;
|
||||
updateSearchHighlights();
|
||||
}
|
||||
@@ -1137,12 +1094,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
/**
|
||||
* Reset the search highlights to the last used pattern after highlighting incsearch results.
|
||||
*/
|
||||
@Override
|
||||
public void resetIncsearchHighlights() {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) {
|
||||
super.resetIncsearchHighlights();
|
||||
return;
|
||||
}
|
||||
SearchHighlightsHelper.updateSearchHighlights(getLastUsedPattern(), lastIgnoreSmartCase, showSearchHighlight, true);
|
||||
}
|
||||
|
||||
@@ -1151,13 +1103,9 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
}
|
||||
|
||||
private void highlightSearchLines(@NotNull Editor editor, int startLine, int endLine) {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) {
|
||||
super.highlightSearchLines(new IjVimEditor(editor), startLine, endLine);
|
||||
return;
|
||||
}
|
||||
final String pattern = getLastUsedPattern();
|
||||
if (pattern != null) {
|
||||
final List<TextRange> results = injector.getSearchHelper().findAll(new IjVimEditor(editor), pattern, startLine, endLine,
|
||||
final List<TextRange> results = SearchHelper.findAll(editor, pattern, startLine, endLine,
|
||||
shouldIgnoreCase(pattern, lastIgnoreSmartCase));
|
||||
SearchHighlightsHelper.highlightSearchResults(editor, pattern, results, -1);
|
||||
}
|
||||
@@ -1166,17 +1114,12 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
/**
|
||||
* Updates search highlights when the selected editor changes
|
||||
*/
|
||||
public void fileEditorManagerSelectionChangedCallback(@SuppressWarnings("unused") @NotNull FileEditorManagerEvent event) {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) {
|
||||
super.updateSearchHighlights(false);
|
||||
return;
|
||||
}
|
||||
public static void fileEditorManagerSelectionChangedCallback(@SuppressWarnings("unused") @NotNull FileEditorManagerEvent event) {
|
||||
VimPlugin.getSearch().updateSearchHighlights();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer findDecimalNumber(@NotNull String line) {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) return super.findDecimalNumber(line);
|
||||
Pair<TextRange, NumberType> searchResult = SearchHelper.findNumberInText(line, 0, false, false, false);
|
||||
if (searchResult != null) {
|
||||
TextRange range = searchResult.component1();
|
||||
@@ -1188,7 +1131,6 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
@NotNull
|
||||
@Override
|
||||
public Direction getLastSearchDirection() {
|
||||
if (globalIjOptions(injector).getUseNewRegex()) return super.getLastSearchDirection();
|
||||
return lastDir;
|
||||
}
|
||||
|
||||
@@ -1332,7 +1274,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
|
||||
if (hasEndOffset) searchOptions.add(SearchOptions.WANT_ENDPOS);
|
||||
|
||||
// Uses RE_LAST. We know this is always set before being called
|
||||
TextRange range = injector.getSearchHelper().findPattern(new IjVimEditor(editor), getLastUsedPattern(), startOffset, count, searchOptions);
|
||||
TextRange range = SearchHelper.findPattern(editor, getLastUsedPattern(), startOffset, count, searchOptions);
|
||||
if (range == null) {
|
||||
logger.warn("No range is found");
|
||||
return -1;
|
||||
|
@@ -177,6 +177,15 @@ internal class VimMarkServiceImpl : VimMarkServiceBase(), PersistentStateCompone
|
||||
return createOrGetSystemMark(char, line, col, editor)
|
||||
}
|
||||
|
||||
@Deprecated("Please use removeMark with other signature")
|
||||
override fun removeMark(ch: Char, mark: Mark) {
|
||||
if (ch.isGlobalMark()) {
|
||||
removeGlobalMark(ch)
|
||||
} else if (ch.isLocalMark()) {
|
||||
getLocalMarks(mark.filepath).remove(ch)
|
||||
}
|
||||
}
|
||||
|
||||
override fun removeGlobalMark(char: Char) {
|
||||
val mark = getGlobalMark(char)
|
||||
if (mark is IntellijMark) {
|
||||
@@ -196,7 +205,7 @@ internal class VimMarkServiceImpl : VimMarkServiceBase(), PersistentStateCompone
|
||||
* @param event The change event
|
||||
*/
|
||||
override fun beforeDocumentChange(event: DocumentEvent) {
|
||||
if (VimPlugin.isNotEnabled()) return
|
||||
if (!VimPlugin.isEnabled()) return
|
||||
if (logger.isDebugEnabled) logger.debug("MarkUpdater before, event = $event")
|
||||
if (event.oldLength == 0) return
|
||||
val doc = event.document
|
||||
@@ -212,7 +221,7 @@ internal class VimMarkServiceImpl : VimMarkServiceBase(), PersistentStateCompone
|
||||
* @param event The change event
|
||||
*/
|
||||
override fun documentChanged(event: DocumentEvent) {
|
||||
if (VimPlugin.isNotEnabled()) return
|
||||
if (!VimPlugin.isEnabled()) return
|
||||
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
|
||||
@@ -233,7 +242,7 @@ internal class VimMarkServiceImpl : VimMarkServiceBase(), PersistentStateCompone
|
||||
|
||||
class VimBookmarksListener(private val myProject: Project) : BookmarksListener {
|
||||
override fun bookmarkAdded(group: BookmarkGroup, bookmark: Bookmark) {
|
||||
if (VimPlugin.isNotEnabled()) return
|
||||
if (!VimPlugin.isEnabled()) return
|
||||
if (!injector.globalIjOptions().ideamarks) {
|
||||
return
|
||||
}
|
||||
@@ -246,7 +255,7 @@ internal class VimMarkServiceImpl : VimMarkServiceBase(), PersistentStateCompone
|
||||
}
|
||||
|
||||
override fun bookmarkRemoved(group: BookmarkGroup, bookmark: Bookmark) {
|
||||
if (VimPlugin.isNotEnabled()) return
|
||||
if (!VimPlugin.isEnabled()) return
|
||||
if (!injector.globalIjOptions().ideamarks) {
|
||||
return
|
||||
}
|
||||
@@ -270,6 +279,16 @@ internal class VimMarkServiceImpl : VimMarkServiceBase(), PersistentStateCompone
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* COMPATIBILITY-LAYER: Method added
|
||||
* Please see: [doc](https://jb.gg/zo8n0r)
|
||||
*
|
||||
*/
|
||||
@Deprecated("Please use method with VimEditor")
|
||||
fun saveJumpLocation(editor: Editor?) {
|
||||
injector.jumpService.saveJumpLocation(IjVimEditor(editor!!))
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val SAVE_MARK_COUNT = 20
|
||||
private val logger = Logger.getInstance(
|
||||
|
@@ -27,12 +27,15 @@ 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.api.setChangeMarks
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
import com.maddyhome.idea.vim.state.mode.isBlock
|
||||
import com.maddyhome.idea.vim.state.mode.isChar
|
||||
import com.maddyhome.idea.vim.state.mode.isLine
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.diagnostic.debug
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.RWLockLabel
|
||||
import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset
|
||||
import com.maddyhome.idea.vim.ide.isClionNova
|
||||
import com.maddyhome.idea.vim.mark.VimMarkConstants.MARK_CHANGE_POS
|
||||
import com.maddyhome.idea.vim.newapi.IjVimCaret
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
|
||||
@@ -45,10 +48,6 @@ import com.maddyhome.idea.vim.put.PutData
|
||||
import com.maddyhome.idea.vim.put.VimPasteProvider
|
||||
import com.maddyhome.idea.vim.put.VimPutBase
|
||||
import com.maddyhome.idea.vim.register.RegisterConstants
|
||||
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||
import com.maddyhome.idea.vim.state.mode.isBlock
|
||||
import com.maddyhome.idea.vim.state.mode.isChar
|
||||
import com.maddyhome.idea.vim.state.mode.isLine
|
||||
import java.awt.datatransfer.DataFlavor
|
||||
|
||||
internal class PutGroup : VimPutBase() {
|
||||
@@ -190,7 +189,7 @@ internal class PutGroup : VimPutBase() {
|
||||
endOffset: Int,
|
||||
): Int {
|
||||
// Temp fix for VIM-2808. Should be removed after rider will fix it's issues
|
||||
if (PlatformUtils.isRider() || isClionNova()) return endOffset
|
||||
if (PlatformUtils.isRider()) return endOffset
|
||||
|
||||
val startLine = editor.offsetToBufferPosition(startOffset).line
|
||||
val endLine = editor.offsetToBufferPosition(endOffset - 1).line
|
||||
|
@@ -40,15 +40,9 @@ internal object IdeaSelectionControl {
|
||||
* This method should be in sync with [predictMode]
|
||||
*
|
||||
* Control unexpected (non vim) selection change and adjust a mode to it. The new mode is not enabled immediately,
|
||||
* but with some delay (using [VimVisualTimer]). The delay is used because some platform functionality
|
||||
* makes features by using selection. E.g. PyCharm unindent firstly select the indenting then applies delete action.
|
||||
* Such "quick" selection breaks IdeaVim behaviour.
|
||||
* but with some delay (using [VimVisualTimer])
|
||||
*
|
||||
* See [VimVisualTimer] to more info.
|
||||
*
|
||||
* XXX: This method can be split into "change calculation" and "change apply". In this way, we would be able
|
||||
* to calculate if we need to make a change or not and reduce the number of these calls.
|
||||
* If this refactoring ever is applied, please add `assertNull(VimVisualTimer.timer)` to `tearDown` of VimTestCase.
|
||||
*/
|
||||
fun controlNonVimSelectionChange(
|
||||
editor: Editor,
|
||||
@@ -56,7 +50,6 @@ internal object IdeaSelectionControl {
|
||||
) {
|
||||
VimVisualTimer.singleTask(editor.vim.mode) { initialMode ->
|
||||
|
||||
if (VimPlugin.isNotEnabled()) return@singleTask
|
||||
if (editor.isIdeaVimDisabledHere) return@singleTask
|
||||
|
||||
logger.debug("Adjust non-vim selection. Source: $selectionSource, initialMode: $initialMode")
|
||||
@@ -128,9 +121,8 @@ internal object IdeaSelectionControl {
|
||||
}
|
||||
}
|
||||
|
||||
private fun dontChangeMode(editor: Editor): Boolean {
|
||||
return editor.isTemplateActive() && (editor.vim.isIdeaRefactorModeKeep || editor.vim.mode.hasVisualSelection)
|
||||
}
|
||||
private fun dontChangeMode(editor: Editor): Boolean =
|
||||
editor.isTemplateActive() && (editor.vim.isIdeaRefactorModeKeep || editor.vim.mode.hasVisualSelection)
|
||||
|
||||
private fun chooseNonSelectionMode(editor: Editor): Mode {
|
||||
val templateActive = editor.isTemplateActive()
|
||||
|
@@ -9,10 +9,10 @@
|
||||
package com.maddyhome.idea.vim.group.visual
|
||||
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
import com.maddyhome.idea.vim.group.visual.VimVisualTimer.mode
|
||||
import com.maddyhome.idea.vim.group.visual.VimVisualTimer.singleTask
|
||||
import com.maddyhome.idea.vim.newapi.globalIjOptions
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
import java.awt.event.ActionEvent
|
||||
import javax.swing.Timer
|
||||
|
||||
@@ -52,13 +52,12 @@ import javax.swing.Timer
|
||||
* editorHasSelection is false. Insert mode ([mode]) has no selection and editor also has no selection, so
|
||||
* no adjustment gets performed and IdeaVim stays in insert mode.
|
||||
*/
|
||||
// Do not remove until it's used in EasyMotion plugin in tests
|
||||
public object VimVisualTimer {
|
||||
internal object VimVisualTimer {
|
||||
|
||||
public var swingTimer: Timer? = null
|
||||
public var mode: Mode? = null
|
||||
var swingTimer: Timer? = null
|
||||
var mode: Mode? = null
|
||||
|
||||
public inline fun singleTask(currentMode: Mode, crossinline task: (initialMode: Mode?) -> Unit) {
|
||||
inline fun singleTask(currentMode: Mode, crossinline task: (initialMode: Mode?) -> Unit) {
|
||||
swingTimer?.stop()
|
||||
|
||||
if (mode == null) mode = currentMode
|
||||
@@ -70,7 +69,7 @@ public object VimVisualTimer {
|
||||
swingTimer = timer
|
||||
}
|
||||
|
||||
public fun doNow() {
|
||||
fun doNow() {
|
||||
val swingTimer1 = swingTimer
|
||||
if (swingTimer1 != null) {
|
||||
swingTimer1.stop()
|
||||
@@ -80,12 +79,7 @@ public object VimVisualTimer {
|
||||
}
|
||||
}
|
||||
|
||||
public fun drop() {
|
||||
swingTimer?.stop()
|
||||
swingTimer = null
|
||||
}
|
||||
|
||||
public inline fun timerAction(task: (initialMode: Mode?) -> Unit) {
|
||||
inline fun timerAction(task: (initialMode: Mode?) -> Unit) {
|
||||
task(mode)
|
||||
swingTimer = null
|
||||
mode = null
|
||||
|
102
src/main/java/com/maddyhome/idea/vim/handler/ActionBeanClass.kt
Normal file
102
src/main/java/com/maddyhome/idea/vim/handler/ActionBeanClass.kt
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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.handler
|
||||
|
||||
import com.intellij.serviceContainer.BaseKeyedLazyInstance
|
||||
import com.intellij.util.SmartList
|
||||
import com.intellij.util.xmlb.annotations.Attribute
|
||||
import com.maddyhome.idea.vim.command.MappingMode
|
||||
import org.jetbrains.annotations.ApiStatus.ScheduledForRemoval
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
/**
|
||||
* Action holder for IdeaVim actions.
|
||||
*
|
||||
* [implementation] should be subclass of [EditorActionHandlerBase]
|
||||
*
|
||||
* [modes] ("mappingModes") defines the action modes. E.g. "NO" - action works in normal and op-pending modes.
|
||||
* Warning: V - Visual and Select mode. X - Visual mode. (like vmap and xmap).
|
||||
* Use "ALL" to enable action for all modes.
|
||||
*
|
||||
* [keys] comma-separated list of keys for the action. E.g. `gt,gT` - action gets executed on `gt` or `gT`
|
||||
* Since xml doesn't allow using raw `<` character, use « and » symbols for mappings with modifiers.
|
||||
* E.g. `«C-U»` - CTRL-U (<C-U> in vim notation)
|
||||
* If you want to use exactly `<` character, replace it with `<`. E.g. `i<` - i<
|
||||
* If you want to use comma in mapping, use `«COMMA»`
|
||||
* Do not place a whitespace around the comma!
|
||||
*
|
||||
*
|
||||
* !! IMPORTANT !!
|
||||
* You may wonder why the extension points are used instead of any other approach to register actions.
|
||||
* The reason is startup performance. Using the extension points you don't even have to load classes of actions.
|
||||
* So, all actions are loaded on demand, including classes in classloader.
|
||||
*/
|
||||
@Deprecated(message = "Please use CommandOrMotion annotation")
|
||||
@ScheduledForRemoval(inVersion = "2.9.0")
|
||||
internal class ActionBeanClass : BaseKeyedLazyInstance<EditorActionHandlerBase>() {
|
||||
@Attribute("implementation")
|
||||
var implementation: String? = null
|
||||
|
||||
@Attribute("mappingModes")
|
||||
var modes: String? = null
|
||||
|
||||
@Attribute("keys")
|
||||
var keys: String? = null
|
||||
|
||||
val actionId: String get() = implementation?.let { EditorActionHandlerBase.getActionId(it) } ?: ""
|
||||
|
||||
fun getParsedKeys(): Set<List<KeyStroke>>? {
|
||||
val myKeys = keys ?: return null
|
||||
val escapedKeys = myKeys.splitByComma()
|
||||
return EditorActionHandlerBase.parseKeysSet(escapedKeys)
|
||||
}
|
||||
|
||||
override fun getImplementationClassName(): String? = implementation
|
||||
|
||||
fun getParsedModes(): Set<MappingMode>? {
|
||||
val myModes = modes ?: return null
|
||||
|
||||
if ("ALL" == myModes) return MappingMode.ALL
|
||||
|
||||
val res = mutableListOf<MappingMode>()
|
||||
for (c in myModes) {
|
||||
when (c) {
|
||||
'N' -> res += MappingMode.NORMAL
|
||||
'X' -> res += MappingMode.VISUAL
|
||||
'V' -> {
|
||||
res += MappingMode.VISUAL
|
||||
res += MappingMode.SELECT
|
||||
}
|
||||
'S' -> res += MappingMode.SELECT
|
||||
'O' -> res += MappingMode.OP_PENDING
|
||||
'I' -> res += MappingMode.INSERT
|
||||
'C' -> res += MappingMode.CMD_LINE
|
||||
else -> error("Wrong mapping mode: $c")
|
||||
}
|
||||
}
|
||||
return res.toSet()
|
||||
}
|
||||
|
||||
private fun String.splitByComma(): List<String> {
|
||||
if (this.isEmpty()) return ArrayList()
|
||||
val res = SmartList<String>()
|
||||
var start = 0
|
||||
var current = 0
|
||||
while (current < this.length) {
|
||||
if (this[current] == ',') {
|
||||
res += this.substring(start, current)
|
||||
current++
|
||||
start = current
|
||||
}
|
||||
current++
|
||||
}
|
||||
res += this.substring(start, current)
|
||||
return res
|
||||
}
|
||||
}
|
@@ -1,120 +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.handler
|
||||
|
||||
import com.intellij.openapi.actionSystem.KeyboardShortcut
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.keymap.Keymap
|
||||
import com.intellij.openapi.keymap.KeymapManagerListener
|
||||
import com.intellij.openapi.keymap.ex.KeymapManagerEx
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.startup.ProjectActivity
|
||||
import com.jetbrains.rd.util.ConcurrentHashMap
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.api.key
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.channels.BufferOverflow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
||||
// We use alarm with delay to avoid many actions in case many events are fired at the same time
|
||||
internal val correctorRequester = MutableSharedFlow<Unit>(replay=1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
|
||||
|
||||
private val LOG = logger<CopilotKeymapCorrector>()
|
||||
|
||||
internal class CopilotKeymapCorrector : ProjectActivity {
|
||||
override suspend fun execute(project: Project) {
|
||||
project.service<CopilotKeymapCorrectorService>().start()
|
||||
correctorRequester.emit(Unit)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* At the moment of release 2023.3 there is a problem that starting a coroutine like this
|
||||
* right in the project activity will block this project activity in tests.
|
||||
* To avoid that, there is an intermediate service that will allow to avoid this issue.
|
||||
*
|
||||
* However, in general we should start this coroutine right in the [CopilotKeymapCorrector]
|
||||
*/
|
||||
@OptIn(FlowPreview::class)
|
||||
@Service(Service.Level.PROJECT)
|
||||
internal class CopilotKeymapCorrectorService(private val cs: CoroutineScope) {
|
||||
fun start() {
|
||||
cs.launch {
|
||||
correctorRequester
|
||||
.debounce(5_000)
|
||||
.collectLatest { correctCopilotKeymap() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal class IdeaVimCorrectorKeymapChangedListener : KeymapManagerListener {
|
||||
override fun activeKeymapChanged(keymap: Keymap?) {
|
||||
check(correctorRequester.tryEmit(Unit))
|
||||
}
|
||||
|
||||
override fun shortcutChanged(keymap: Keymap, actionId: String) {
|
||||
check(correctorRequester.tryEmit(Unit))
|
||||
}
|
||||
|
||||
override fun shortcutChanged(keymap: Keymap, actionId: String, fromSettings: Boolean) {
|
||||
check(correctorRequester.tryEmit(Unit))
|
||||
}
|
||||
}
|
||||
|
||||
private val copilotHideActionMap = ConcurrentHashMap<String, Unit>()
|
||||
|
||||
/**
|
||||
* See VIM-3206
|
||||
* The user expected to both copilot suggestion and the insert mode to be exited on a single esc.
|
||||
* However, for the moment, the first esc hides copilot suggestion and the second one exits insert mode.
|
||||
* To fix this, we remove the esc shortcut from the copilot action if the IdeaVim is active.
|
||||
*
|
||||
* This workaround is not the best solution, however, I don't see the better way with the current architecture of
|
||||
* actions and EditorHandlers. Firstly, I wanted to suggest to copilot to migrate to EditorActionHandler as well,
|
||||
* but this doesn't seem correct for me because in this case the user will lose an ability to change the shorcut for
|
||||
* it. It seems like copilot has a similar problem as we do - we don't want to make a handler for "Editor enter action",
|
||||
* but a handler for the esc key press. And, moreover, be able to communicate with other plugins about the ordering.
|
||||
* Before this feature is implemented, hiding the copilot suggestion on esc looks like a good workaround.
|
||||
*/
|
||||
private fun correctCopilotKeymap() {
|
||||
// This is needed to initialize the injector in case this verification is called to fast
|
||||
VimPlugin.getInstance()
|
||||
|
||||
if (!enableOctopus) return
|
||||
if (injector.enabler.isEnabled()) {
|
||||
val keymap = KeymapManagerEx.getInstanceEx().activeKeymap
|
||||
val res = keymap.getShortcuts("copilot.disposeInlays")
|
||||
if (res.isEmpty()) return
|
||||
|
||||
|
||||
val escapeShortcut = res.find { it.toString() == "[pressed ESCAPE]" } ?: return
|
||||
keymap.removeShortcut("copilot.disposeInlays", escapeShortcut)
|
||||
copilotHideActionMap[keymap.name] = Unit
|
||||
LOG.info("Remove copilot escape shortcut from keymap ${keymap.name}")
|
||||
}
|
||||
else {
|
||||
copilotHideActionMap.forEach { (name, _) ->
|
||||
val keymap = KeymapManagerEx.getInstanceEx().getKeymap(name) ?: return@forEach
|
||||
val currentShortcuts = keymap.getShortcuts("copilot.disposeInlays")
|
||||
if ("[pressed ESCAPE]" !in currentShortcuts.map { it.toString() }) {
|
||||
keymap.addShortcut("copilot.disposeInlays", KeyboardShortcut(key("<esc>"), null))
|
||||
}
|
||||
LOG.info("Restore copilot escape shortcut in keymap ${keymap.name}")
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,14 +8,11 @@
|
||||
|
||||
package com.maddyhome.idea.vim.handler
|
||||
|
||||
import com.intellij.openapi.actionSystem.IdeActions
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandlerBean
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
import com.intellij.openapi.keymap.ex.KeymapManagerEx
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.startup.ProjectActivity
|
||||
import com.maddyhome.idea.vim.api.key
|
||||
import com.intellij.openapi.startup.StartupActivity
|
||||
|
||||
/**
|
||||
* Logs the chain of handlers for esc and enter
|
||||
@@ -29,13 +26,11 @@ import com.maddyhome.idea.vim.api.key
|
||||
* Strictly speaking, such access to the extension point is not allowed by the platform. But we can't do this thing
|
||||
* otherwise, so let's use it as long as we can.
|
||||
*/
|
||||
internal class EditorHandlersChainLogger : ProjectActivity {
|
||||
internal class EditorHandlersChainLogger : StartupActivity {
|
||||
@Suppress("UnresolvedPluginConfigReference")
|
||||
private val editorHandlers = ExtensionPointName<EditorActionHandlerBean>("com.intellij.editorActionHandler")
|
||||
|
||||
override suspend fun execute(project: Project) {
|
||||
if (!enableOctopus) return
|
||||
|
||||
override fun runActivity(project: Project) {
|
||||
val escHandlers = editorHandlers.extensionList
|
||||
.filter { it.action == "EditorEscape" }
|
||||
.joinToString("\n") { it.implementationClass }
|
||||
@@ -45,22 +40,6 @@ internal class EditorHandlersChainLogger : ProjectActivity {
|
||||
|
||||
LOG.info("Esc handlers chain:\n$escHandlers")
|
||||
LOG.info("Enter handlers chain:\n$enterHandlers")
|
||||
|
||||
val keymapManager = KeymapManagerEx.getInstanceEx()
|
||||
val keymap = keymapManager.activeKeymap
|
||||
val keymapShortcutsForEsc = keymap.getShortcuts(IdeActions.ACTION_EDITOR_ESCAPE).joinToString()
|
||||
val keymapShortcutsForEnter = keymap.getShortcuts(IdeActions.ACTION_EDITOR_ENTER).joinToString()
|
||||
|
||||
LOG.info("Active keymap (${keymap.name}) shortcuts for esc: $keymapShortcutsForEsc, Shortcuts for enter: $keymapShortcutsForEnter")
|
||||
|
||||
val actionsForEsc = keymap.getActionIds(key("<esc>")).joinToString("\n")
|
||||
val actionsForEnter = keymap.getActionIds(key("<enter>")).joinToString("\n")
|
||||
|
||||
LOG.info(
|
||||
"Also keymap (${keymap.name}) has " +
|
||||
"the following actions assigned to esc:\n$actionsForEsc " +
|
||||
"\nand following actions assigned to enter:\n$actionsForEnter"
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@@ -1,156 +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.handler
|
||||
|
||||
import com.intellij.openapi.actionSystem.IdeActions
|
||||
import com.intellij.openapi.actionSystem.KeyboardShortcut
|
||||
import com.intellij.openapi.actionSystem.Shortcut
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.keymap.Keymap
|
||||
import com.intellij.openapi.keymap.KeymapManagerListener
|
||||
import com.intellij.openapi.keymap.ex.KeymapManagerEx
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.startup.ProjectActivity
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.api.key
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.channels.BufferOverflow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
// We use alarm with delay to avoid many notifications in case many events are fired at the same time
|
||||
internal val keyCheckRequests = MutableSharedFlow<Unit>(replay=1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
|
||||
|
||||
/**
|
||||
* This checker verifies that the keymap has a correct configuration that is required for IdeaVim plugin
|
||||
*/
|
||||
internal class KeymapChecker : ProjectActivity {
|
||||
override suspend fun execute(project: Project) {
|
||||
project.service<KeymapCheckerService>().start()
|
||||
keyCheckRequests.emit(Unit)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* At the moment of release 2023.3 there is a problem that starting a coroutine like this
|
||||
* right in the project activity will block this project activity in tests.
|
||||
* To avoid that, there is an intermediate service that will allow to avoid this issue.
|
||||
*
|
||||
* However, in general we should start this coroutine right in the [KeymapChecker]
|
||||
*/
|
||||
@OptIn(FlowPreview::class)
|
||||
@Service(Service.Level.PROJECT)
|
||||
internal class KeymapCheckerService(private val cs: CoroutineScope) {
|
||||
fun start() {
|
||||
cs.launch {
|
||||
keyCheckRequests
|
||||
.debounce(5_000)
|
||||
.collectLatest { verifyKeymap() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class IdeaVimKeymapChangedListener : KeymapManagerListener {
|
||||
override fun activeKeymapChanged(keymap: Keymap?) {
|
||||
check(keyCheckRequests.tryEmit(Unit))
|
||||
}
|
||||
|
||||
override fun shortcutChanged(keymap: Keymap, actionId: String) {
|
||||
check(keyCheckRequests.tryEmit(Unit))
|
||||
}
|
||||
|
||||
override fun shortcutChanged(keymap: Keymap, actionId: String, fromSettings: Boolean) {
|
||||
check(keyCheckRequests.tryEmit(Unit))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* After migration to the editor action handlers, we have to make sure that the keymap has a correct configuration.
|
||||
* For example, that esc key is assigned to esc editor action
|
||||
*
|
||||
* Usually this is not a problem because this is a standard mapping, but the problem may appear in a misconfiguration
|
||||
* like it was in VIM-3204
|
||||
*/
|
||||
private fun verifyKeymap() {
|
||||
// This is needed to initialize the injector in case this verification is called to fast
|
||||
VimPlugin.getInstance()
|
||||
|
||||
if (!enableOctopus) return
|
||||
if (!injector.enabler.isEnabled()) return
|
||||
|
||||
val keymap = KeymapManagerEx.getInstanceEx().activeKeymap
|
||||
val keymapShortcutsForEsc = keymap.getShortcuts(IdeActions.ACTION_EDITOR_ESCAPE)
|
||||
val keymapShortcutsForEnter = keymap.getShortcuts(IdeActions.ACTION_EDITOR_ENTER)
|
||||
|
||||
val issues = ArrayList<KeyMapIssue>()
|
||||
val correctShortcutMissing = keymapShortcutsForEsc
|
||||
.filterIsInstance<KeyboardShortcut>()
|
||||
.none { it.firstKeyStroke.toString() == "pressed ESCAPE" && it.secondKeyStroke == null }
|
||||
|
||||
// We also check if there are any shortcuts starting from esc and with a second key. This should also be removed.
|
||||
// For example, VIM-3162 has a case when two escapes were assigned to editor escape action
|
||||
val shortcutsStartingFromEsc = keymapShortcutsForEsc
|
||||
.filterIsInstance<KeyboardShortcut>()
|
||||
.filter { it.firstKeyStroke.toString() == "pressed ESCAPE" && it.secondKeyStroke != null }
|
||||
if (correctShortcutMissing) {
|
||||
issues += KeyMapIssue.AddShortcut(
|
||||
"esc",
|
||||
"editor escape",
|
||||
IdeActions.ACTION_EDITOR_ESCAPE,
|
||||
key("<esc>")
|
||||
)
|
||||
}
|
||||
shortcutsStartingFromEsc.forEach {
|
||||
issues += KeyMapIssue.RemoveShortcut("editor escape", IdeActions.ACTION_EDITOR_ESCAPE, it)
|
||||
}
|
||||
|
||||
|
||||
val correctEnterShortcutMissing = keymapShortcutsForEnter
|
||||
.filterIsInstance<KeyboardShortcut>()
|
||||
.none { it.firstKeyStroke.toString() == "pressed ENTER" && it.secondKeyStroke == null }
|
||||
val shortcutsStartingFromEnter = keymapShortcutsForEnter
|
||||
.filterIsInstance<KeyboardShortcut>()
|
||||
.filter { it.firstKeyStroke.toString() == "pressed ENTER" && it.secondKeyStroke != null }
|
||||
if (correctEnterShortcutMissing) {
|
||||
issues += KeyMapIssue.AddShortcut(
|
||||
"enter",
|
||||
"editor enter",
|
||||
IdeActions.ACTION_EDITOR_ENTER,
|
||||
key("<enter>")
|
||||
)
|
||||
}
|
||||
shortcutsStartingFromEnter.forEach {
|
||||
issues += KeyMapIssue.RemoveShortcut("editor enter", IdeActions.ACTION_EDITOR_ENTER, it)
|
||||
}
|
||||
|
||||
if (issues.isNotEmpty()) {
|
||||
VimPlugin.getNotifications(null).notifyKeymapIssues(issues)
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed interface KeyMapIssue {
|
||||
data class AddShortcut(
|
||||
val key: String,
|
||||
val action: String,
|
||||
val actionId: String,
|
||||
val keyStroke: KeyStroke,
|
||||
) : KeyMapIssue
|
||||
|
||||
data class RemoveShortcut(
|
||||
val action: String,
|
||||
val actionId: String,
|
||||
val shortcut: Shortcut,
|
||||
): KeyMapIssue
|
||||
}
|
@@ -10,7 +10,6 @@ package com.maddyhome.idea.vim.handler
|
||||
|
||||
import com.intellij.codeInsight.editorActions.AutoHardWrapHandler
|
||||
import com.intellij.codeInsight.lookup.LookupManager
|
||||
import com.intellij.formatting.LineWrappingUtil
|
||||
import com.intellij.ide.DataManager
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
@@ -19,7 +18,6 @@ import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler
|
||||
import com.intellij.openapi.editor.actions.SplitLineAction
|
||||
import com.intellij.openapi.editor.impl.CaretModelImpl
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||
import com.intellij.openapi.util.Key
|
||||
@@ -27,7 +25,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
|
||||
@@ -53,7 +50,7 @@ internal val commandContinuation = Key.create<EditorActionHandler>("commandConti
|
||||
*/
|
||||
internal class CaretShapeEnterEditorHandler(private val nextHandler: EditorActionHandler) : EditorActionHandler() {
|
||||
override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext?) {
|
||||
if (VimPlugin.isEnabled() && enableOctopus) {
|
||||
if (VimPlugin.isEnabled()) {
|
||||
invokeLater {
|
||||
editor.updateCaretsVisualAttributes()
|
||||
}
|
||||
@@ -98,15 +95,7 @@ internal abstract class OctopusHandler(private val nextHandler: EditorActionHand
|
||||
// the condition (see VIM-3103 for example).
|
||||
// Since we can't make sure we don't execute `runForEachCaret`, we have to "escape" out of this function. This is
|
||||
// done by scheduling the execution of our code later via the invokeLater function.
|
||||
//
|
||||
// We run this job only once for a primary caret. In the handler itself, we'll multiply the execution by the
|
||||
// number of carets. If we run this job for each caret, we may end up in the issue like VIM-3186.
|
||||
// However, I think that we may do some refactoring to run this job for each caret (if needed).
|
||||
//
|
||||
// For the moment, the known case when the caret is null - work in injected editor - VIM-3195
|
||||
if (caret == null || caret == editor.caretModel.primaryCaret) {
|
||||
ApplicationManager.getApplication().invokeLater(executionHandler)
|
||||
}
|
||||
ApplicationManager.getApplication().invokeLater(executionHandler)
|
||||
} else {
|
||||
executionHandler()
|
||||
}
|
||||
@@ -117,19 +106,14 @@ internal abstract class OctopusHandler(private val nextHandler: EditorActionHand
|
||||
|
||||
private fun executeInInvokeLater(editor: Editor): Boolean {
|
||||
// Currently we have a workaround for the PY console VIM-3157
|
||||
val fileName = FileDocumentManager.getInstance().getFile(editor.document)?.name
|
||||
if (
|
||||
fileName == "Python Console.py" || // This is the name in 232+
|
||||
fileName == "Python Console" // This is the name in 231
|
||||
) return false
|
||||
if (FileDocumentManager.getInstance().getFile(editor.document)?.name == "Python Console.py") return false
|
||||
return (editor.caretModel as? CaretModelImpl)?.isIteratingOverCarets ?: true
|
||||
}
|
||||
|
||||
private fun isThisHandlerEnabled(editor: Editor, caret: Caret?, dataContext: DataContext?): Boolean {
|
||||
if (VimPlugin.isNotEnabled()) return false
|
||||
if (!VimPlugin.isEnabled()) return false
|
||||
if (!isHandlerEnabled(editor, dataContext)) return false
|
||||
if (isNotActualKeyPress(dataContext)) return false
|
||||
if (!enableOctopus) return false
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -147,20 +131,7 @@ internal abstract class OctopusHandler(private val nextHandler: EditorActionHand
|
||||
return true
|
||||
}
|
||||
|
||||
// From VIM-3177
|
||||
val wrapLongLineDuringFormattingInProgress = dataManager
|
||||
.loadFromDataContext(dataContext, LineWrappingUtil.WRAP_LONG_LINE_DURING_FORMATTING_IN_PROGRESS_KEY)
|
||||
if (wrapLongLineDuringFormattingInProgress == true) {
|
||||
return true
|
||||
}
|
||||
|
||||
// From VIM-3203
|
||||
val splitLineInProgress = dataManager.loadFromDataContext(dataContext, SplitLineAction.SPLIT_LINE_KEY)
|
||||
if (splitLineInProgress == true) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (dataManager.loadFromDataContext(dataContext, StartNewLineDetectorBase.Util.key) == true) {
|
||||
if (dataManager.loadFromDataContext(dataContext, ShiftEnterDetector.Util.key) == true) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -231,7 +202,7 @@ internal class VimEscHandler(nextHandler: EditorActionHandler) : VimKeyHandler(n
|
||||
}
|
||||
|
||||
/**
|
||||
* Rider (and CLion Nova) uses a separate handler for esc to close the completion. IdeaOnlyEscapeHandlerAction is especially
|
||||
* Rider uses a separate handler for esc to close the completion. IdeaOnlyEscapeHandlerAction is especially
|
||||
* designer to get all the esc presses, and if there is a completion close it and do not pass the execution further.
|
||||
* This doesn't work the same as in IJ.
|
||||
* In IdeaVim, we'd like to exit insert mode on closing completion. This is a requirement as the change of this
|
||||
@@ -244,7 +215,6 @@ internal class VimEscForRiderHandler(nextHandler: EditorActionHandler) : VimKeyH
|
||||
override val key: String = "<Esc>"
|
||||
|
||||
override fun isHandlerEnabled(editor: Editor, dataContext: DataContext?): Boolean {
|
||||
if (!enableOctopus) return false
|
||||
return LookupManager.getActiveLookup(editor) != null
|
||||
}
|
||||
}
|
||||
@@ -260,9 +230,7 @@ internal class VimEscForRiderHandler(nextHandler: EditorActionHandler) : VimKeyH
|
||||
*/
|
||||
internal class VimEscLoggerHandler(private val nextHandler: EditorActionHandler) : EditorActionHandler() {
|
||||
override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext?) {
|
||||
if (enableOctopus) {
|
||||
LOG.info("Esc pressed")
|
||||
}
|
||||
LOG.info("Esc pressed")
|
||||
nextHandler.execute(editor, caret, dataContext)
|
||||
}
|
||||
|
||||
@@ -276,21 +244,13 @@ internal class VimEscLoggerHandler(private val nextHandler: EditorActionHandler)
|
||||
}
|
||||
|
||||
/**
|
||||
* Workaround to support "Start New Line" action in normal mode.
|
||||
* IJ executes enter handler on "Start New Line". This causes an issue that IdeaVim thinks that this is just an enter key.
|
||||
* Workaround to support shift-enter in normal mode.
|
||||
* IJ executes enter handler on shift-enter. This causes an issue that IdeaVim thinks that this is just an enter key.
|
||||
* This thing should be refactored, but for now we'll use this workaround VIM-3159
|
||||
*
|
||||
* The Same thing happens with "Start New Line Before Current" action.
|
||||
*/
|
||||
internal class StartNewLineDetector(nextHandler: EditorActionHandler) : StartNewLineDetectorBase(nextHandler)
|
||||
internal class StartNewLineBeforeCurrentDetector(nextHandler: EditorActionHandler) :
|
||||
StartNewLineDetectorBase(nextHandler)
|
||||
|
||||
internal open class StartNewLineDetectorBase(private val nextHandler: EditorActionHandler) : EditorActionHandler() {
|
||||
internal class ShiftEnterDetector(private val nextHandler: EditorActionHandler) : EditorActionHandler() {
|
||||
override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext?) {
|
||||
if (enableOctopus) {
|
||||
DataManager.getInstance().saveInDataContext(dataContext, Util.key, true)
|
||||
}
|
||||
DataManager.getInstance().saveInDataContext(dataContext, Util.key, true)
|
||||
nextHandler.execute(editor, caret, dataContext)
|
||||
}
|
||||
|
||||
@@ -299,7 +259,7 @@ internal open class StartNewLineDetectorBase(private val nextHandler: EditorActi
|
||||
}
|
||||
|
||||
object Util {
|
||||
val key = Key.create<Boolean>("vim.is.start.new.line")
|
||||
val key = Key.create<Boolean>("vim.is.shift.enter")
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -318,9 +278,7 @@ internal open class StartNewLineDetectorBase(private val nextHandler: EditorActi
|
||||
*/
|
||||
internal class VimEnterLoggerHandler(private val nextHandler: EditorActionHandler) : EditorActionHandler() {
|
||||
override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext?) {
|
||||
if (enableOctopus) {
|
||||
LOG.info("Enter pressed")
|
||||
}
|
||||
LOG.info("Enter pressed")
|
||||
nextHandler.execute(editor, caret, dataContext)
|
||||
}
|
||||
|
||||
@@ -350,16 +308,12 @@ internal abstract class VimKeyHandler(nextHandler: EditorActionHandler?) : Octop
|
||||
}
|
||||
|
||||
internal fun isOctopusEnabled(s: KeyStroke, editor: Editor): Boolean {
|
||||
if (!enableOctopus) return false
|
||||
// CMD line has a different processing mechanizm: the processing actions are registered
|
||||
// for the input field component. These keys are not dispatched via the octopus handler.
|
||||
if (editor.vim.mode is Mode.CMD_LINE) return false
|
||||
when {
|
||||
s.keyCode == KeyEvent.VK_ENTER && s.modifiers == 0 -> return true
|
||||
s.keyCode == KeyEvent.VK_ESCAPE && s.modifiers == 0 -> return true
|
||||
when (s.keyCode) {
|
||||
KeyEvent.VK_ENTER -> return true
|
||||
KeyEvent.VK_ESCAPE -> return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
internal val enableOctopus: Boolean
|
||||
get() = injector.globalOptions().octopushandler
|
||||
|
@@ -81,7 +81,7 @@ private fun Editor.guicursorMode(): GuiCursorMode {
|
||||
private fun isBlockCursorOverride() = EditorSettingsExternalizable.getInstance().isBlockCursor
|
||||
|
||||
private fun Editor.updatePrimaryCaretVisualAttributes() {
|
||||
if (VimPlugin.isNotEnabled()) thisLogger().error("The caret attributes should not be updated if the IdeaVim is disabled")
|
||||
if (!VimPlugin.isEnabled()) thisLogger().error("The caret attributes should not be updated if the IdeaVim is disabled")
|
||||
caretModel.primaryCaret.visualAttributes = AttributesCache.getCaretVisualAttributes(this)
|
||||
|
||||
// Make sure the caret is visible as soon as it's set. It might be invisible while blinking
|
||||
@@ -89,7 +89,7 @@ private fun Editor.updatePrimaryCaretVisualAttributes() {
|
||||
}
|
||||
|
||||
private fun Editor.updateSecondaryCaretsVisualAttributes() {
|
||||
if (VimPlugin.isNotEnabled()) thisLogger().error("The caret attributes should not be updated if the IdeaVim is disabled")
|
||||
if (!VimPlugin.isEnabled()) thisLogger().error("The caret attributes should not be updated if the IdeaVim is disabled")
|
||||
// IntelliJ simulates visual block with multiple carets with selections. Do our best to hide them
|
||||
val attributes = if (this.vim.inBlockSelection) HIDDEN else AttributesCache.getCaretVisualAttributes(this)
|
||||
this.caretModel.allCarets.forEach {
|
||||
|
@@ -36,7 +36,7 @@ public val Editor.mode: CommandState.Mode
|
||||
get() {
|
||||
val mode = this.vim.vimStateMachine.mode
|
||||
return when (mode) {
|
||||
is Mode.CMD_LINE -> CommandState.Mode.CMD_LINE
|
||||
Mode.CMD_LINE -> CommandState.Mode.CMD_LINE
|
||||
Mode.INSERT -> CommandState.Mode.INSERT
|
||||
is Mode.NORMAL -> CommandState.Mode.COMMAND
|
||||
is Mode.OP_PENDING -> CommandState.Mode.OP_PENDING
|
||||
|
@@ -46,6 +46,12 @@ public class EditorHelper {
|
||||
return editor.getScrollingModel().getVisibleAreaOnScrollingFinished();
|
||||
}
|
||||
|
||||
//("Use extension function with the same name on VimEditor")
|
||||
@Deprecated
|
||||
public static boolean isLineEmpty(final @NotNull Editor editor, final int line, final boolean allowBlanks) {
|
||||
return EngineEditorHelperKt.isLineEmpty(new IjVimEditor(editor), line, allowBlanks);
|
||||
}
|
||||
|
||||
public static boolean scrollVertically(@NotNull Editor editor, int verticalOffset) {
|
||||
final ScrollingModel scrollingModel = editor.getScrollingModel();
|
||||
final Rectangle area = scrollingModel.getVisibleAreaOnScrollingFinished();
|
||||
|
@@ -23,6 +23,43 @@ import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.state.mode.inBlockSelection
|
||||
import java.util.stream.Collectors
|
||||
|
||||
/**
|
||||
* This annotation is created for test functions (methods).
|
||||
* It means that the original vim behavior has small differences from behavior of IdeaVim.
|
||||
* [shouldBeFixed] flag indicates whether the given functionality should be fixed
|
||||
* or the given behavior is normal for IdeaVim and should be leaved as is.
|
||||
*
|
||||
* E.g. after execution of some commands original vim has the following text:
|
||||
* Hello1
|
||||
* Hello2
|
||||
* Hello3
|
||||
*
|
||||
* But IdeaVim gives you:
|
||||
* Hello1
|
||||
*
|
||||
* Hello2
|
||||
* Hello3
|
||||
*
|
||||
* In this case you should still create the test function and mark this function with [VimBehaviorDiffers] annotation.
|
||||
*
|
||||
* Why does this annotation exist?
|
||||
* After creating some functionality you can understand that IdeaVim has a bit different behavior, but you
|
||||
* cannot fix it right now because of any reason (bugs in IDE,
|
||||
* the impossibility of this functionality in IDEA (*[shouldBeFixed] == false*), leak of time for fixing).
|
||||
* In that case, you should NOT remove the corresponding test or leave it without any marks that this test
|
||||
* not fully convenient with vim, but leave the test with IdeaVim's behavior and put this annotation
|
||||
* with description of how original vim works.
|
||||
*
|
||||
* Note that using this annotation should be avoided as much as possible and behavior of IdeaVim should be as close
|
||||
* to vim as possible.
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
internal annotation class VimBehaviorDiffers(
|
||||
val originalVimAfter: String = "",
|
||||
val description: String = "",
|
||||
val shouldBeFixed: Boolean = true,
|
||||
)
|
||||
|
||||
internal fun <T : Comparable<T>> sort(a: T, b: T) = if (a > b) b to a else a to b
|
||||
|
||||
// TODO Should be replaced with VimEditor.carets()
|
||||
@@ -73,7 +110,7 @@ internal fun Editor.isTemplateActive(): Boolean {
|
||||
}
|
||||
|
||||
private fun vimEnabled(editor: Editor?): Boolean {
|
||||
if (VimPlugin.isNotEnabled()) return false
|
||||
if (!VimPlugin.isEnabled()) return false
|
||||
if (editor != null && editor.isIdeaVimDisabledHere) return false
|
||||
return true
|
||||
}
|
||||
|
@@ -15,12 +15,10 @@ import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.actionSystem.AnActionResult
|
||||
import com.intellij.openapi.actionSystem.DataContextWrapper
|
||||
import com.intellij.openapi.actionSystem.EmptyAction
|
||||
import com.intellij.openapi.actionSystem.IdeActions
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys
|
||||
import com.intellij.openapi.actionSystem.ex.ActionManagerEx
|
||||
import com.intellij.openapi.actionSystem.ex.ActionUtil
|
||||
import com.intellij.openapi.actionSystem.impl.ProxyShortcutSet
|
||||
import com.intellij.openapi.command.CommandProcessor
|
||||
import com.intellij.openapi.command.UndoConfirmationPolicy
|
||||
import com.intellij.openapi.components.Service
|
||||
@@ -41,8 +39,6 @@ import com.maddyhome.idea.vim.newapi.IjNativeAction
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.newapi.runFromVimKey
|
||||
import org.jetbrains.annotations.NonNls
|
||||
import java.awt.Component
|
||||
import javax.swing.JComponent
|
||||
import javax.swing.SwingUtilities
|
||||
|
||||
@Service
|
||||
@@ -143,7 +139,7 @@ internal class IjActionExecutor : VimActionExecutor {
|
||||
manager.fireAfterActionPerformed(action, event, result!!)
|
||||
}
|
||||
if (indexError != null) {
|
||||
ActionUtil.showDumbModeWarning(project, action, event)
|
||||
ActionUtil.showDumbModeWarning(project, event)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,43 +150,10 @@ internal class IjActionExecutor : VimActionExecutor {
|
||||
* @param context The context to run it in
|
||||
*/
|
||||
override fun executeAction(name: @NonNls String, context: ExecutionContext): Boolean {
|
||||
val action = getAction(name, context)
|
||||
val aMgr = ActionManager.getInstance()
|
||||
val action = aMgr.getAction(name)
|
||||
return action != null && executeAction(null, IjNativeAction(action), context)
|
||||
}
|
||||
|
||||
private fun getAction(name: String, context: ExecutionContext): AnAction? {
|
||||
val actionManager = ActionManager.getInstance()
|
||||
val action = actionManager.getAction(name)
|
||||
if (action !is EmptyAction) return action
|
||||
|
||||
// But if the action is an instance of EmptyAction, the fun begins
|
||||
var component: Component? = context.ij.getData(PlatformDataKeys.CONTEXT_COMPONENT) ?: return null
|
||||
while (component != null) {
|
||||
if (component !is JComponent) {
|
||||
component = component.parent
|
||||
continue
|
||||
}
|
||||
|
||||
val listOfActions = ActionUtil.getActions(component)
|
||||
if (listOfActions.isEmpty()) {
|
||||
component = component.getParent()
|
||||
continue
|
||||
}
|
||||
|
||||
fun AnAction.getId(): String? {
|
||||
return actionManager.getId(this)
|
||||
?: (shortcutSet as? ProxyShortcutSet)?.actionId
|
||||
}
|
||||
|
||||
for (action in listOfActions) {
|
||||
if (action.getId() == name) {
|
||||
return action
|
||||
}
|
||||
}
|
||||
component = component.getParent()
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override fun executeCommand(
|
||||
editor: VimEditor?,
|
||||
|
@@ -9,7 +9,6 @@
|
||||
package com.maddyhome.idea.vim.helper;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerEx;
|
||||
import com.intellij.lang.CodeDocumentationAwareCommenter;
|
||||
import com.intellij.lang.Commenter;
|
||||
import com.intellij.lang.Language;
|
||||
@@ -17,17 +16,15 @@ import com.intellij.lang.LanguageCommenters;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.spellchecker.SpellCheckerSeveritiesProvider;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.api.EngineEditorHelperKt;
|
||||
import com.maddyhome.idea.vim.api.VimEditor;
|
||||
import com.maddyhome.idea.vim.regexp.*;
|
||||
import com.maddyhome.idea.vim.regexp.match.VimMatchResult;
|
||||
import com.maddyhome.idea.vim.state.mode.Mode;
|
||||
import com.maddyhome.idea.vim.state.VimStateMachine;
|
||||
import com.maddyhome.idea.vim.common.CharacterPosition;
|
||||
import com.maddyhome.idea.vim.common.Direction;
|
||||
import com.maddyhome.idea.vim.common.TextRange;
|
||||
@@ -35,12 +32,6 @@ import com.maddyhome.idea.vim.newapi.IjVimCaret;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import com.maddyhome.idea.vim.regexp.CharPointer;
|
||||
import com.maddyhome.idea.vim.regexp.RegExp;
|
||||
import com.maddyhome.idea.vim.state.VimStateMachine;
|
||||
import com.maddyhome.idea.vim.state.mode.Mode;
|
||||
import it.unimi.dsi.fastutil.ints.IntComparator;
|
||||
import it.unimi.dsi.fastutil.ints.IntIterator;
|
||||
import it.unimi.dsi.fastutil.ints.IntRBTreeSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSortedSet;
|
||||
import kotlin.Pair;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -51,10 +42,10 @@ import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.maddyhome.idea.vim.api.VimInjectorKt.*;
|
||||
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.SearchHelperKtKt.checkInString;
|
||||
import static com.maddyhome.idea.vim.helper.SearchHelperKtKt.shouldIgnoreCase;
|
||||
import static com.maddyhome.idea.vim.newapi.IjVimInjectorKt.globalIjOptions;
|
||||
|
||||
/**
|
||||
* Helper methods for searching text
|
||||
@@ -68,8 +59,6 @@ public class SearchHelper {
|
||||
/**
|
||||
* Find text matching the given pattern.
|
||||
*
|
||||
* @deprecated Use IjVimSearchHelper.findPattern instead
|
||||
*
|
||||
* <p>See search.c:searchit</p>
|
||||
*
|
||||
* @param editor The editor to search in
|
||||
@@ -80,13 +69,12 @@ public class SearchHelper {
|
||||
* @return A TextRange representing the result, or null
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
public static TextRange findPattern(@NotNull Editor editor,
|
||||
@Nullable String pattern,
|
||||
int startOffset,
|
||||
int count,
|
||||
EnumSet<SearchOptions> searchOptions) {
|
||||
if (pattern == null || pattern.isEmpty()) {
|
||||
if (pattern == null || pattern.length() == 0) {
|
||||
logger.warn("Pattern is null or empty. Cannot perform search");
|
||||
return null;
|
||||
}
|
||||
@@ -359,8 +347,6 @@ public class SearchHelper {
|
||||
/**
|
||||
* Find all occurrences of the pattern.
|
||||
*
|
||||
* @deprecated Use IjVimSearchHelper.findall instead
|
||||
*
|
||||
* @param editor The editor to search in
|
||||
* @param pattern The pattern to search for
|
||||
* @param startLine The start line of the range to search for
|
||||
@@ -368,33 +354,12 @@ public class SearchHelper {
|
||||
* @param ignoreCase Case sensitive or insensitive searching
|
||||
* @return A list of TextRange objects representing the results
|
||||
*/
|
||||
@Deprecated
|
||||
public static @NotNull List<TextRange> findAll(@NotNull Editor editor,
|
||||
@NotNull String pattern,
|
||||
int startLine,
|
||||
int endLine,
|
||||
boolean ignoreCase) {
|
||||
final List<TextRange> results = Lists.newArrayList();
|
||||
|
||||
if (globalIjOptions(injector).getUseNewRegex()) {
|
||||
final List<VimRegexOptions> options = new ArrayList<>();
|
||||
if (globalOptions(injector).getSmartcase()) options.add(VimRegexOptions.SMART_CASE);
|
||||
if (globalOptions(injector).getIgnorecase()) options.add(VimRegexOptions.IGNORE_CASE);
|
||||
VimEditor vimEditor = new IjVimEditor(editor);
|
||||
try {
|
||||
// TODO: we shouldn't care about the ignoreCase argument, and instead just look into the editor options.
|
||||
// It would require a refactor, so for now prepend \c or \C to "force" ignoreCase
|
||||
String newPattern = (ignoreCase ? "\\c" : "\\C") + pattern;
|
||||
VimRegex regex = new VimRegex(newPattern);
|
||||
List<VimMatchResult.Success> foundMatches = regex.findAll(vimEditor, vimEditor.getLineStartOffset(startLine), vimEditor.getLineEndOffset(endLine == -1 ? vimEditor.lineCount() - 1 : endLine) + 1, options);
|
||||
for (VimMatchResult.Success match : foundMatches) results.add(match.getRange());
|
||||
return results;
|
||||
} catch (VimRegexException e) {
|
||||
injector.getMessages().showStatusBarMessage(vimEditor, e.getMessage());
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
final int lineCount = new IjVimEditor(editor).lineCount();
|
||||
final int actualEndLine = endLine == -1 ? lineCount - 1 : endLine;
|
||||
|
||||
@@ -437,10 +402,6 @@ public class SearchHelper {
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use IjVimSearchHelper.findSection instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static int findSection(@NotNull Editor editor, @NotNull Caret caret, char type, int dir, int count) {
|
||||
CharSequence chars = editor.getDocument().getCharsSequence();
|
||||
int line = caret.getLogicalPosition().line + dir;
|
||||
@@ -467,10 +428,6 @@ public class SearchHelper {
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use IjVimSearchHelper.findUnmatchedBlock instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static int findUnmatchedBlock(@NotNull Editor editor, @NotNull Caret caret, char type, int count) {
|
||||
CharSequence chars = editor.getDocument().getCharsSequence();
|
||||
int pos = caret.getOffset();
|
||||
@@ -490,8 +447,6 @@ public class SearchHelper {
|
||||
/**
|
||||
* Find block enclosing the caret
|
||||
*
|
||||
* @deprecated Use IjVimSearchHelper.findBlockRange instead
|
||||
*
|
||||
* @param editor The editor to search in
|
||||
* @param caret The caret currently at
|
||||
* @param type The type of block, e.g. (, [, {, <
|
||||
@@ -843,10 +798,6 @@ public class SearchHelper {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated Use IjVimSearchHelper.findBlockTagRange instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static @Nullable TextRange findBlockTagRange(@NotNull Editor editor,
|
||||
@NotNull Caret caret,
|
||||
int count,
|
||||
@@ -1379,10 +1330,6 @@ public class SearchHelper {
|
||||
return new TextRange(start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use IjVimSearchHelper.findWordUnderCursor instead
|
||||
*/
|
||||
@Deprecated
|
||||
@Contract("_, _, _, _, _, _, _ -> new")
|
||||
public static @NotNull TextRange findWordUnderCursor(@NotNull Editor editor,
|
||||
@NotNull Caret caret,
|
||||
@@ -1568,56 +1515,14 @@ public class SearchHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use IjVimSearchHelper.findMethodStart instead
|
||||
*/
|
||||
public static int findMethodStart(@NotNull Editor editor, @NotNull Caret caret, int count) {
|
||||
return PsiHelper.findMethodStart(editor, caret.getOffset(), count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use IjVimSearchHelper.findMethodEnd instead
|
||||
*/
|
||||
public static int findMethodEnd(@NotNull Editor editor, @NotNull Caret caret, int count) {
|
||||
return PsiHelper.findMethodEnd(editor, caret.getOffset(), count);
|
||||
}
|
||||
|
||||
public static int findMisspelledWords(@NotNull Editor editor,
|
||||
int startOffset,
|
||||
int endOffset,
|
||||
int skipCount,
|
||||
IntComparator offsetOrdering) {
|
||||
Project project = editor.getProject();
|
||||
if (project == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
IntSortedSet offsets = new IntRBTreeSet(offsetOrdering);
|
||||
DaemonCodeAnalyzerEx.processHighlights(editor.getDocument(), project, SpellCheckerSeveritiesProvider.TYPO,
|
||||
startOffset, endOffset, highlight -> {
|
||||
if (highlight.getSeverity() == SpellCheckerSeveritiesProvider.TYPO) {
|
||||
int offset = highlight.getStartOffset();
|
||||
if (offset >= startOffset && offset <= endOffset) {
|
||||
offsets.add(offset);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (offsets.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (skipCount >= offsets.size()) {
|
||||
return offsets.lastInt();
|
||||
}
|
||||
else {
|
||||
IntIterator offsetIterator = offsets.iterator();
|
||||
offsetIterator.skip(skipCount);
|
||||
return offsetIterator.nextInt();
|
||||
}
|
||||
}
|
||||
|
||||
private static @NotNull String parseMatchPairsOption(final VimEditor vimEditor) {
|
||||
List<String> pairs = options(injector, vimEditor).getMatchpairs();
|
||||
StringBuilder res = new StringBuilder();
|
||||
|
@@ -26,7 +26,6 @@ import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.api.options
|
||||
import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.ex.ranges.LineRange
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import org.jetbrains.annotations.Contract
|
||||
import java.awt.Color
|
||||
@@ -106,7 +105,7 @@ private fun updateSearchHighlights(
|
||||
val startLine = searchRange?.startLine ?: 0
|
||||
val endLine = searchRange?.endLine ?: -1
|
||||
val results =
|
||||
injector.searchHelper.findAll(IjVimEditor(editor), pattern, startLine, endLine, shouldIgnoreCase(pattern, shouldIgnoreSmartCase))
|
||||
SearchHelper.findAll(editor, pattern, startLine, endLine, shouldIgnoreCase(pattern, shouldIgnoreSmartCase))
|
||||
if (results.isNotEmpty()) {
|
||||
currentMatchOffset = findClosestMatch(editor, results, initialOffset, forwards)
|
||||
highlightSearchResults(editor, pattern, results, currentMatchOffset)
|
||||
@@ -120,7 +119,7 @@ private fun updateSearchHighlights(
|
||||
}
|
||||
if (shouldIgnoreSmartCase) searchOptions.add(SearchOptions.IGNORE_SMARTCASE)
|
||||
if (!forwards) searchOptions.add(SearchOptions.BACKWARDS)
|
||||
val result = injector.searchHelper.findPattern(IjVimEditor(editor), pattern, initialOffset, 1, searchOptions)
|
||||
val result = SearchHelper.findPattern(editor, pattern, initialOffset, 1, searchOptions)
|
||||
if (result != null) {
|
||||
currentMatchOffset = result.startOffset
|
||||
val results = listOf(result)
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user