1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2024-10-18 01:42:46 +02:00

Compare commits

..

No commits in common. "9dbe3c3363a1bfb6874a4bec9a1ea31ae2122751" and "36370228904528af8b3b14a6adb1187045e958b2" have entirely different histories.

1187 changed files with 31437 additions and 39484 deletions

6
.gitignore vendored
View File

@ -10,9 +10,9 @@
!/.idea/runConfigurations
!/.idea/codeStyles
**/build/
**/out/
**/tmp/
/build/
/out/
/tmp/
*.DS_Store

View File

@ -5,10 +5,11 @@ object Constants {
const val EAP_CHANNEL = "eap"
const val DEV_CHANNEL = "Dev"
const val VERSION = "1.10.3"
const val DEV_VERSION = "1.11.0"
const val VERSION = "1.9.3"
const val DEV_VERSION = "1.10.0"
const val GITHUB_TESTS = "LATEST-EAP-SNAPSHOT"
const val LINTING_TESTS = "LATEST-EAP-SNAPSHOT"
const val NVIM_TESTS = "LATEST-EAP-SNAPSHOT"
const val PROPERTY_TESTS = "LATEST-EAP-SNAPSHOT"
const val LONG_RUNNING_TESTS = "LATEST-EAP-SNAPSHOT"

View File

@ -9,8 +9,6 @@ import _Self.vcsRoots.Branch_183
import _Self.vcsRoots.Branch_191_193
import _Self.vcsRoots.Branch_201
import _Self.vcsRoots.Branch_202
import _Self.vcsRoots.Branch_203_212
import _Self.vcsRoots.Branch_Release
import _Self.vcsRoots.GitHubPullRequest
import jetbrains.buildServer.configs.kotlin.v2019_2.Project
@ -25,12 +23,12 @@ object Project : Project({
vcsRoot(Branch_191_193)
vcsRoot(Branch_201)
vcsRoot(Branch_202)
vcsRoot(Branch_203_212)
vcsRoot(Branch_Release)
vcsRoot(GitHubPullRequest)
// Builds
buildType(TestsForIntelliJ20213)
buildType(TestsForIntelliJ20203)
buildType(TestsForIntelliJ20211)
buildType(TestsForIntelliJ20212)
buildType(TestsForIntelliJEAP)
buildType(PropertyBased)

View File

@ -55,4 +55,6 @@ sealed class ActiveTests(buildName: String, ijVersion: String) : BuildType({
})
object TestsForIntelliJEAP : ActiveTests("Tests for IntelliJ Latest EAP", "LATEST-EAP-SNAPSHOT")
object TestsForIntelliJ20213 : ActiveTests("Tests for IntelliJ 2021.3", "2021.3.2")
object TestsForIntelliJ20212 : ActiveTests("Tests for IntelliJ 2021.2", "2021.2.2")
object TestsForIntelliJ20211 : ActiveTests("Tests for IntelliJ 2021.1", "2021.1")
object TestsForIntelliJ20203 : ActiveTests("Tests for IntelliJ 2020.3", "2020.3")

View File

@ -28,15 +28,11 @@ object Qodana : BuildType({
steps {
qodana {
name = "Qodana"
/*
reportAsTestsEnable = ""
failBuildOnErrors = ""
codeInspectionXmlConfig = "Custom"
codeInspectionCustomXmlConfigPath = ".idea/inspectionProfiles/Qodana.xml"
reportAsTestsEnable = "true"
*/
clearConditions()
param("licenseaudit-enable", "true")
param("clonefinder-languages", "Java")
param("clonefinder-mode", "")
param("report-version", "")

View File

@ -5,7 +5,6 @@ import _Self.Constants.DEV_CHANNEL
import _Self.Constants.EAP_CHANNEL
import _Self.Constants.RELEASE
import _Self.Constants.VERSION
import _Self.vcsRoots.Branch_Release
import jetbrains.buildServer.configs.kotlin.v2019_2.BuildType
import jetbrains.buildServer.configs.kotlin.v2019_2.CheckoutMode
import jetbrains.buildServer.configs.kotlin.v2019_2.DslContext
@ -39,7 +38,7 @@ object Release : BuildType({
}
vcs {
root(Branch_Release)
root(DslContext.settingsRoot)
checkoutMode = CheckoutMode.AUTO
}

View File

@ -1,64 +0,0 @@
@file:Suppress("ClassName")
package _Self.buildTypes
import jetbrains.buildServer.configs.kotlin.v2019_2.BuildType
import jetbrains.buildServer.configs.kotlin.v2019_2.CheckoutMode
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.gradle
import jetbrains.buildServer.configs.kotlin.v2019_2.failureConditions.BuildFailureOnMetric
import jetbrains.buildServer.configs.kotlin.v2019_2.failureConditions.failOnMetricChange
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.vcs
sealed class TestsForIntelliJ_203_212_branch(private val version: String) : BuildType({
name = "Tests for IntelliJ $version"
params {
param("env.ORG_GRADLE_PROJECT_downloadIdeaSources", "false")
param("env.ORG_GRADLE_PROJECT_legacyNoJavaPlugin", "true")
param("env.ORG_GRADLE_PROJECT_ideaVersion", "IC-$version")
param("env.ORG_GRADLE_PROJECT_instrumentPluginCode", "false")
param("env.ORG_GRADLE_PROJECT_javaVersion", "1.8")
}
vcs {
root(_Self.vcsRoots.Branch_203_212)
checkoutMode = CheckoutMode.AUTO
}
steps {
gradle {
tasks = "clean test"
buildFile = ""
enableStacktrace = true
param("org.jfrog.artifactory.selectedDeployableServer.defaultModuleVersionConfiguration", "GLOBAL")
}
}
triggers {
vcs {
branchFilter = ""
}
}
requirements {
noLessThanVer("teamcity.agent.jvm.version", "1.8")
}
failureConditions {
failOnMetricChange {
metric = BuildFailureOnMetric.MetricType.TEST_COUNT
threshold = 20
units = BuildFailureOnMetric.MetricUnit.PERCENTS
comparison = BuildFailureOnMetric.MetricComparison.LESS
compareTo = build {
buildRule = lastSuccessful()
}
}
}
})
object TestsForIntelliJ20212 : TestsForIntelliJ_203_212_branch("2021.2.2")
object TestsForIntelliJ20211 : TestsForIntelliJ_203_212_branch("2021.1")
object TestsForIntelliJ20203 : TestsForIntelliJ_203_212_branch("2020.3")

View File

@ -8,24 +8,18 @@ import _Self.buildTypes.TestsForIntelliJ20192
import _Self.buildTypes.TestsForIntelliJ20193
import _Self.buildTypes.TestsForIntelliJ20201
import _Self.buildTypes.TestsForIntelliJ20202
import _Self.buildTypes.TestsForIntelliJ20203
import _Self.buildTypes.TestsForIntelliJ20211
import _Self.buildTypes.TestsForIntelliJ20212
import jetbrains.buildServer.configs.kotlin.v2019_2.Project
object OldTests : Project({
name = "Old IdeaVim tests"
description = "Tests for older versions of IJ"
buildType(TestsForIntelliJ20181)
buildType(TestsForIntelliJ20182)
buildType(TestsForIntelliJ20183)
buildType(TestsForIntelliJ20191)
buildType(TestsForIntelliJ20192)
buildType(TestsForIntelliJ20193)
buildType(TestsForIntelliJ20201)
buildType(TestsForIntelliJ20202)
buildType(TestsForIntelliJ20203)
buildType(TestsForIntelliJ20211)
buildType(TestsForIntelliJ20212)
buildType(TestsForIntelliJ20201)
buildType(TestsForIntelliJ20191)
buildType(TestsForIntelliJ20181)
buildType(TestsForIntelliJ20192)
buildType(TestsForIntelliJ20182)
buildType(TestsForIntelliJ20193)
buildType(TestsForIntelliJ20183)
})

View File

@ -1,12 +0,0 @@
@file:Suppress("ClassName")
package _Self.vcsRoots
import jetbrains.buildServer.configs.kotlin.v2019_2.vcs.GitVcsRoot
object Branch_203_212 : GitVcsRoot({
name = "https://github.com/JetBrains/ideavim (branch 203-212)"
url = "https://github.com/JetBrains/ideavim.git"
branch = "203-212"
useMirrors = false
})

View File

@ -1,11 +0,0 @@
@file:Suppress("ClassName")
package _Self.vcsRoots
import jetbrains.buildServer.configs.kotlin.v2019_2.vcs.GitVcsRoot
object Branch_Release : GitVcsRoot({
name = "https://github.com/JetBrains/ideavim (branch release)"
url = "https://github.com/JetBrains/ideavim.git"
branch = "release"
})

View File

@ -1,25 +0,0 @@
package patches.buildTypes
import jetbrains.buildServer.configs.kotlin.v2019_2.*
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.VcsTrigger
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.vcs
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 = 'Nvim'
accordingly, and delete the patch script.
*/
changeBuildType(RelativeId("Nvim")) {
triggers {
val trigger1 = find<VcsTrigger> {
vcs {
branchFilter = ""
}
}
trigger1.apply {
enabled = false
}
}
}

View File

@ -1,25 +0,0 @@
package patches.buildTypes
import jetbrains.buildServer.configs.kotlin.v2019_2.*
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.VcsTrigger
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.vcs
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 = 'PluginVerifier'
accordingly, and delete the patch script.
*/
changeBuildType(RelativeId("PluginVerifier")) {
triggers {
val trigger1 = find<VcsTrigger> {
vcs {
branchFilter = ""
}
}
trigger1.apply {
enabled = false
}
}
}

View File

@ -3,8 +3,6 @@ package patches.buildTypes
import jetbrains.buildServer.configs.kotlin.v2019_2.*
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.Qodana
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.qodana
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.ScheduleTrigger
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.schedule
import jetbrains.buildServer.configs.kotlin.v2019_2.ui.*
/*
@ -16,18 +14,16 @@ changeBuildType(RelativeId("Qodana")) {
expectSteps {
qodana {
name = "Qodana"
reportAsTests = true
inspectionProfile = customProfile {
path = ".idea/inspectionProfiles/Qodana.xml"
}
reportAsTestsEnable = "true"
failBuildOnErrors = ""
codeInspectionXmlConfig = "Custom"
codeInspectionCustomXmlConfigPath = ".idea/inspectionProfiles/Qodana.xml"
param("clonefinder-enable", "true")
param("clonefinder-languages", "Java")
param("clonefinder-languages-container", "Java Kotlin")
param("clonefinder-mode", "")
param("clonefinder-queried-project", "src")
param("clonefinder-reference-projects", "src")
param("fail-build-on-errors", "")
param("licenseaudit-enable", "true")
param("namesAndTagsCustom", "repo.labs.intellij.net/static-analyser/qodana")
param("report-version", "")
param("yaml-configuration", "")
@ -36,25 +32,7 @@ changeBuildType(RelativeId("Qodana")) {
steps {
update<Qodana>(0) {
clearConditions()
linter = jvm {
version = Qodana.JVMVersion.LATEST
}
}
}
triggers {
val trigger1 = find<ScheduleTrigger> {
schedule {
schedulingPolicy = weekly {
dayOfWeek = ScheduleTrigger.DAY.Tuesday
}
branchFilter = ""
triggerBuild = always()
}
}
trigger1.apply {
enabled = false
param("licenseaudit-enable", "true")
}
}
}

View File

@ -0,0 +1,16 @@
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 = 'Release'
accordingly, and delete the patch script.
*/
changeBuildType(RelativeId("Release")) {
vcs {
remove(DslContext.settingsRoot.id!!)
add(RelativeId("Branch_Release"))
}
}

View File

@ -0,0 +1,18 @@
package patches.vcsRoots
import jetbrains.buildServer.configs.kotlin.v2019_2.*
import jetbrains.buildServer.configs.kotlin.v2019_2.ui.*
import jetbrains.buildServer.configs.kotlin.v2019_2.vcs.GitVcsRoot
/*
This patch script was generated by TeamCity on settings change in UI.
To apply the patch, create a vcsRoot with id = 'Branch_Release'
in the root project, and delete the patch script.
*/
create(DslContext.projectId, GitVcsRoot({
id("Branch_Release")
name = "https://github.com/JetBrains/ideavim (branch release)"
url = "https://github.com/JetBrains/ideavim.git"
branch = "release"
}))

View File

@ -380,42 +380,6 @@ Contributors:
[![icon][github]](https://github.com/chylex)
&nbsp;
chylex
* [![icon][mail]](mailto:daniel.egger@gmail.com)
[![icon][github]](https://github.com/DanEEStar)
&nbsp;
DanEEStar
* [![icon][mail]](mailto:ksrbkevinsuen@gmail.com)
[![icon][github]](https://github.com/ksrb)
&nbsp;
Kevin Suen
* [![icon][mail]](mailto:michael.schertenleib@inftec.ch)
[![icon][github]](https://github.com/cravay)
&nbsp;
Michael Schertenleib
* [![icon][mail]](mailto:piotr@near.org)
[![icon][github]](https://github.com/pmnoxx)
&nbsp;
Piotr Mikulski
* [![icon][mail]](mailto:lonrevip@gmail.com)
[![icon][github]](https://github.com/lonre)
&nbsp;
Lonre Wang
* [![icon][mail]](mailto:AlexPl292@gmail.com)
[![icon][github]](https://github.com/AlexPl292)
&nbsp;
Alex Pláte
* [![icon][mail]](mailto:david@dadon.fr)
[![icon][github]](https://github.com/ddadon10)
&nbsp;
David Dadon
* [![icon][mail]](mailto:hollandpirates@gmail.com)
[![icon][github]](https://github.com/PHPirates)
&nbsp;
Thomas Schouten
* [![icon][mail]](mailto:sr@mail25.de)
[![icon][github]](https://github.com/Vvalter)
&nbsp;
Simon Rainer
If you are a contributor and your name is not listed here, feel free to
contact the maintainers.

View File

@ -26,70 +26,14 @@ usual beta standards.
## To Be Released
### Features:
* Add `gcu` command for Commentary plugin
* Add `:Commentary` command, which works great for commands such as `:%g/fun/Commentary`
* Support `gc` commentary text objects. E.g. `dgc`: delete commented text.
* Support `redo-register feature` | [VIM-2643](https://youtrack.jetbrains.com/issue/VIM-2643/Dot-operator-doesn-t-increment-number-register-after-pasting-fro) | [viminfo](http://vimdoc.sourceforge.net/htmldoc/undo.html#redo-register)
### Changes:
* Uses the same mappings as Commentary, so custom bindings for the Vim plugin will work with IdeaVim, too.
E.g. `<Plug>Commentary` instead of `<Plug>(CommentMotion)`. Old mappings are maintained for compatibility.
* If you open `~/.ideavimrc` in IDE, remove a mapping, and reload the config using the reload button,
the mapping will actually be unmapped.
### Fixes:
* [VIM-2587](https://youtrack.jetbrains.com/issue/VIM-2587) Use ctrl-6 as ctrl-^
* [VIM-2590](https://youtrack.jetbrains.com/issue/VIM-2590) Fix caret shape in PyCharm
* [VIM-2553](https://youtrack.jetbrains.com/issue/VIM-2553) Substitute consecutive matches
* [VIM-1687](https://youtrack.jetbrains.com/issue/VIM-1687) Support count for `gcc`
* [VIM-2381](https://youtrack.jetbrains.com/issue/VIM-2381) Fall back to line comment if block comment is not available
* [VIM-2589](https://youtrack.jetbrains.com/issue/VIM-2589) Add `gc` text object
* [VIM-2604](https://youtrack.jetbrains.com/issue/VIM-2604) Update action execution rules
* [VIM-2654](https://youtrack.jetbrains.com/issue/VIM-2654) Add support for `return` without expression
* [VIM-2630](https://youtrack.jetbrains.com/issue/VIM-2630/Please-fix-warning-Shall-not-be-called-on-a-template-presentatio) Fix IDE freeze
* [VIM-2661](https://youtrack.jetbrains.com/issue/VIM-2661/Spamming-does-not-work) Fix repeating the `@@` command
* [VIM-2668](https://youtrack.jetbrains.com/issue/VIM-2668/tabm-or-tabm-with-no-number-does-not-match-vim-behavior) Fix omitted numbers in `tabm` command
* [VIM-2595](https://youtrack.jetbrains.com/issue/VIM-2595) Support plugins in macro execution
* [VIM-2671](https://youtrack.jetbrains.com/issue/VIM-2671) Fix using plugins from mappings
* [VIM-2675](https://youtrack.jetbrains.com/issue/VIM-2675) Fix numbering register in visual mode
* [VIM-696](https://youtrack.jetbrains.com/issue/VIM-696/vim-selection-issue-after-undo) Fix selection after undo
* [VIM-744](https://youtrack.jetbrains.com/issue/VIM-744/Use-undoredo-with-count-modifier) Add count to undo/redo
* [VIM-1862](https://youtrack.jetbrains.com/issue/VIM-1862/Ex-commands-executed-in-keymaps-and-macros-are-added-to-the-command-history) Fix command history
### Merged PRs:
* [468](https://github.com/JetBrains/ideavim/pull/468) by [Thomas Schouten](https://github.com/PHPirates): Implement UserDataHolder for EditorDataContext
* [483](https://github.com/JetBrains/ideavim/pull/483) by [Simon Rainer](https://github.com/Vvalter): Fix(VIM-2553): Substitute consecutive matches
* [488](https://github.com/JetBrains/ideavim/pull/488) by [Martin Yzeiri](https://github.com/myzeiri): Add Matchit support for the C family of languages
* [493](https://github.com/JetBrains/ideavim/pull/493) by [Matt Ellis](https://github.com/citizenmatt): Improvements to Commentary extension
* [494](https://github.com/JetBrains/ideavim/pull/494) by [Matt Ellis](https://github.com/citizenmatt): Cleanup pre-212 CaretVisualAttributes compatibility code
* [504](https://github.com/JetBrains/ideavim/pull/504) by [Matt Ellis](https://github.com/citizenmatt): Minor bug fixes
## 1.10.0, 2022-02-17
### Features:
* Add register support to let command | [VIM-749](https://youtrack.jetbrains.com/issue/VIM-749), [VIM-1783](https://youtrack.jetbrains.com/issue/VIM-1783)
* Add tabmove command | [VIM-1164](https://youtrack.jetbrains.com/issue/VIM-1164)
* Add register support to let command | [VIM-749](https://youtrack.jetbrains.com/issue/VIM-749)
* Add register support to let command | [VIM-1783](https://youtrack.jetbrains.com/issue/VIM-1783)
* Add `trackactionids`/`tai` option to track action ids
### Fixes:
* [VIM-2502](https://youtrack.jetbrains.com/issue/VIM-2502) Fix the shape of new carets
* [VIM-2499](https://youtrack.jetbrains.com/issue/VIM-2499) Fix mapping to esc
* [VIM-2500](https://youtrack.jetbrains.com/issue/VIM-2500) Fix esc for normal mode
* [VIM-2523](https://youtrack.jetbrains.com/issue/VIM-2523) `i` command for the folder in the project tree
* [VIM-2471](https://youtrack.jetbrains.com/issue/VIM-2471) Multiple [{ and ]} actions
* [VIM-2504](https://youtrack.jetbrains.com/issue/VIM-2504) Fix esc with using python notebooks
* [VIM-2540](https://youtrack.jetbrains.com/issue/VIM-2540) Fix option listeners
* [VIM-2548](https://youtrack.jetbrains.com/issue/VIM-2548) Fix paste
* [VIM-2470](https://youtrack.jetbrains.com/issue/VIM-2470) Fix incorrect reset of cursor shape
* [VIM-2223](https://youtrack.jetbrains.com/issue/VIM-2223), [VIM-1684](https://youtrack.jetbrains.com/issue/VIM-1684), [VIM-2491](https://youtrack.jetbrains.com/issue/VIM-2491) Fix `gv`
### Merged PRs:
* [441](https://github.com/JetBrains/ideavim/pull/441) by [DanEEStar](https://github.com/DanEEStar): Add Matchit support for Vue.js files
* [440](https://github.com/JetBrains/ideavim/pull/440) by [Kevin Suen](https://github.com/ksrb): Add matchit support for handlebars
* [448](https://github.com/JetBrains/ideavim/pull/448) by [Michael Schertenleib](https://github.com/cravay): Support custom element names in vim-surround
* [435](https://github.com/JetBrains/ideavim/pull/435) by [Piotr Mikulski](https://github.com/pmnoxx): Print stderr when running a command just like vim does
* [449](https://github.com/JetBrains/ideavim/pull/449) by [Lonre Wang](https://github.com/lonre): Typo fix
* [453](https://github.com/JetBrains/ideavim/pull/453) by [Matt Ellis](https://github.com/citizenmatt): fix(VIM-2470): Fix incorrect reset of cursor shape
* [461](https://github.com/JetBrains/ideavim/pull/461) by [David Dadon](https://github.com/ddadon10): Add shortcut to ideajoin example
## 1.9.0, 2021-12-10

View File

@ -4,9 +4,6 @@ IdeaVim is an open source project created by 80+ contributors. Would you like to
This page is created to help you start contributing. And who knows, maybe in a few days this project will be brighter than ever!
:warning: The plugin is currently under a huge refactoring aiming to split into vim-engine and IdeaVim in order to
support the new [Fleet IDE](https://www.jetbrains.com/fleet/).
## Before you begin
- The project is written in Kotlin and Java. Choose whichever language you feel more comfortable with,
@ -74,7 +71,7 @@ If you are looking for:
- Common features:
- State machine. How every particular keystroke is parsed in IdeaVim: `KeyHandler.handleKey()`.
- Options (`incsearch`, `iskeyword`, `relativenumber`): `OptionServiceImpl`.
- Options (`incsearch`, `iskeyword`, `relativenumber`): `OptionsManager`.
- Plugin startup: `PluginStartup`.
- Notifications: `NotificationService`.
- Status bar icon: `StatusBar.kt`.

View File

@ -212,7 +212,6 @@ Ex commands or via `:map` command mappings:
### Executing actions:
* `:action {action_id}`
* Execute an action by `{action_id}`. Works from Ex command line.
* Please don't use `:action` in mappings. Use `<Action>` instead.
* `<Action>({action_id})`
* For the mappings you can use a special `<Action>` keyword. Don't forget the parentheses.
* E.g. `map gh <Action>(ShowErrorDescription)` <- execute hover on `gh`.

View File

@ -11,24 +11,24 @@ buildscript {
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10")
classpath("com.github.AlexPl292:mark-down-to-slack:1.1.2")
classpath("org.eclipse.jgit:org.eclipse.jgit:6.1.0.202203080745-r")
classpath("org.kohsuke:github-api:1.305")
classpath("org.jetbrains:markdown:0.3.1")
classpath("org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r")
classpath("org.kohsuke:github-api:1.301")
classpath("org.jetbrains:markdown:0.2.4")
}
}
plugins {
antlr
java
kotlin("jvm") version "1.6.21"
kotlin("jvm") version "1.5.10"
id("org.jetbrains.intellij") version "1.6.0"
id("org.jetbrains.intellij") version "1.3.0"
id("org.jetbrains.changelog") version "1.3.1"
// ktlint linter - read more: https://github.com/JLLeitschuh/ktlint-gradle
id("org.jlleitschuh.gradle.ktlint") version "10.2.1"
id("org.jlleitschuh.gradle.ktlint") version "10.2.0"
}
// Import variables from gradle.properties file
@ -38,7 +38,6 @@ val ideaVersion: String by project
val downloadIdeaSources: String by project
val instrumentPluginCode: String by project
val remoteRobotVersion: String by project
val antlrVersion: String by project
val publishChannels: String by project
val publishToken: String by project
@ -58,19 +57,11 @@ dependencies {
testImplementation("com.ensarsarajcic.neovim.java:neovim-api:0.2.3")
testImplementation("com.ensarsarajcic.neovim.java:core-rpc:0.2.3")
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-test
testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion")
// https://mvnrepository.com/artifact/org.mockito.kotlin/mockito-kotlin
testImplementation("org.mockito.kotlin:mockito-kotlin:4.0.0")
testImplementation("com.intellij.remoterobot:remote-robot:$remoteRobotVersion")
testImplementation("com.intellij.remoterobot:remote-fixtures:$remoteRobotVersion")
testImplementation("com.automation-remarks:video-recorder-junit:2.0")
runtimeOnly("org.antlr:antlr4-runtime:$antlrVersion")
antlr("org.antlr:antlr4:$antlrVersion")
implementation(project(":vim-engine"))
runtimeOnly("org.antlr:antlr4-runtime:4.9.3")
antlr("org.antlr:antlr4:4.9.3")
}
configurations {
@ -80,22 +71,6 @@ configurations {
}
// --- Compilation
// This can be moved to other test registration when issue with tests in gradle will be fixed
tasks.register<Test>("testWithNeovim") {
group = "verification"
systemProperty("ideavim.nvim.test", "true")
exclude("/ui/**")
}
tasks.register<Test>("testPropertyBased") {
group = "verification"
// include("**/propertybased/**")
}
tasks.register<Test>("testLongRunning") {
group = "verification"
// include("**/longrunning/**")
}
tasks {
// Issue in gradle 7.3
@ -108,32 +83,6 @@ tasks {
exclude("**/ParserTest.class")
}
val testWithNeovim by getting(Test::class) {
isScanForTestClasses = false
// Only run tests from classes that end with "Test"
include("**/*Test.class")
include("**/*test.class")
include("**/*Tests.class")
exclude("**/ParserTest.class")
}
val testPropertyBased by getting(Test::class) {
isScanForTestClasses = false
// Only run tests from classes that end with "Test"
include("**/propertybased/*Test.class")
include("**/propertybased/*test.class")
include("**/propertybased/*Tests.class")
}
val testLongRunning by getting(Test::class) {
isScanForTestClasses = false
// Only run tests from classes that end with "Test"
include("**/longrunning/**/*Test.class")
include("**/longrunning/**/*test.class")
include("**/longrunning/**/*Tests.class")
exclude("**/longrunning/**/ParserTest.class")
}
compileJava {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
@ -144,14 +93,14 @@ tasks {
compileKotlin {
kotlinOptions {
jvmTarget = javaVersion
apiVersion = "1.5"
apiVersion = "1.4"
// allWarningsAsErrors = true
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = javaVersion
apiVersion = "1.5"
apiVersion = "1.4"
// allWarningsAsErrors = true
}
}
@ -169,14 +118,11 @@ gradle.projectsEvaluated {
intellij {
version.set(ideaVersion)
pluginName.set("IdeaVim")
updateSinceUntilBuild.set(false)
downloadSources.set(downloadIdeaSources.toBoolean())
instrumentCode.set(instrumentPluginCode.toBoolean())
intellijRepository.set("https://www.jetbrains.com/intellij-repository")
// Yaml is only used for testing. It's part of the IdeaIC distribution, but needs to be included as a reference
plugins.set(listOf("java", "AceJump:3.8.4", "yaml"))
plugins.set(listOf("java", "AceJump:3.8.4"))
}
tasks {
@ -199,7 +145,6 @@ tasks {
runPluginVerifier {
downloadDir.set("${project.buildDir}/pluginVerifier/ides")
teamCityOutputFormat.set(true)
ideVersions.set(listOf("IC-2021.3.4"))
}
generateGrammarSource {
@ -229,6 +174,22 @@ tasks {
}
}
tasks.register<Test>("testWithNeovim") {
group = "verification"
systemProperty("ideavim.nvim.test", "true")
exclude("/ui/**")
}
tasks.register<Test>("testPropertyBased") {
group = "verification"
include("**/propertybased/**")
}
tasks.register<Test>("testLongRunning") {
group = "verification"
include("**/longrunning/**")
}
tasks.register<Test>("testUi") {
group = "verification"
include("/ui/**")

View File

@ -1,8 +1,6 @@
Some examples of join command with `ideajoin` option enabled.
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.
* Automatic join concatenated lines:
```
@ -57,4 +55,4 @@ sb.append("a"); -> sb.append("a").append("b");
sb.append("b");
```
And other features provided by the plugins.
And other features provided by the plugins.

View File

@ -6,10 +6,9 @@ instrumentPluginCode=true
version=SNAPSHOT
javaVersion=11
remoteRobotVersion=0.11.10
antlrVersion=4.10.1
# Please don't forget to update kotlin version in buildscript section
kotlinVersion=1.6.21
kotlinVersion=1.5.10
publishToken=token
publishChannels=eap

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -1,3 +1,19 @@
rootProject.name = 'IdeaVIM'
include 'vim-engine'
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
rootProject.name = 'IdeaVIM'

View File

@ -28,7 +28,7 @@ comment: (WS | COLON)* QUOTE ~(NEW_LINE)* NEW_LINE;
finishStatement: (WS | COLON)* FINISH WS* (NEW_LINE | BAR);
continueStatement: (WS | COLON)* CONTINUE WS* (NEW_LINE | BAR);
breakStatement: (WS | COLON)* BREAK WS* (NEW_LINE | BAR);
returnStatement: (WS | COLON)* range? (WS | COLON)* RETURN (WS+ expr)? WS* (NEW_LINE | BAR);
returnStatement: (WS | COLON)* range? (WS | COLON)* RETURN WS+ expr WS* (NEW_LINE | BAR);
throwStatement: (WS | COLON)* THROW WS+ expr WS* (NEW_LINE | BAR);
ifStatement: ifBlock
@ -117,7 +117,7 @@ command:
| MARK_COMMAND | JUMPS | J_LOWERCASE | JOIN_LINES | HISTORY | GO_TO_CHAR | SYMBOL | FIND | CLASS | F_LOWERCASE
| FILE | EXIT | E_LOWERCASE | EDIT_FILE | DUMP_LINE | DIGRAPH | DEL_MARKS | D_LOWERCASE | DEL_LINES | DELCMD
| T_LOWERCASE | COPY | CMD_CLEAR | BUFFER_LIST | BUFFER_CLOSE | B_LOWERCASE | BUFFER | ASCII
| ACTIONLIST | ACTION | LOCKVAR | UNLOCKVAR | PACKADD | TABMOVE
| ACTIONLIST | ACTION | LOCKVAR | UNLOCKVAR | PACKADD
)
WS* ((commandArgumentWithoutBars? inline_comment NEW_LINE) | (commandArgumentWithoutBars? NEW_LINE) | (commandArgumentWithoutBars? BAR)) (NEW_LINE | BAR)*
#CommandWithComment|
@ -492,7 +492,6 @@ existingCommands: RETURN
| EXECUTE
| CALL
| NORMAL
| TABMOVE
;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
@ -685,7 +684,6 @@ EXECUTE: 'exe' | 'exec' | 'execu' | 'execut' | 'execute';
LOCKVAR: 'lockv' | 'lockva' | 'lockvar';
UNLOCKVAR: 'unlo' | 'unloc' | 'unlock' | 'unlockv' | 'unlockva' | 'unlockvar';
NORMAL: 'norm' | 'norma' | 'normal';
TABMOVE: 'tabm' | 'tabmo' | 'tabmov' | 'tabmove';
// Types
DIGIT: [0-9];

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -53,7 +53,7 @@ public class EventFacade {
public void setupTypedActionHandler(@NotNull VimTypedActionHandler handler) {
final TypedAction typedAction = getTypedAction();
if (HandlerInjector.notebookCommandMode(null)) {
if (HandlerInjector.notebookCommandMode()) {
TypedActionHandler result = HandlerInjector.inject();
if (result != null) {
myOriginalTypedActionHandler = result;

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -22,7 +22,6 @@ import com.maddyhome.idea.vim.group.KeyGroup;
import com.maddyhome.idea.vim.handler.ActionBeanClass;
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase;
import com.maddyhome.idea.vim.key.MappingOwner;
import com.maddyhome.idea.vim.newapi.IjVimActionsInitiator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -72,7 +71,7 @@ public class RegisterActions {
private static void registerVimCommandActions() {
KeyGroup parser = VimPlugin.getKey();
VIM_ACTIONS_EP.extensions().map(IjVimActionsInitiator::new).forEach(parser::registerCommandAction);
VIM_ACTIONS_EP.extensions().forEach(parser::registerCommandAction);
}
private static void registerEmptyShortcuts() {
@ -81,6 +80,6 @@ public class RegisterActions {
// The {char1} <BS> {char2} shortcut is handled directly by KeyHandler#handleKey, so doesn't have an action. But we
// still need to register the shortcut, to make sure the editor doesn't swallow it.
parser
.registerShortcutWithoutAction(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), MappingOwner.IdeaVim.System.INSTANCE);
.registerShortcutWithoutAction(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), MappingOwner.IdeaVim.INSTANCE);
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,6 +25,7 @@ import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.diagnostic.Logger;
@ -34,10 +35,11 @@ import com.intellij.openapi.keymap.ex.KeymapManagerEx;
import com.intellij.openapi.keymap.impl.DefaultKeymap;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.SystemInfo;
import com.maddyhome.idea.vim.api.VimInjectorKt;
import com.maddyhome.idea.vim.api.VimKeyGroup;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.openapi.wm.WindowManager;
import com.maddyhome.idea.vim.config.VimState;
import com.maddyhome.idea.vim.config.migration.ApplicationConfigurationMigrator;
import com.maddyhome.idea.vim.extension.VimExtensionRegistrar;
@ -47,20 +49,21 @@ import com.maddyhome.idea.vim.group.copy.YankGroup;
import com.maddyhome.idea.vim.group.visual.VisualMotionGroup;
import com.maddyhome.idea.vim.helper.MacKeyRepeat;
import com.maddyhome.idea.vim.listener.VimListenerManager;
import com.maddyhome.idea.vim.newapi.IjVimInjector;
import com.maddyhome.idea.vim.options.OptionService;
import com.maddyhome.idea.vim.option.OptionsManager;
import com.maddyhome.idea.vim.ui.StatusBarIconFactory;
import com.maddyhome.idea.vim.ui.VimEmulationConfigurable;
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel;
import com.maddyhome.idea.vim.vimscript.services.FunctionStorage;
import com.maddyhome.idea.vim.vimscript.services.IjVimOptionService;
import com.maddyhome.idea.vim.vimscript.services.VimVariableService;
import com.maddyhome.idea.vim.vimscript.services.OptionService;
import com.maddyhome.idea.vim.vimscript.services.VariableService;
import com.maddyhome.idea.vim.vimscript.services.VariableServiceImpl;
import org.jdom.Element;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.event.HyperlinkEvent;
import java.awt.*;
import static com.maddyhome.idea.vim.group.EditorGroup.EDITOR_STORE_ELEMENT;
import static com.maddyhome.idea.vim.group.KeyGroup.SHORTCUT_CONFLICTS_ELEMENT;
@ -74,16 +77,18 @@ import static com.maddyhome.idea.vim.vimscript.services.VimRcService.executeIdea
* This is an application level plugin meaning that all open projects will share a common instance of the plugin.
* Registers and marks are shared across open projects so you can copy and paste between files of different projects.
*/
@SuppressWarnings("deprecation")
// [VERSION UPDATE] 212+ getService
@State(name = "VimSettings", storages = {@Storage("$APP_CONFIG$/vim_settings.xml")})
public class VimPlugin implements PersistentStateComponent<Element>, Disposable {
static {
VimInjectorKt.setInjector(new IjVimInjector());
}
private static final String IDEAVIM_PLUGIN_ID = "IdeaVIM";
public static final int STATE_VERSION = 7;
private static long lastBeepTimeMillis;
private boolean error = false;
private String message = null;
private int previousStateVersion = 0;
private String previousKeyMap = "";
@ -126,10 +131,10 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
*/
public static @NotNull NotificationService getNotifications(@Nullable Project project) {
if (project == null) {
return ApplicationManager.getApplication().getService(NotificationService.class);
return ServiceManager.getService(NotificationService.class);
}
else {
return project.getService(NotificationService.class);
return ServiceManager.getService(project, NotificationService.class);
}
}
@ -139,35 +144,35 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
public static @NotNull MotionGroup getMotion() {
return ApplicationManager.getApplication().getService(MotionGroup.class);
}
public static @NotNull XMLGroup getXML() {
return ApplicationManager.getApplication().getService(XMLGroup.class);
return ServiceManager.getService(MotionGroup.class);
}
public static @NotNull ChangeGroup getChange() {
return ((ChangeGroup)VimInjectorKt.getInjector().getChangeGroup());
return ServiceManager.getService(ChangeGroup.class);
}
public static @NotNull CommandGroup getCommand() {
return ApplicationManager.getApplication().getService(CommandGroup.class);
return ServiceManager.getService(CommandGroup.class);
}
public static @NotNull MarkGroup getMark() {
return ((MarkGroup)VimInjectorKt.getInjector().getMarkGroup());
return ServiceManager.getService(MarkGroup.class);
}
public static @NotNull RegisterGroup getRegister() {
return ((RegisterGroup)VimInjectorKt.getInjector().getRegisterGroup());
return ServiceManager.getService(RegisterGroup.class);
}
public static @Nullable RegisterGroup getRegisterIfCreated() {
return ApplicationManager.getApplication().getServiceIfCreated(RegisterGroup.class);
}
public static @NotNull FileGroup getFile() {
return (FileGroup)VimInjectorKt.getInjector().getFile();
return ServiceManager.getService(FileGroup.class);
}
public static @NotNull SearchGroup getSearch() {
return ApplicationManager.getApplication().getService(SearchGroup.class);
return ServiceManager.getService(SearchGroup.class);
}
public static @Nullable SearchGroup getSearchIfCreated() {
@ -175,39 +180,35 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
}
public static @NotNull ProcessGroup getProcess() {
return ((ProcessGroup)VimInjectorKt.getInjector().getProcessGroup());
return ServiceManager.getService(ProcessGroup.class);
}
public static @NotNull MacroGroup getMacro() {
return (MacroGroup)VimInjectorKt.getInjector().getMacro();
return ServiceManager.getService(MacroGroup.class);
}
public static @NotNull DigraphGroup getDigraph() {
return (DigraphGroup)VimInjectorKt.getInjector().getDigraphGroup();
return ServiceManager.getService(DigraphGroup.class);
}
public static @NotNull HistoryGroup getHistory() {
return ApplicationManager.getApplication().getService(HistoryGroup.class);
return ServiceManager.getService(HistoryGroup.class);
}
public static @NotNull KeyGroup getKey() {
return ((KeyGroup)VimInjectorKt.getInjector().getKeyGroup());
return ServiceManager.getService(KeyGroup.class);
}
public static @Nullable KeyGroup getKeyIfCreated() {
return ((KeyGroup)ApplicationManager.getApplication().getServiceIfCreated(VimKeyGroup.class));
return ApplicationManager.getApplication().getServiceIfCreated(KeyGroup.class);
}
public static @NotNull WindowGroup getWindow() {
return ((WindowGroup)VimInjectorKt.getInjector().getWindow());
}
public static @NotNull TabService getTabService() {
return ApplicationManager.getApplication().getService(TabService.class);
return ServiceManager.getService(WindowGroup.class);
}
public static @NotNull EditorGroup getEditor() {
return ApplicationManager.getApplication().getService(EditorGroup.class);
return ServiceManager.getService(EditorGroup.class);
}
public static @Nullable EditorGroup getEditorIfCreated() {
@ -215,27 +216,23 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
}
public static @NotNull VisualMotionGroup getVisualMotion() {
return (VisualMotionGroup)VimInjectorKt.getInjector().getVisualMotionGroup();
return ServiceManager.getService(VisualMotionGroup.class);
}
public static @NotNull YankGroup getYank() {
return (YankGroup)VimInjectorKt.getInjector().getYank();
return ServiceManager.getService(YankGroup.class);
}
public static @NotNull PutGroup getPut() {
return (PutGroup)VimInjectorKt.getInjector().getPut();
return ServiceManager.getService(PutGroup.class);
}
public static @NotNull VimVariableService getVariableService() {
return ApplicationManager.getApplication().getService(VimVariableService.class);
public static @NotNull VariableService getVariableService() {
return ServiceManager.getService(VariableService.class);
}
public static @NotNull OptionService getOptionService() {
return VimInjectorKt.getInjector().getOptionService();
}
public static @NotNull IjVimOptionService getOptionServiceImpl() {
return (IjVimOptionService)VimInjectorKt.getInjector().getOptionService();
return ServiceManager.getService(OptionService.class);
}
private static @NotNull NotificationService getNotifications() {
@ -288,79 +285,85 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
}
public static boolean isError() {
return VimInjectorKt.getInjector().getMessages().isError();
return getInstance().error;
}
public static String getMessage() {
return VimInjectorKt.getInjector().getMessages().getStatusBarMessage();
return getInstance().message;
}
/**
* Indicate to the user that an error has occurred. Just beep.
*/
public static void indicateError() {
VimInjectorKt.getInjector().getMessages().indicateError();
if (ApplicationManager.getApplication().isUnitTestMode()) {
getInstance().error = true;
}
else if (!VimPlugin.getOptionService().isSet(OptionService.Scope.GLOBAL.INSTANCE, "visualbell", "visualbell")) {
// Vim only allows a beep once every half second - :help 'visualbell'
final long currentTimeMillis = System.currentTimeMillis();
if (currentTimeMillis - lastBeepTimeMillis > 500) {
Toolkit.getDefaultToolkit().beep();
lastBeepTimeMillis = currentTimeMillis;
}
}
}
public static void clearError() {
VimInjectorKt.getInjector().getMessages().clearError();
if (ApplicationManager.getApplication().isUnitTestMode()) {
getInstance().error = false;
}
}
public static void showMode(String msg) {
VimInjectorKt.getInjector().getMessages().showMode(msg);
showMessage(msg);
}
public static void showMessage(@Nls(capitalization = Nls.Capitalization.Sentence) @Nullable String msg) {
VimInjectorKt.getInjector().getMessages().showStatusBarMessage(msg);
if (ApplicationManager.getApplication().isUnitTestMode()) {
getInstance().message = msg;
}
ProjectManager pm = ProjectManager.getInstance();
Project[] projects = pm.getOpenProjects();
for (Project project : projects) {
StatusBar bar = WindowManager.getInstance().getStatusBar(project);
if (bar != null) {
if (msg == null || msg.length() == 0) {
bar.setInfo("");
}
else {
bar.setInfo("VIM - " + msg);
}
}
}
}
public static @NotNull VimPlugin getInstance() {
return ApplicationManager.getApplication().getService(VimPlugin.class);
return ServiceManager.getService(VimPlugin.class);
}
/**
* IdeaVim plugin initialization.
* This is an important operation and some commands ordering should be preserved.
* Please make sure that the documentation of this function is in sync with the code
*
* 1) Update state
* This schedules a state update. In most cases it just shows some dialogs to the user. As I know, there are
* no special reasons to keep this command as a first line, so it seems safe to move it.
* 2) Command registration
* This block should be located BEFORE ~/.ideavimrc execution. Without it the commands won't be registered
* and initialized, but ~/.ideavimrc file may refer or execute some commands or functions.
* This block DOES NOT initialize extensions, but only registers the available ones.
* 3) ~/.ideavimrc execution
* 3.1 executes commands from the .ideavimrc file and 3.2 initializes extensions.
* 3.1 MUST BE BEFORE 3.2. This is a flow of vim/IdeaVim initialization, firstly .ideavimrc is executed and then
* the extensions are initialized.
* 4) Components initialization
* This should happen after ideavimrc execution because VimListenerManager accesses `number` option
* to init line numbers and guicaret to initialize carets.
* However, there is a question about listeners attaching. Listeners registration happens after the .ideavimrc
* execution, what theoretically may cause bugs (e.g. VIM-2540)
*/
private void turnOnPlugin() {
// 1) Update state
ApplicationManager.getApplication().invokeLater(this::updateState);
// 2) Command registration
// 2.1) Register vim actions in command mode
// Register vim actions in command mode
RegisterActions.registerActions();
// 2.2) Register extensions
// Register extensions
VimExtensionRegistrar.registerExtensions();
// 2.3) Register functions
// Register functions
FunctionStorage.INSTANCE.registerHandlers();
// 3) ~/.ideavimrc execution
// 3.1) Execute ~/.ideavimrc
// Execute ~/.ideavimrc
registerIdeavimrc();
// 3.2) Initialize extensions. Always after 3.1
// Initialize extensions
VimExtensionRegistrar.enableDelayedExtensions();
// Some options' default values are based on values set in .ideavimrc, e.g. 'shellxquote' on Windows when 'shell'
// is cmd.exe has a different default to when 'shell' contains "sh"
OptionsManager.INSTANCE.completeInitialisation();
// Turing on should be performed after all commands registration
getSearch().turnOn();
VimListenerManager.INSTANCE.turnOn();

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,12 +25,8 @@ import com.intellij.openapi.editor.actionSystem.TypedActionHandler
import com.intellij.openapi.editor.actionSystem.TypedActionHandlerEx
import com.intellij.openapi.progress.ProcessCanceledException
import com.maddyhome.idea.vim.helper.EditorDataContext
import com.maddyhome.idea.vim.helper.inInsertMode
import com.maddyhome.idea.vim.helper.isIdeaVimDisabledHere
import com.maddyhome.idea.vim.key.KeyHandlerKeeper
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.options.OptionConstants
import com.maddyhome.idea.vim.options.OptionScope
import com.maddyhome.idea.vim.vimscript.services.OptionService
import java.awt.event.KeyAdapter
import java.awt.event.KeyEvent
import javax.swing.KeyStroke
@ -40,43 +36,33 @@ import javax.swing.KeyStroke
*
* IDE shortcut keys used by Vim commands are handled by [com.maddyhome.idea.vim.action.VimShortcutKeyAction].
*/
class VimTypedActionHandler(origHandler: TypedActionHandler) : TypedActionHandlerEx {
class VimTypedActionHandler(origHandler: TypedActionHandler?) : TypedActionHandlerEx {
private val handler = KeyHandler.getInstance()
private val traceTime = VimPlugin.getOptionService().isSet(OptionScope.GLOBAL, OptionConstants.ideatracetimeName)
private val traceTime = VimPlugin.getOptionService().isSet(OptionService.Scope.GLOBAL, "ideatracetime")
init {
KeyHandlerKeeper.getInstance().originalHandler = origHandler
handler.originalHandler = origHandler
}
override fun beforeExecute(editor: Editor, charTyped: Char, context: DataContext, plan: ActionPlan) {
LOG.trace("Before execute for typed action")
if (editor.isIdeaVimDisabledHere) {
LOG.trace("IdeaVim disabled here, finish")
(KeyHandlerKeeper.getInstance().originalHandler as? TypedActionHandlerEx)?.beforeExecute(editor, charTyped, context, plan)
(handler.originalHandler as? TypedActionHandlerEx)?.beforeExecute(editor, charTyped, context, plan)
return
}
LOG.trace("Executing before execute")
val modifiers = if (charTyped == ' ' && VimKeyListener.isSpaceShift) KeyEvent.SHIFT_DOWN_MASK else 0
val keyStroke = KeyStroke.getKeyStroke(charTyped, modifiers)
/* Invoked before acquiring a write lock and actually handling the keystroke.
*
* Drafts an optional [ActionPlan] that will be used as a base for zero-latency rendering in editor.
*/
if (editor.inInsertMode) {
val originalHandler = KeyHandlerKeeper.getInstance().originalHandler
if (originalHandler is TypedActionHandlerEx) {
originalHandler.beforeExecute(editor, keyStroke.keyChar, context, plan)
}
}
handler.beforeHandleKey(editor, keyStroke, context, plan)
}
override fun execute(editor: Editor, charTyped: Char, context: DataContext) {
LOG.trace("Execute for typed action")
if (editor.isIdeaVimDisabledHere) {
LOG.trace("IdeaVim disabled here, finish")
KeyHandlerKeeper.getInstance().originalHandler.execute(editor, charTyped, context)
handler.originalHandler.execute(editor, charTyped, context)
return
}
@ -85,7 +71,7 @@ class VimTypedActionHandler(origHandler: TypedActionHandler) : TypedActionHandle
val modifiers = if (charTyped == ' ' && VimKeyListener.isSpaceShift) KeyEvent.SHIFT_DOWN_MASK else 0
val keyStroke = KeyStroke.getKeyStroke(charTyped, modifiers)
val startTime = if (traceTime) System.currentTimeMillis() else null
handler.handleKey(editor.vim, keyStroke, EditorDataContext.init(editor, context).vim)
handler.handleKey(editor, keyStroke, EditorDataContext.init(editor, context))
if (startTime != null) {
val duration = System.currentTimeMillis() - startTime
LOG.info("VimTypedAction '$charTyped': $duration ms")

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.maddyhome.idea.vim.command
package com.maddyhome.idea.vim.action
/**
* There are some double-character commands like `cc`, `dd`, `yy`.

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,9 +17,9 @@
*/
package com.maddyhome.idea.vim.action
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.VimActionHandler
@ -27,7 +27,7 @@ import com.maddyhome.idea.vim.handler.VimActionHandler
class ExEntryAction : VimActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.OTHER_READONLY
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
VimPlugin.getProcess().startExCommand(editor, context, cmd)
return true
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,32 +17,30 @@
*/
package com.maddyhome.idea.vim.action
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.KeyHandler
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.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.group.MotionGroup
import com.maddyhome.idea.vim.handler.VimActionHandler
import com.maddyhome.idea.vim.helper.getTopLevelEditor
import com.maddyhome.idea.vim.helper.mode
import com.maddyhome.idea.vim.helper.vimForEachCaret
class ResetModeAction : VimActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.OTHER_WRITABLE
override fun execute(
editor: VimEditor,
context: ExecutionContext,
cmd: Command,
operatorArguments: OperatorArguments,
): Boolean {
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
val modeBeforeReset = editor.mode
KeyHandler.getInstance().fullReset(editor)
KeyHandler.getInstance().fullReset(editor.getTopLevelEditor())
if (modeBeforeReset == CommandState.Mode.INSERT) {
editor.forEachCaret { caret ->
val position = injector.motion.getOffsetOfHorizontalMotion(editor, caret, -1, false)
caret.moveToOffset(position)
editor.vimForEachCaret { caret ->
val position = VimPlugin.getMotion().getOffsetOfHorizontalMotion(editor, caret, -1, false)
MotionGroup.moveCaret(editor, caret, position)
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -34,10 +34,10 @@ import com.intellij.openapi.util.Key
import com.intellij.ui.KeyStrokeAdapter
import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.helper.EditorDataContext
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.HandlerInjector
import com.maddyhome.idea.vim.helper.StringHelper
import com.maddyhome.idea.vim.helper.inInsertMode
import com.maddyhome.idea.vim.helper.inNormalMode
import com.maddyhome.idea.vim.helper.isIdeaVimDisabledHere
@ -48,14 +48,10 @@ import com.maddyhome.idea.vim.key.ShortcutOwner
import com.maddyhome.idea.vim.key.ShortcutOwnerInfo
import com.maddyhome.idea.vim.listener.AceJumpService
import com.maddyhome.idea.vim.listener.AppCodeTemplates.appCodeTemplateCaptured
import com.maddyhome.idea.vim.newapi.IjVimEditor
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.options.OptionChangeListener
import com.maddyhome.idea.vim.options.OptionConstants
import com.maddyhome.idea.vim.options.OptionScope
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString
import com.maddyhome.idea.vim.vimscript.services.IjVimOptionService
import com.maddyhome.idea.vim.vimscript.model.options.OptionChangeListener
import com.maddyhome.idea.vim.vimscript.services.OptionService
import java.awt.event.InputEvent
import java.awt.event.KeyEvent
import javax.swing.KeyStroke
@ -67,7 +63,7 @@ import javax.swing.KeyStroke
* These keys are not passed to [com.maddyhome.idea.vim.VimTypedActionHandler] and should be handled by actions.
*/
class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible*/ {
private val traceTime = VimPlugin.getOptionService().isSet(OptionScope.GLOBAL, OptionConstants.ideatracetimeName)
private val traceTime = VimPlugin.getOptionService().isSet(OptionService.Scope.GLOBAL, "ideatracetime")
override fun actionPerformed(e: AnActionEvent) {
LOG.trace("Executing shortcut key action")
@ -81,7 +77,7 @@ class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible*/ {
// Should we use HelperKt.getTopLevelEditor(editor) here, as we did in former EditorKeyHandler?
try {
val start = if (traceTime) System.currentTimeMillis() else null
KeyHandler.getInstance().handleKey(editor.vim, keyStroke, EditorDataContext.init(editor, e.dataContext).vim)
KeyHandler.getInstance().handleKey(editor, keyStroke, EditorDataContext.init(editor, e.dataContext))
if (start != null) {
val duration = System.currentTimeMillis() - start
LOG.info("VimShortcut update '$keyStroke': $duration ms")
@ -125,8 +121,8 @@ class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible*/ {
val keyCode = keyStroke.keyCode
if (HandlerInjector.notebookCommandMode(editor)) {
LOG.debug("Python Notebook command mode")
if (HandlerInjector.notebookCommandMode()) {
LOG.trace("Python Notebook command mode")
if (keyCode == KeyEvent.VK_RIGHT || keyCode == KeyEvent.VK_KP_RIGHT || keyCode == KeyEvent.VK_ENTER) {
invokeLater { editor.updateCaretsVisualAttributes() }
}
@ -174,7 +170,19 @@ class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible*/ {
val savedShortcutConflicts = VimPlugin.getKey().savedShortcutConflicts
val info = savedShortcutConflicts[keyStroke]
return when (info?.forEditor(editor.vim)) {
if (info is ShortcutOwner) {
return when (info) {
ShortcutOwner.VIM -> true
ShortcutOwner.IDE -> !isShortcutConflict(keyStroke)
else -> {
if (isShortcutConflict(keyStroke)) {
savedShortcutConflicts[keyStroke] = ShortcutOwnerInfo.allUndefined
}
true
}
}
}
return when ((info as? ShortcutOwnerInfo)?.forEditor(editor)) {
ShortcutOwner.VIM -> true
ShortcutOwner.IDE -> !isShortcutConflict(keyStroke)
else -> {
@ -189,10 +197,10 @@ class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible*/ {
}
private fun isEnabledForEscape(editor: Editor): Boolean {
val ideaVimSupportValue = (VimPlugin.getOptionService().getOptionValue(OptionScope.LOCAL(IjVimEditor(editor)), IjVimOptionService.ideavimsupportName) as VimString).value
val ideaVimSupportValue = (VimPlugin.getOptionService().getOptionValue(OptionService.Scope.LOCAL(editor), "ideavimsupport") as VimString).value
return editor.isPrimaryEditor() ||
EditorHelper.isFileEditor(editor) && !editor.inNormalMode ||
ideaVimSupportValue.contains(IjVimOptionService.ideavimsupport_dialog) && !editor.inNormalMode
ideaVimSupportValue.contains("dialog") && !editor.inNormalMode
}
private fun isShortcutConflict(keyStroke: KeyStroke): Boolean {
@ -238,7 +246,7 @@ class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible*/ {
init {
VimPlugin.getOptionService().addListener(
OptionConstants.lookupkeysName,
"lookupkeys",
object : OptionChangeListener<VimDataType> {
override fun processGlobalValueChange(oldValue: VimDataType?) {
parsedLookupKeys = parseLookupKeys()
@ -249,9 +257,9 @@ class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible*/ {
fun isEnabledForLookup(keyStroke: KeyStroke): Boolean = keyStroke !in parsedLookupKeys
private fun parseLookupKeys() = (VimPlugin.getOptionService().getOptionValue(OptionScope.GLOBAL, OptionConstants.lookupkeysName) as VimString).value
private fun parseLookupKeys() = (VimPlugin.getOptionService().getOptionValue(OptionService.Scope.GLOBAL, "lookupkeys") as VimString).value
.split(",")
.map { injector.parser.parseKeys(it) }
.map { StringHelper.parseKeys(it) }
.filter { it.isNotEmpty() }
.map { it.first() }
.toSet()

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,108 +17,57 @@
*/
package com.maddyhome.idea.vim.action.change
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
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.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
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.command.SelectionType
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.common.argumentCaptured
import com.maddyhome.idea.vim.group.MotionGroup
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.commandState
import com.maddyhome.idea.vim.helper.enumSetOf
import com.maddyhome.idea.vim.newapi.ij
import java.util.*
private fun doOperatorAction(editor: VimEditor, context: ExecutionContext, textRange: TextRange, selectionType: SelectionType): Boolean {
val operatorFunction = VimPlugin.getKey().operatorFunction
if (operatorFunction == null) {
VimPlugin.showMessage(MessageHelper.message("E774"))
return false
}
val saveRepeatHandler = VimRepeater.repeatHandler
VimPlugin.getMark().setChangeMarks(editor, textRange)
KeyHandler.getInstance().reset(editor)
val result = operatorFunction.apply(editor.ij, context.ij, selectionType)
VimRepeater.repeatHandler = saveRepeatHandler
return result
}
/**
* @author vlan
*/
class OperatorAction : VimActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
override val argumentType: Argument.Type = Argument.Type.MOTION
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
val argument = cmd.argument ?: return false
if (!editor.commandState.isDotRepeatInProgress) {
argumentCaptured = argument
}
val range = getMotionRange(editor, context, argument, operatorArguments)
if (range != null) {
val selectionType = if (argument.motion.isLinewiseMotion()) {
SelectionType.LINE_WISE
} else {
SelectionType.CHARACTER_WISE
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
val operatorFunction = VimPlugin.getKey().operatorFunction
if (operatorFunction != null) {
val argument = cmd.argument
if (argument != null) {
if (!editor.commandState.isDotRepeatInProgress) {
VimRepeater.Extension.argumentCaptured = argument
}
val saveRepeatHandler = VimRepeater.repeatHandler
val motion = argument.motion
val range = MotionGroup
.getMotionRange(
editor,
editor.caretModel.primaryCaret,
context,
argument,
operatorArguments
)
if (range != null) {
VimPlugin.getMark().setChangeMarks(editor, range)
val selectionType = if (motion.isLinewiseMotion()) SelectionType.LINE_WISE else SelectionType.CHARACTER_WISE
KeyHandler.getInstance().reset(editor)
val result = operatorFunction.apply(editor, context, selectionType)
VimRepeater.repeatHandler = saveRepeatHandler
return result
}
}
return doOperatorAction(editor, context, range, selectionType)
return false
}
VimPlugin.showMessage(MessageHelper.message("E774"))
return false
}
private fun getMotionRange(
editor: VimEditor,
context: ExecutionContext,
argument: Argument,
operatorArguments: OperatorArguments
): TextRange? {
// Note that we're using getMotionRange2 in order to avoid normalising the linewise range into line start
// offsets that will be used to set the change marks. This affects things like the location of the caret in the
// Commentary extension
val ijEditor = editor.ij
return MotionGroup.getMotionRange2(
ijEditor,
ijEditor.caretModel.primaryCaret,
context.ij,
argument,
operatorArguments
)?.normalize()?.let {
// If we're linewise, make sure the end offset isn't just the EOL char
if (argument.motion.isLinewiseMotion() && it.endOffset < editor.fileSize()) {
TextRange(it.startOffset, it.endOffset + 1)
} else {
it
}
}
}
}
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,
context: ExecutionContext,
cmd: Command,
range: VimSelection,
operatorArguments: OperatorArguments,
): Boolean {
return doOperatorAction(editor, context, range.toVimTextRange(), range.type)
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,27 +17,15 @@
*/
package com.maddyhome.idea.vim.action.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.VimActionHandler
import com.maddyhome.idea.vim.helper.UndoRedoHelper.redo
class RedoAction : VimActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
override fun execute(
editor: VimEditor,
context: ExecutionContext,
cmd: Command,
operatorArguments: OperatorArguments,
): Boolean {
var count = operatorArguments.count1
var result = injector.undo.redo(context)
while ((--count > 0) && result) {
result = injector.undo.redo(context)
}
return result
}
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean = redo(context)
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,49 +17,44 @@
*/
package com.maddyhome.idea.vim.action.change
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.command.CommandProcessor
import com.intellij.openapi.editor.Editor
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.injector
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.extension.VimExtensionHandler
import com.maddyhome.idea.vim.handler.VimActionHandler
import com.maddyhome.idea.vim.helper.commandState
import com.maddyhome.idea.vim.newapi.ij
import javax.swing.KeyStroke
class RepeatChangeAction : VimActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.OTHER_WRITABLE
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
val state = editor.commandState
val lastCommand = VimRepeater.lastChangeCommand
if (lastCommand == null && Extension.lastExtensionHandler == null) return false
if (lastCommand == null && VimRepeater.Extension.lastExtensionHandler == null) return false
// Save state
val save = state.executingCommand
val lastFTCmd = injector.motion.lastFTCmd
val lastFTChar = injector.motion.lastFTChar
val reg = injector.registerGroup.currentRegister
val lastHandler = Extension.lastExtensionHandler
val lastFTCmd = VimPlugin.getMotion().lastFTCmd
val lastFTChar = VimPlugin.getMotion().lastFTChar
val reg = VimPlugin.getRegister().currentRegister
val lastHandler = VimRepeater.Extension.lastExtensionHandler
val repeatHandler = VimRepeater.repeatHandler
state.isDotRepeatInProgress = true
// A fancy 'redo-register' feature
// VIM-2643, :h redo-register
if (VimRepeater.lastChangeRegister in '1'..'8') {
VimRepeater.lastChangeRegister = VimRepeater.lastChangeRegister.inc()
}
injector.registerGroup.selectRegister(VimRepeater.lastChangeRegister)
VimPlugin.getRegister().selectRegister(VimRepeater.lastChangeRegister)
try {
if (repeatHandler && lastHandler != null) {
val processor = CommandProcessor.getInstance()
processor.executeCommand(
editor.ij.project,
editor.project,
{ lastHandler.execute(editor, context) },
"Vim " + lastHandler.javaClass.simpleName,
null
@ -76,7 +71,7 @@ class RepeatChangeAction : VimActionHandler.SingleExecution() {
state.setExecutingCommand(lastCommand)
val arguments = operatorArguments.copy(count0 = lastCommand.rawCount)
injector.actionExecutor.executeVimAction(editor, lastCommand.action, context, arguments)
KeyHandler.executeVimAction(editor, lastCommand.action, context, arguments)
VimRepeater.saveLastChange(lastCommand)
}
@ -88,10 +83,66 @@ class RepeatChangeAction : VimActionHandler.SingleExecution() {
// Restore state
if (save != null) state.setExecutingCommand(save)
VimPlugin.getMotion().setLastFTCmd(lastFTCmd, lastFTChar)
if (lastHandler != null) Extension.lastExtensionHandler = lastHandler
if (lastHandler != null) VimRepeater.Extension.lastExtensionHandler = lastHandler
VimRepeater.repeatHandler = repeatHandler
Extension.reset()
VimRepeater.Extension.reset()
VimPlugin.getRegister().selectRegister(reg)
return true
}
}
object VimRepeater {
var repeatHandler = false
var lastChangeCommand: Command? = null
private set
var lastChangeRegister = VimPlugin.getRegister().defaultRegister
private set
fun saveLastChange(command: Command) {
lastChangeCommand = command
lastChangeRegister = VimPlugin.getRegister().currentRegister
}
object Extension {
var lastExtensionHandler: VimExtensionHandler? = null
var argumentCaptured: Argument? = null
private val keyStrokes = mutableListOf<KeyStroke>()
private val strings = mutableListOf<String>()
private var keystrokePointer = 0
private var stringPointer = 0
fun addKeystroke(key: KeyStroke) = keyStrokes.add(key)
fun addString(key: String) = strings.add(key)
fun consumeKeystroke(): KeyStroke? {
if (keystrokePointer in keyStrokes.indices) {
keystrokePointer += 1
return keyStrokes[keystrokePointer - 1]
}
return null
}
fun consumeString(): String? {
if (stringPointer in strings.indices) {
stringPointer += 1
return strings[stringPointer - 1]
}
return null
}
fun reset() {
keystrokePointer = 0
stringPointer = 0
}
fun clean() {
keyStrokes.clear()
strings.clear()
keystrokePointer = 0
stringPointer = 0
}
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,35 +17,24 @@
*/
package com.maddyhome.idea.vim.action.change
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
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
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.VimActionHandler
import com.maddyhome.idea.vim.helper.StringHelper
import com.maddyhome.idea.vim.helper.UndoRedoHelper.undo
import java.awt.event.KeyEvent
import javax.swing.KeyStroke
class UndoAction : VimActionHandler.SingleExecution(), ComplicatedKeysAction {
override val keyStrokesSet: Set<List<KeyStroke>> = setOf(
injector.parser.parseKeys("u"),
StringHelper.parseKeys("u"),
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_UNDO, 0))
)
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
override fun execute(
editor: VimEditor,
context: ExecutionContext,
cmd: Command,
operatorArguments: OperatorArguments,
): Boolean {
var count = operatorArguments.count1
var result = injector.undo.undo(context)
while ((--count > 0) && result) {
result = injector.undo.undo(context)
}
return result
}
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean = undo(context)
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.OperatorArguments
@ -38,14 +38,14 @@ class AutoIndentLinesVisualAction : VisualOperatorActionHandler.ForEachCaret() {
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_EXIT_VISUAL)
override fun executeAction(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
cmd: Command,
range: VimSelection,
operatorArguments: OperatorArguments,
): Boolean {
injector.changeGroup.autoIndentRange(editor, caret, context, range.toVimTextRange(true))
VimPlugin.getChange().autoIndentRange(editor, caret, context, range.toVimTextRange(true))
return true
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,13 +17,13 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.action.DuplicableOperatorAction
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.DuplicableOperatorAction
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
import com.maddyhome.idea.vim.helper.CharacterHelper
@ -36,14 +36,14 @@ class ChangeCaseLowerMotionAction : ChangeEditorActionHandler.ForEachCaret(), Du
override val duplicateWith: Char = 'u'
override fun execute(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
return argument != null &&
injector.changeGroup
VimPlugin.getChange()
.changeCaseMotion(
editor,
caret,

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.OperatorArguments
@ -28,6 +28,7 @@ import com.maddyhome.idea.vim.group.visual.VimSelection
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler
import com.maddyhome.idea.vim.helper.CharacterHelper
import com.maddyhome.idea.vim.helper.enumSetOf
import com.maddyhome.idea.vim.helper.getTopLevelEditor
import java.util.*
/**
@ -39,14 +40,15 @@ class ChangeCaseLowerVisualAction : VisualOperatorActionHandler.ForEachCaret() {
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_EXIT_VISUAL)
override fun executeAction(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
cmd: Command,
range: VimSelection,
operatorArguments: OperatorArguments,
): Boolean {
return injector.changeGroup
.changeCaseRange(editor, caret, range.toVimTextRange(false), CharacterHelper.CASE_LOWER)
val topLevelEditor = editor.getTopLevelEditor()
return VimPlugin.getChange()
.changeCaseRange(topLevelEditor, caret, range.toVimTextRange(false), CharacterHelper.CASE_LOWER)
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
@ -30,12 +30,12 @@ class ChangeCaseToggleCharacterAction : ChangeEditorActionHandler.ForEachCaret()
override val type: Command.Type = Command.Type.CHANGE
override fun execute(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
return injector.changeGroup.changeCaseToggleCharacter(editor, caret, operatorArguments.count1)
return VimPlugin.getChange().changeCaseToggleCharacter(editor, caret, operatorArguments.count1)
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,13 +17,13 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.action.DuplicableOperatorAction
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.DuplicableOperatorAction
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
import com.maddyhome.idea.vim.helper.CharacterHelper
@ -36,14 +36,14 @@ class ChangeCaseToggleMotionAction : ChangeEditorActionHandler.ForEachCaret(), D
override val duplicateWith: Char = '~'
override fun execute(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
return argument != null &&
injector.changeGroup
VimPlugin.getChange()
.changeCaseMotion(
editor,
caret,

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.OperatorArguments
@ -39,14 +39,14 @@ class ChangeCaseToggleVisualAction : VisualOperatorActionHandler.ForEachCaret()
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_EXIT_VISUAL)
override fun executeAction(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
cmd: Command,
range: VimSelection,
operatorArguments: OperatorArguments,
): Boolean {
return injector.changeGroup
return VimPlugin.getChange()
.changeCaseRange(editor, caret, range.toVimTextRange(false), CharacterHelper.CASE_TOGGLE)
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,13 +17,13 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.action.DuplicableOperatorAction
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.DuplicableOperatorAction
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
import com.maddyhome.idea.vim.helper.CharacterHelper
@ -36,14 +36,14 @@ class ChangeCaseUpperMotionAction : ChangeEditorActionHandler.ForEachCaret(), Du
override val duplicateWith: Char = 'U'
override fun execute(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
return argument != null &&
injector.changeGroup
VimPlugin.getChange()
.changeCaseMotion(
editor,
caret,

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.OperatorArguments
@ -39,14 +39,14 @@ class ChangeCaseUpperVisualAction : VisualOperatorActionHandler.ForEachCaret() {
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_EXIT_VISUAL)
override fun executeAction(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
cmd: Command,
range: VimSelection,
operatorArguments: OperatorArguments,
): Boolean {
return injector.changeGroup
return VimPlugin.getChange()
.changeCaseRange(editor, caret, range.toVimTextRange(false), CharacterHelper.CASE_UPPER)
}
}

View File

@ -0,0 +1,48 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.maddyhome.idea.vim.action.change.change
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.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.handler.ChangeEditorActionHandler
import com.maddyhome.idea.vim.helper.enumSetOf
import java.util.*
class ChangeCharacterAction : ChangeEditorActionHandler.ForEachCaret() {
override val type: Command.Type = Command.Type.CHANGE
override val argumentType: Argument.Type = Argument.Type.DIGRAPH
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_ALLOW_DIGRAPH)
override fun execute(
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
return argument != null && VimPlugin.getChange().changeCharacter(editor, caret, operatorArguments.count1, argument.character)
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
@ -37,12 +37,12 @@ class ChangeCharactersAction : ChangeEditorActionHandler.ForEachCaret() {
override val flags: EnumSet<CommandFlags> = enumSetOf(FLAG_NO_REPEAT_INSERT, FLAG_MULTIKEY_UNDO)
override fun execute(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
return injector.changeGroup.changeCharacters(editor, caret, operatorArguments.count1)
return VimPlugin.getChange().changeCharacters(editor, caret, operatorArguments.count1)
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
@ -37,12 +37,12 @@ class ChangeEndOfLineAction : ChangeEditorActionHandler.ForEachCaret() {
override val flags: EnumSet<CommandFlags> = enumSetOf(FLAG_NO_REPEAT_INSERT, FLAG_MULTIKEY_UNDO)
override fun execute(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
return injector.changeGroup.changeEndOfLine(editor, caret, operatorArguments.count1)
return VimPlugin.getChange().changeEndOfLine(editor, caret, operatorArguments.count1)
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,27 +17,28 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.ex.ranges.LineRange
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.vimscript.model.Script
class ChangeLastGlobalSearchReplaceAction : ChangeEditorActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
override fun execute(
editor: VimEditor,
context: ExecutionContext,
editor: Editor,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
val range = LineRange(0, editor.lineCount() - 1)
return injector.searchGroup
.processSubstituteCommand(editor, editor.primaryCaret(), range, "s", "//~/&", Script(listOf()))
val range = LineRange(0, EditorHelper.getLineCount(editor) - 1)
return VimPlugin.getSearch()
.processSubstituteCommand(editor, editor.caretModel.primaryCaret, range, "s", "//~/&", Script(listOf()))
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,9 +17,9 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
@ -31,17 +31,15 @@ class ChangeLastSearchReplaceAction : ChangeEditorActionHandler.SingleExecution(
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
override fun execute(
editor: VimEditor,
context: ExecutionContext,
editor: Editor,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
var result = true
for (caret in editor.carets()) {
val line = caret.getLogicalPosition().line
if (!injector.searchGroup
.processSubstituteCommand(editor, caret, LineRange(line, line), "s", "//~/", Script(listOf()))
) {
for (caret in editor.caretModel.allCarets) {
val line = caret.logicalPosition.line
if (!VimPlugin.getSearch().processSubstituteCommand(editor, caret, LineRange(line, line), "s", "//~/", Script(listOf()))) {
result = false
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,11 +17,11 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.action.motion.updown.MotionDownLess1FirstNonSpaceAction
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
@ -38,16 +38,16 @@ class ChangeLineAction : ChangeEditorActionHandler.ForEachCaret() {
override val flags: EnumSet<CommandFlags> = enumSetOf(FLAG_NO_REPEAT_INSERT, FLAG_MULTIKEY_UNDO)
override fun execute(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
// `S` command is a synonym of `cc`
val motion = MotionDownLess1FirstNonSpaceAction()
val command = Command(1, motion, motion.type, motion.flags)
return injector.changeGroup.changeMotion(
return VimPlugin.getChange().changeMotion(
editor,
caret,
context,

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,13 +17,13 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.action.DuplicableOperatorAction
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.DuplicableOperatorAction
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
@ -35,13 +35,13 @@ class ChangeMotionAction : ChangeEditorActionHandler.ForEachCaret(), DuplicableO
override val duplicateWith: Char = 'c'
override fun execute(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
return argument != null && injector.changeGroup.changeMotion(
return argument != null && VimPlugin.getChange().changeMotion(
editor,
caret,
context,

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,13 +17,12 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
import com.maddyhome.idea.vim.helper.enumSetOf
@ -35,21 +34,12 @@ class ChangeReplaceAction : ChangeEditorActionHandler.SingleExecution() {
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MULTIKEY_UNDO)
override fun execute(
editor: VimEditor,
context: ExecutionContext,
editor: Editor,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
changeReplace(editor, context)
VimPlugin.getChange().changeReplace(editor, context)
return true
}
}
/**
* Begin Replace mode
* @param editor The editor to replace in
* @param context The data context
*/
private fun changeReplace(editor: VimEditor, context: ExecutionContext) {
injector.changeGroup.initInsert(editor, context, CommandState.Mode.REPLACE)
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.OperatorArguments
@ -38,14 +38,14 @@ class ChangeVisualAction : VisualOperatorActionHandler.ForEachCaret() {
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MULTIKEY_UNDO, CommandFlags.FLAG_EXIT_VISUAL)
override fun executeAction(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
cmd: Command,
range: VimSelection,
operatorArguments: OperatorArguments,
): Boolean {
return injector.changeGroup.changeRange(
return VimPlugin.getChange().changeRange(
editor,
caret,
range.toVimTextRange(false),

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,17 +17,14 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.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.common.TextRange
import com.maddyhome.idea.vim.diagnostic.debug
import com.maddyhome.idea.vim.diagnostic.vimLogger
import com.maddyhome.idea.vim.group.visual.VimSelection
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler
import com.maddyhome.idea.vim.helper.enumSetOf
@ -44,40 +41,15 @@ class ChangeVisualCharacterAction : VisualOperatorActionHandler.ForEachCaret() {
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_ALLOW_DIGRAPH, CommandFlags.FLAG_EXIT_VISUAL)
override fun executeAction(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
cmd: Command,
range: VimSelection,
operatorArguments: OperatorArguments,
): Boolean {
val argument = cmd.argument
return argument != null &&
changeCharacterRange(editor, range.toVimTextRange(false), argument.character)
VimPlugin.getChange().changeCharacterRange(editor, range.toVimTextRange(false), argument.character)
}
}
private val logger = vimLogger<ChangeVisualCharacterAction>()
/**
* Each character in the supplied range gets replaced with the character ch
*
* @param editor The editor to change
* @param range The range to change
* @param ch The replacing character
* @return true if able to change the range, false if not
*/
private fun changeCharacterRange(editor: VimEditor, range: TextRange, ch: Char): Boolean {
logger.debug { "change range: $range to $ch" }
val chars = editor.text()
val starts = range.startOffsets
val ends = range.endOffsets
for (j in ends.indices.reversed()) {
for (i in starts[j] until ends[j]) {
if (i < chars.length && '\n' != chars[i]) {
injector.changeGroup.replaceText(editor, i, i + 1, Character.toString(ch))
}
}
}
return true
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.CommandFlags.FLAG_EXIT_VISUAL
@ -31,7 +31,9 @@ import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.group.visual.VimSelection
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.enumSetOf
import com.maddyhome.idea.vim.helper.fileSize
import java.util.*
/**
@ -43,21 +45,21 @@ class ChangeVisualLinesAction : VisualOperatorActionHandler.ForEachCaret() {
override val flags: EnumSet<CommandFlags> = enumSetOf(FLAG_MOT_LINEWISE, FLAG_MULTIKEY_UNDO, FLAG_EXIT_VISUAL)
override fun executeAction(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
cmd: Command,
range: VimSelection,
operatorArguments: OperatorArguments,
): Boolean {
val textRange = range.toVimTextRange(true)
val lineEndForOffset = injector.engineEditorHelper.getLineEndForOffset(editor, textRange.endOffset)
val endsWithNewLine = if (lineEndForOffset.toLong() == editor.fileSize()) 0 else 1
val lineEndForOffset = EditorHelper.getLineEndForOffset(editor, textRange.endOffset)
val endsWithNewLine = if (lineEndForOffset == editor.fileSize) 0 else 1
val lineRange = TextRange(
injector.engineEditorHelper.getLineStartForOffset(editor, textRange.startOffset),
EditorHelper.getLineStartForOffset(editor, textRange.startOffset),
lineEndForOffset + endsWithNewLine
)
return injector.changeGroup.changeRange(
return VimPlugin.getChange().changeRange(
editor,
caret,
lineRange,

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.CommandFlags.FLAG_EXIT_VISUAL
@ -31,7 +31,9 @@ import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.group.visual.VimSelection
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.enumSetOf
import com.maddyhome.idea.vim.helper.fileSize
import java.util.*
/**
@ -43,9 +45,9 @@ class ChangeVisualLinesEndAction : VisualOperatorActionHandler.ForEachCaret() {
override val flags: EnumSet<CommandFlags> = enumSetOf(FLAG_MOT_LINEWISE, FLAG_MULTIKEY_UNDO, FLAG_EXIT_VISUAL)
override fun executeAction(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
cmd: Command,
range: VimSelection,
operatorArguments: OperatorArguments,
@ -56,19 +58,19 @@ class ChangeVisualLinesEndAction : VisualOperatorActionHandler.ForEachCaret() {
val ends = vimTextRange.endOffsets
for (i in starts.indices) {
if (ends[i] > starts[i]) {
ends[i] = injector.engineEditorHelper.getLineEndForOffset(editor, starts[i])
ends[i] = EditorHelper.getLineEndForOffset(editor, starts[i])
}
}
val blockRange = TextRange(starts, ends)
injector.changeGroup.changeRange(editor, caret, blockRange, SelectionType.BLOCK_WISE, context)
VimPlugin.getChange().changeRange(editor, caret, blockRange, SelectionType.BLOCK_WISE, context)
} else {
val lineEndForOffset = injector.engineEditorHelper.getLineEndForOffset(editor, vimTextRange.endOffset)
val endsWithNewLine = if (lineEndForOffset.toLong() == editor.fileSize()) 0 else 1
val lineEndForOffset = EditorHelper.getLineEndForOffset(editor, vimTextRange.endOffset)
val endsWithNewLine = if (lineEndForOffset == editor.fileSize) 0 else 1
val lineRange = TextRange(
injector.engineEditorHelper.getLineStartForOffset(editor, vimTextRange.startOffset),
EditorHelper.getLineStartForOffset(editor, vimTextRange.startOffset),
lineEndForOffset + endsWithNewLine
)
injector.changeGroup.changeRange(editor, caret, lineRange, SelectionType.LINE_WISE, context)
VimPlugin.getChange().changeRange(editor, caret, lineRange, SelectionType.LINE_WISE, context)
}
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -18,13 +18,14 @@
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.action.DuplicableOperatorAction
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.DuplicableOperatorAction
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.group.MotionGroup
import com.maddyhome.idea.vim.handler.VimActionHandler
import com.maddyhome.idea.vim.helper.endOffsetInclusive
@ -36,21 +37,26 @@ class FilterMotionAction : VimActionHandler.SingleExecution(), DuplicableOperato
override val duplicateWith: Char = '!'
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
val argument = cmd.argument ?: return false
val range = injector.motion.getMotionRange(editor, editor.primaryCaret(), context, argument, operatorArguments)
val range = MotionGroup
.getMotionRange(
editor, editor.caretModel.primaryCaret, context,
argument,
operatorArguments
)
?: return false
val current = editor.currentCaret().getLogicalPosition()
val current = editor.caretModel.logicalPosition
val start = editor.offsetToLogicalPosition(range.startOffset)
val end = editor.offsetToLogicalPosition(range.endOffsetInclusive)
if (current.line != start.line) {
injector.motion.moveCaret(editor, editor.primaryCaret(), range.startOffset)
MotionGroup.moveCaret(editor, editor.caretModel.primaryCaret, range.startOffset)
}
val count = if (start.line < end.line) end.line - start.line + 1 else 1
injector.processGroup.startFilterCommand(editor, context, Argument.EMPTY_COMMAND.copy(rawCount = count))
VimPlugin.getProcess().startFilterCommand(editor, context, Argument.EMPTY_COMMAND.copy(rawCount = count))
return true
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,14 +17,15 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.VimActionHandler
import com.maddyhome.idea.vim.helper.enumSetOf
import com.maddyhome.idea.vim.helper.exitVisualMode
import java.util.*
/**
@ -35,9 +36,9 @@ class FilterVisualLinesAction : VimActionHandler.SingleExecution() {
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE)
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
injector.processGroup.startFilterCommand(editor, context, cmd)
editor.exitVisualModeNative()
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
VimPlugin.getProcess().startFilterCommand(editor, context, cmd)
editor.exitVisualMode()
return true
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,13 +17,13 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.action.DuplicableOperatorAction
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.DuplicableOperatorAction
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
@ -35,13 +35,13 @@ class ReformatCodeMotionAction : ChangeEditorActionHandler.ForEachCaret(), Dupli
override val duplicateWith: Char = 'q'
override fun execute(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
return argument != null &&
injector.changeGroup.reformatCodeMotion(editor, caret, context, argument, operatorArguments)
VimPlugin.getChange().reformatCodeMotion(editor, caret, context, argument, operatorArguments)
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.change
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.OperatorArguments
@ -38,14 +38,14 @@ class ReformatCodeVisualAction : VisualOperatorActionHandler.ForEachCaret() {
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_EXIT_VISUAL)
override fun executeAction(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
cmd: Command,
range: VimSelection,
operatorArguments: OperatorArguments,
): Boolean {
injector.changeGroup.reformatCodeSelection(editor, caret, range)
VimPlugin.getChange().reformatCodeSelection(editor, caret, range)
return true
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.change.number
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
@ -30,13 +30,13 @@ sealed class IncAction(val inc: Int) : ChangeEditorActionHandler.ForEachCaret()
override val type: Command.Type = Command.Type.CHANGE
override fun execute(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
return injector.changeGroup.changeNumber(editor, caret, inc * operatorArguments.count1)
return VimPlugin.getChange().changeNumber(editor, caret, inc * operatorArguments.count1)
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.change.number
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.OperatorArguments
@ -34,14 +34,15 @@ sealed class IncNumber(val inc: Int, private val avalanche: Boolean) : VisualOpe
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_EXIT_VISUAL)
override fun executeAction(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
cmd: Command,
range: VimSelection,
operatorArguments: OperatorArguments,
): Boolean {
return injector.changeGroup.changeNumberVisualMode(editor, caret, range.toVimTextRange(false), inc * cmd.count, avalanche)
return VimPlugin.getChange()
.changeNumberVisualMode(editor, caret, range.toVimTextRange(false), inc * cmd.count, avalanche)
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.delete
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
@ -34,12 +34,12 @@ abstract class DeleteCharacter(private val countModifier: (Int) -> Int) : Change
override val type: Command.Type = Command.Type.DELETE
override fun execute(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
return injector.changeGroup.deleteCharacter(editor, caret, countModifier(operatorArguments.count1), false)
return VimPlugin.getChange().deleteCharacter(editor, caret, countModifier(operatorArguments.count1), false)
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.delete
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
@ -30,12 +30,12 @@ class DeleteEndOfLineAction : ChangeEditorActionHandler.ForEachCaret() {
override val type: Command.Type = Command.Type.DELETE
override fun execute(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
return injector.changeGroup.deleteEndOfLine(editor, caret, operatorArguments.count1)
return VimPlugin.getChange().deleteEndOfLine(editor, caret, operatorArguments.count1)
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,38 +17,38 @@
*/
package com.maddyhome.idea.vim.action.change.delete
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.Ref
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
import com.maddyhome.idea.vim.options.OptionScope
import com.maddyhome.idea.vim.vimscript.services.IjVimOptionService
import com.maddyhome.idea.vim.vimscript.services.OptionService
class DeleteJoinLinesAction : ChangeEditorActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.DELETE
override fun execute(
editor: VimEditor,
context: ExecutionContext,
editor: Editor,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
if (editor.isOneLineMode()) return false
if (injector.optionService.isSet(OptionScope.LOCAL(editor), IjVimOptionService.ideajoinName)) {
return injector.changeGroup.joinViaIdeaByCount(editor, context, operatorArguments.count1)
if (editor.isOneLineMode) return false
if (VimPlugin.getOptionService().isSet(OptionService.Scope.LOCAL(editor), "ideajoin")) {
return VimPlugin.getChange().joinViaIdeaByCount(editor, context, operatorArguments.count1)
}
injector.editorGroup.notifyIdeaJoin(editor)
val res = arrayOf(true)
editor.forEachNativeCaret(
{ caret: VimCaret ->
if (!injector.changeGroup.deleteJoinLines(editor, caret, operatorArguments.count1, false)) res[0] = false
VimPlugin.getEditor().notifyIdeaJoin(editor.project)
val res = Ref.create(true)
editor.caretModel.runForEachCaret(
{ caret: Caret ->
if (!VimPlugin.getChange().deleteJoinLines(editor, caret, operatorArguments.count1, false)) res.set(false)
},
true
)
return res[0]
return res.get()
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,38 +17,38 @@
*/
package com.maddyhome.idea.vim.action.change.delete
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.Ref
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
import com.maddyhome.idea.vim.options.OptionScope
import com.maddyhome.idea.vim.vimscript.services.IjVimOptionService
import com.maddyhome.idea.vim.vimscript.services.OptionService
class DeleteJoinLinesSpacesAction : ChangeEditorActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.DELETE
override fun execute(
editor: VimEditor,
context: ExecutionContext,
editor: Editor,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
if (editor.isOneLineMode()) return false
if (injector.optionService.isSet(OptionScope.LOCAL(editor), IjVimOptionService.ideajoinName)) {
return injector.changeGroup.joinViaIdeaByCount(editor, context, operatorArguments.count1)
if (editor.isOneLineMode) return false
if (VimPlugin.getOptionService().isSet(OptionService.Scope.LOCAL(editor), "ideajoin")) {
return VimPlugin.getChange().joinViaIdeaByCount(editor, context, operatorArguments.count1)
}
injector.editorGroup.notifyIdeaJoin(editor)
val res = arrayOf(true)
editor.forEachNativeCaret(
{ caret: VimCaret ->
if (!injector.changeGroup.deleteJoinLines(editor, caret, operatorArguments.count1, true)) res[0] = false
VimPlugin.getEditor().notifyIdeaJoin(editor.project)
val res = Ref.create(true)
editor.caretModel.runForEachCaret(
{ caret: Caret ->
if (!VimPlugin.getChange().deleteJoinLines(editor, caret, operatorArguments.count1, true)) res.set(false)
},
true
)
return res[0]
return res.get()
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,18 +17,18 @@
*/
package com.maddyhome.idea.vim.action.change.delete
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.Ref
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.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.options.OptionScope
import com.maddyhome.idea.vim.vimscript.services.IjVimOptionService
import com.maddyhome.idea.vim.vimscript.services.OptionService
import java.util.*
/**
@ -40,28 +40,28 @@ class DeleteJoinVisualLinesAction : VisualOperatorActionHandler.SingleExecution(
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_EXIT_VISUAL)
override fun executeForAllCarets(
editor: VimEditor,
context: ExecutionContext,
editor: Editor,
context: DataContext,
cmd: Command,
caretsAndSelections: Map<VimCaret, VimSelection>,
caretsAndSelections: Map<Caret, VimSelection>,
operatorArguments: OperatorArguments,
): Boolean {
if (editor.isOneLineMode()) return false
if (injector.optionService.isSet(OptionScope.LOCAL(editor), IjVimOptionService.ideajoinName)) {
injector.changeGroup.joinViaIdeaBySelections(editor, context, caretsAndSelections)
if (editor.isOneLineMode) return false
if (VimPlugin.getOptionService().isSet(OptionService.Scope.LOCAL(editor), "ideajoin")) {
VimPlugin.getChange().joinViaIdeaBySelections(editor, context, caretsAndSelections)
return true
}
val res = arrayOf(true)
editor.forEachNativeCaret(
{
caret: VimCaret ->
if (!caret.isValid) return@forEachNativeCaret
val range = caretsAndSelections[caret] ?: return@forEachNativeCaret
if (!injector.changeGroup.deleteJoinRange(editor, caret, range.toVimTextRange(true).normalize(), false)) {
res[0] = false
val res = Ref.create(true)
editor.caretModel.runForEachCaret(
{ caret: Caret ->
if (!caret.isValid) return@runForEachCaret
val range = caretsAndSelections[caret] ?: return@runForEachCaret
if (!VimPlugin.getChange().deleteJoinRange(editor, caret, range.toVimTextRange(true).normalize(), false)) {
res.set(false)
}
}, true
},
true
)
return res[0]
return res.get()
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,18 +17,18 @@
*/
package com.maddyhome.idea.vim.action.change.delete
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.Ref
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.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.options.OptionScope
import com.maddyhome.idea.vim.vimscript.services.IjVimOptionService
import com.maddyhome.idea.vim.vimscript.services.OptionService
import java.util.*
/**
@ -40,28 +40,28 @@ class DeleteJoinVisualLinesSpacesAction : VisualOperatorActionHandler.SingleExec
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_EXIT_VISUAL)
override fun executeForAllCarets(
editor: VimEditor,
context: ExecutionContext,
editor: Editor,
context: DataContext,
cmd: Command,
caretsAndSelections: Map<VimCaret, VimSelection>,
caretsAndSelections: Map<Caret, VimSelection>,
operatorArguments: OperatorArguments,
): Boolean {
if (editor.isOneLineMode()) return false
if (injector.optionService.isSet(OptionScope.LOCAL(editor), IjVimOptionService.ideajoinName)) {
injector.changeGroup.joinViaIdeaBySelections(editor, context, caretsAndSelections)
if (editor.isOneLineMode) return false
if (VimPlugin.getOptionService().isSet(OptionService.Scope.LOCAL(editor), "ideajoin")) {
VimPlugin.getChange().joinViaIdeaBySelections(editor, context, caretsAndSelections)
return true
}
val res = arrayOf(true)
editor.forEachNativeCaret(
{ caret: VimCaret ->
if (!caret.isValid) return@forEachNativeCaret
val range = caretsAndSelections[caret] ?: return@forEachNativeCaret
if (!injector.changeGroup.deleteJoinRange(editor, caret, range.toVimTextRange(true).normalize(), true)) {
res[0] = false
val res = Ref.create(true)
editor.caretModel.runForEachCaret(
{ caret: Caret ->
if (!caret.isValid) return@runForEachCaret
val range = caretsAndSelections[caret] ?: return@runForEachCaret
if (!VimPlugin.getChange().deleteJoinRange(editor, caret, range.toVimTextRange(true).normalize(), true)) {
res.set(false)
}
},
true
)
return res[0]
return res.get()
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,17 +17,17 @@
*/
package com.maddyhome.idea.vim.action.change.delete
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.action.DuplicableOperatorAction
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.DuplicableOperatorAction
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.group.deleteRange
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
import com.maddyhome.idea.vim.options.OptionConstants
import com.maddyhome.idea.vim.options.OptionScope
import com.maddyhome.idea.vim.vimscript.services.OptionService
class DeleteMotionAction : ChangeEditorActionHandler.ForEachCaret(), DuplicableOperatorAction {
override val type: Command.Type = Command.Type.DELETE
@ -37,23 +37,23 @@ class DeleteMotionAction : ChangeEditorActionHandler.ForEachCaret(), DuplicableO
override val duplicateWith: Char = 'd'
override fun execute(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
if (argument == null) return false
if (injector.optionService.isSet(OptionScope.GLOBAL, OptionConstants.experimentalapiName)) {
val (first, second) = injector.changeGroup
if (VimPlugin.getOptionService().isSet(OptionService.Scope.GLOBAL, "experimentalapi")) {
val (first, second) = VimPlugin.getChange()
.getDeleteRangeAndType2(editor, caret, context, argument, false, operatorArguments)
?: return false
return injector.changeGroup.deleteRange2(editor, caret, first, second)
return deleteRange(editor, caret, first, second)
} else {
val (first, second) = injector.changeGroup
val (first, second) = VimPlugin.getChange()
.getDeleteRangeAndType(editor, caret, context, argument, false, operatorArguments)
?: return false
return injector.changeGroup.deleteRange(editor, caret, first, second, false)
return VimPlugin.getChange().deleteRange(editor, caret, first, second, false)
}
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.delete
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.OperatorArguments
@ -38,14 +38,14 @@ class DeleteVisualAction : VisualOperatorActionHandler.ForEachCaret() {
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_EXIT_VISUAL)
override fun executeAction(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
cmd: Command,
range: VimSelection,
operatorArguments: OperatorArguments,
): Boolean {
val selectionType = range.type
return injector.changeGroup.deleteRange(editor, caret, range.toVimTextRange(false), selectionType, false)
return VimPlugin.getChange().deleteRange(editor, caret, range.toVimTextRange(false), selectionType, false)
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.delete
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.OperatorArguments
@ -28,7 +28,9 @@ import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.group.visual.VimSelection
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.enumSetOf
import com.maddyhome.idea.vim.helper.fileSize
import java.util.*
/**
@ -40,27 +42,27 @@ class DeleteVisualLinesAction : VisualOperatorActionHandler.ForEachCaret() {
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_EXIT_VISUAL)
override fun executeAction(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
cmd: Command,
range: VimSelection,
operatorArguments: OperatorArguments,
): Boolean {
val textRange = range.toVimTextRange(false)
val (usedCaret, usedRange, usedType) = when (range.type) {
SelectionType.BLOCK_WISE -> Triple(editor.primaryCaret(), textRange, range.type)
SelectionType.BLOCK_WISE -> Triple(editor.caretModel.primaryCaret, textRange, range.type)
SelectionType.LINE_WISE -> Triple(caret, textRange, SelectionType.LINE_WISE)
SelectionType.CHARACTER_WISE -> {
val lineEndForOffset = injector.engineEditorHelper.getLineEndForOffset(editor, textRange.endOffset)
val endsWithNewLine = if (lineEndForOffset.toLong() == editor.fileSize()) 0 else 1
val lineEndForOffset = EditorHelper.getLineEndForOffset(editor, textRange.endOffset)
val endsWithNewLine = if (lineEndForOffset == editor.fileSize) 0 else 1
val lineRange = TextRange(
injector.engineEditorHelper.getLineStartForOffset(editor, textRange.startOffset),
EditorHelper.getLineStartForOffset(editor, textRange.startOffset),
lineEndForOffset + endsWithNewLine
)
Triple(caret, lineRange, SelectionType.LINE_WISE)
}
}
return injector.changeGroup.deleteRange(editor, usedCaret, usedRange, usedType, false)
return VimPlugin.getChange().deleteRange(editor, usedCaret, usedRange, usedType, false)
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.delete
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.OperatorArguments
@ -28,7 +28,9 @@ import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.group.visual.VimSelection
import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.enumSetOf
import com.maddyhome.idea.vim.helper.fileSize
import java.util.*
/**
@ -40,9 +42,9 @@ class DeleteVisualLinesEndAction : VisualOperatorActionHandler.ForEachCaret() {
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MOT_LINEWISE, CommandFlags.FLAG_EXIT_VISUAL)
override fun executeAction(
editor: VimEditor,
caret: VimCaret,
context: ExecutionContext,
editor: Editor,
caret: Caret,
context: DataContext,
cmd: Command,
range: VimSelection,
operatorArguments: OperatorArguments,
@ -53,19 +55,20 @@ class DeleteVisualLinesEndAction : VisualOperatorActionHandler.ForEachCaret() {
val ends = vimTextRange.endOffsets
for (i in starts.indices) {
if (ends[i] > starts[i]) {
ends[i] = injector.engineEditorHelper.getLineEndForOffset(editor, starts[i])
ends[i] = EditorHelper.getLineEndForOffset(editor, starts[i])
}
}
val blockRange = TextRange(starts, ends)
injector.changeGroup.deleteRange(editor, editor.primaryCaret(), blockRange, SelectionType.BLOCK_WISE, false)
VimPlugin.getChange()
.deleteRange(editor, editor.caretModel.primaryCaret, blockRange, SelectionType.BLOCK_WISE, false)
} else {
val lineEndForOffset = injector.engineEditorHelper.getLineEndForOffset(editor, vimTextRange.endOffset)
val endsWithNewLine = if (lineEndForOffset.toLong() == editor.fileSize()) 0 else 1
val lineEndForOffset = EditorHelper.getLineEndForOffset(editor, vimTextRange.endOffset)
val endsWithNewLine = if (lineEndForOffset == editor.fileSize) 0 else 1
val lineRange = TextRange(
injector.engineEditorHelper.getLineStartForOffset(editor, vimTextRange.startOffset),
EditorHelper.getLineStartForOffset(editor, vimTextRange.startOffset),
lineEndForOffset + endsWithNewLine
)
injector.changeGroup.deleteRange(editor, caret, lineRange, SelectionType.LINE_WISE, false)
VimPlugin.getChange().deleteRange(editor, caret, lineRange, SelectionType.LINE_WISE, false)
}
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,9 +17,9 @@
*/
package com.maddyhome.idea.vim.action.change.insert
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
@ -34,12 +34,12 @@ class InsertAfterCursorAction : ChangeEditorActionHandler.SingleExecution() {
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MULTIKEY_UNDO)
override fun execute(
editor: VimEditor,
context: ExecutionContext,
editor: Editor,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
injector.changeGroup.insertAfterCursor(editor, context)
VimPlugin.getChange().insertAfterCursor(editor, context)
return true
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,9 +17,9 @@
*/
package com.maddyhome.idea.vim.action.change.insert
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
@ -34,12 +34,12 @@ class InsertAfterLineEndAction : ChangeEditorActionHandler.SingleExecution() {
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MULTIKEY_UNDO)
override fun execute(
editor: VimEditor,
context: ExecutionContext,
editor: Editor,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
injector.changeGroup.insertAfterLineEnd(editor, context)
VimPlugin.getChange().insertAfterLineEnd(editor, context)
return true
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,9 +17,9 @@
*/
package com.maddyhome.idea.vim.action.change.insert
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
@ -34,27 +34,12 @@ class InsertAtPreviousInsertAction : ChangeEditorActionHandler.SingleExecution()
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MULTIKEY_UNDO)
override fun execute(
editor: VimEditor,
context: ExecutionContext,
editor: Editor,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
insertAtPreviousInsert(editor, context)
VimPlugin.getChange().insertAtPreviousInsert(editor, context)
return true
}
}
/**
* Begin insert at the location of the previous insert
*
* @param editor The editor to insert into
*/
fun insertAtPreviousInsert(editor: VimEditor, context: ExecutionContext) {
editor.removeSecondaryCarets()
val caret = editor.primaryCaret()
val offset = injector.motion.moveCaretToMark(editor, '^', false)
if (offset != -1) {
caret.moveToOffset(offset)
}
injector.changeGroup.insertBeforeCursor(editor, context)
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,9 +17,9 @@
*/
package com.maddyhome.idea.vim.action.change.insert
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
@ -36,12 +36,12 @@ class InsertBeforeCursorAction : ChangeEditorActionHandler.SingleExecution() {
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MULTIKEY_UNDO)
override fun execute(
editor: VimEditor,
context: ExecutionContext,
editor: Editor,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
injector.changeGroup.insertBeforeCursor(editor, context)
VimPlugin.getChange().insertBeforeCursor(editor, context)
return true
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,9 +17,9 @@
*/
package com.maddyhome.idea.vim.action.change.insert
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
@ -34,12 +34,12 @@ class InsertBeforeFirstNonBlankAction : ChangeEditorActionHandler.SingleExecutio
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MULTIKEY_UNDO)
override fun execute(
editor: VimEditor,
context: ExecutionContext,
editor: Editor,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
injector.changeGroup.insertBeforeFirstNonBlank(editor, context)
VimPlugin.getChange().insertBeforeFirstNonBlank(editor, context)
return true
}
}

View File

@ -0,0 +1,43 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.maddyhome.idea.vim.action.change.insert
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
class InsertCharacterAboveCursorAction : ChangeEditorActionHandler.ForEachCaret() {
override val type: Command.Type = Command.Type.INSERT
override fun execute(
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
return if (editor.isOneLineMode) {
false
} else VimPlugin.getChange().insertCharacterAroundCursor(editor, caret, -1)
}
}

View File

@ -0,0 +1,43 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.maddyhome.idea.vim.action.change.insert
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
class InsertCharacterBelowCursorAction : ChangeEditorActionHandler.ForEachCaret() {
override val type: Command.Type = Command.Type.INSERT
override fun execute(
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
return if (editor.isOneLineMode) {
false
} else VimPlugin.getChange().insertCharacterAroundCursor(editor, caret, 1)
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -18,9 +18,9 @@
package com.maddyhome.idea.vim.action.change.insert
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
@ -31,7 +31,7 @@ class InsertCompletedDigraphAction : VimActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.INSERT
override val argumentType: Argument.Type = Argument.Type.DIGRAPH
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
// The converted digraph character has been captured as an argument, push it back through key handler
val keyStroke = KeyStroke.getKeyStroke(cmd.argument!!.character)
KeyHandler.getInstance().handleKey(editor, keyStroke, context)

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -18,9 +18,9 @@
package com.maddyhome.idea.vim.action.change.insert
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
@ -31,7 +31,7 @@ class InsertCompletedLiteralAction : VimActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.INSERT
override val argumentType: Argument.Type = Argument.Type.DIGRAPH
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
// The converted literal character has been captured as an argument, push it back through key handler
val keyStroke = KeyStroke.getKeyStroke(cmd.argument!!.character)
KeyHandler.getInstance().handleKey(editor, keyStroke, context)

View File

@ -0,0 +1,46 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.maddyhome.idea.vim.action.change.insert
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.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.handler.ChangeEditorActionHandler
import com.maddyhome.idea.vim.helper.enumSetOf
import java.util.*
class InsertDeleteInsertedTextAction : ChangeEditorActionHandler.ForEachCaret() {
override val type: Command.Type = Command.Type.INSERT
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_CLEAR_STROKES)
override fun execute(
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
return VimPlugin.getChange().insertDeleteInsertedText(editor, caret)
}
}

View File

@ -0,0 +1,46 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.maddyhome.idea.vim.action.change.insert
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.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.handler.ChangeEditorActionHandler
import com.maddyhome.idea.vim.helper.enumSetOf
import java.util.*
class InsertDeletePreviousWordAction : ChangeEditorActionHandler.ForEachCaret() {
override val type: Command.Type = Command.Type.INSERT
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_CLEAR_STROKES)
override fun execute(
editor: Editor,
caret: Caret,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
return VimPlugin.getChange().insertDeletePreviousWord(editor, caret)
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,14 +17,16 @@
*/
package com.maddyhome.idea.vim.action.change.insert
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.group.MotionGroup
import com.maddyhome.idea.vim.handler.VimActionHandler
import com.maddyhome.idea.vim.helper.enumSetOf
import com.maddyhome.idea.vim.helper.getTopLevelEditor
import java.util.*
class InsertEnterAction : VimActionHandler.SingleExecution() {
@ -32,9 +34,9 @@ class InsertEnterAction : VimActionHandler.SingleExecution() {
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_SAVE_STROKE)
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
injector.changeGroup.processEnter(editor, context)
injector.motion.scrollCaretIntoView(editor)
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
VimPlugin.getChange().processEnter(editor.getTopLevelEditor(), context)
MotionGroup.scrollCaretIntoView(editor)
return true
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,16 +17,17 @@
*/
package com.maddyhome.idea.vim.action.change.insert
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.VimActionHandler
import com.maddyhome.idea.vim.helper.exitInsertMode
class InsertExitModeAction : VimActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.INSERT
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
editor.exitInsertMode(context, operatorArguments)
return true
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,13 +17,13 @@
*/
package com.maddyhome.idea.vim.action.change.insert
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.VimActionHandler
import com.maddyhome.idea.vim.helper.commandState
import com.maddyhome.idea.vim.helper.enumSetOf
import java.util.*
@ -32,18 +32,8 @@ class InsertInsertAction : VimActionHandler.SingleExecution() {
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_SAVE_STROKE)
override fun execute(
editor: VimEditor,
context: ExecutionContext,
cmd: Command,
operatorArguments: OperatorArguments,
): Boolean {
processInsert(editor)
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
VimPlugin.getChange().processInsert(editor)
return true
}
}
private fun processInsert(editor: VimEditor) {
editor.insertMode = !editor.insertMode
editor.commandState.toggleInsertOverwrite()
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,9 +17,9 @@
*/
package com.maddyhome.idea.vim.action.change.insert
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
@ -34,12 +34,12 @@ class InsertLineStartAction : ChangeEditorActionHandler.SingleExecution() {
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MULTIKEY_UNDO)
override fun execute(
editor: VimEditor,
context: ExecutionContext,
editor: Editor,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
injector.changeGroup.insertLineStart(editor, context)
VimPlugin.getChange().insertLineStart(editor, context)
return true
}
}

View File

@ -0,0 +1,46 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.maddyhome.idea.vim.action.change.insert
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
import com.maddyhome.idea.vim.helper.enumSetOf
import java.util.*
class InsertNewLineAboveAction : ChangeEditorActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.INSERT
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MULTIKEY_UNDO)
override fun execute(
editor: Editor,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
if (editor.isOneLineMode) return false
VimPlugin.getChange().insertNewLineAbove(editor, context)
return true
}
}

View File

@ -0,0 +1,46 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.maddyhome.idea.vim.action.change.insert
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
import com.maddyhome.idea.vim.helper.enumSetOf
import java.util.*
class InsertNewLineBelowAction : ChangeEditorActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.INSERT
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_MULTIKEY_UNDO)
override fun execute(
editor: Editor,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
if (editor.isOneLineMode) return false
VimPlugin.getChange().insertNewLineBelow(editor, context)
return true
}
}

View File

@ -0,0 +1,40 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.maddyhome.idea.vim.action.change.insert
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
class InsertPreviousInsertAction : ChangeEditorActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.INSERT
override fun execute(
editor: Editor,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
VimPlugin.getChange().insertPreviousInsert(editor, context, false, operatorArguments)
return true
}
}

View File

@ -1,6 +1,6 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,10 +17,10 @@
*/
package com.maddyhome.idea.vim.action.change.insert
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.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.api.injector
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
@ -28,20 +28,6 @@ import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
import java.awt.event.KeyEvent
import javax.swing.KeyStroke
class InsertPreviousInsertAction : ChangeEditorActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.INSERT
override fun execute(
editor: VimEditor,
context: ExecutionContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
injector.changeGroup.insertPreviousInsert(editor, context, false, operatorArguments)
return true
}
}
class InsertPreviousInsertExitAction : ChangeEditorActionHandler.SingleExecution(), ComplicatedKeysAction {
override val keyStrokesSet: Set<List<KeyStroke>> = setOf(
listOf(KeyStroke.getKeyStroke(KeyEvent.VK_2, KeyEvent.CTRL_DOWN_MASK or KeyEvent.SHIFT_DOWN_MASK)),
@ -52,12 +38,12 @@ class InsertPreviousInsertExitAction : ChangeEditorActionHandler.SingleExecution
override val type: Command.Type = Command.Type.INSERT
override fun execute(
editor: VimEditor,
context: ExecutionContext,
editor: Editor,
context: DataContext,
argument: Argument?,
operatorArguments: OperatorArguments,
): Boolean {
injector.changeGroup.insertPreviousInsert(editor, context, true, operatorArguments)
VimPlugin.getChange().insertPreviousInsert(editor, context, true, operatorArguments)
return false
}
}
}

View File

@ -0,0 +1,70 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.maddyhome.idea.vim.action.change.insert
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.ex.ExException
import com.maddyhome.idea.vim.handler.VimActionHandler
import com.maddyhome.idea.vim.helper.CommandLineHelper
import com.maddyhome.idea.vim.vimscript.model.Script
import com.maddyhome.idea.vim.vimscript.parser.VimscriptParser
class InsertRegisterAction : VimActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.INSERT
override val argumentType: Argument.Type = Argument.Type.CHARACTER
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
val argument = cmd.argument
if (argument?.character == '=') {
ApplicationManager.getApplication().invokeLater {
try {
val expression = readExpression(editor)
if (expression != null) {
if (expression.isNotEmpty()) {
val expressionValue = VimscriptParser.parseExpression(expression)?.evaluate(editor, context, Script(listOf()))
?: throw ExException("E15: Invalid expression: $expression")
val textToStore = expressionValue.toInsertableString()
VimPlugin.getRegister().storeTextSpecial('=', textToStore)
}
VimPlugin.getChange().insertRegister(editor, context, argument.character)
}
} catch (e: ExException) {
VimPlugin.indicateError()
VimPlugin.showMessage(e.message)
}
}
return true
} else {
return argument != null && VimPlugin.getChange().insertRegister(editor, context, argument.character)
}
}
@SuppressWarnings("deprecation") // [VERSION UPDATE] 212+ getService
private fun readExpression(editor: Editor): String? {
return ServiceManager.getService(CommandLineHelper::class.java).inputString(editor, "=", null)
}
}

Some files were not shown because too many files have changed in this diff Show More