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

Compare commits

...

79 Commits

Author SHA1 Message Date
Alex Plate
1791692d92
Use java boolean 2022-07-05 12:26:16 +03:00
Alex Plate
ba23c9ab5e
Rename variable service 2022-07-05 11:27:53 +03:00
Alex Plate
f96ab37bcb
Rename Scope 2022-07-05 11:04:08 +03:00
Alex Plate
0da34bbb34
Compatibility of toggleOption 2022-07-05 10:56:45 +03:00
Alex Plate
51e7c745ea
Move number option to a different package 2022-07-05 10:26:14 +03:00
aleksei.plate
8347251572 TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: triggers of 'IdeaVim compatibility with external plugins' build configuration were updated 2022-07-05 07:13:58 +00:00
aleksei.plate
ce8512f4e0 TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: triggers of 'IdeaVim compatibility with external plugins' build configuration were updated 2022-07-05 07:13:22 +00:00
aleksei.plate
a724a19d00 TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: triggers of 'IdeaVim compatibility with external plugins' build configuration were updated 2022-07-05 07:13:00 +00:00
Alex Plate
7eae7a98e8
Command state compatibility 2022-07-05 10:05:02 +03:00
Alex Plate
fe9566eebd
Convert helper to kt 2022-07-04 10:59:24 +03:00
Alex Plate
b69756730f
Rename .java to .kt 2022-07-04 10:59:23 +03:00
Alex Plate
6cd1a60b53
More compatibility 2022-07-04 10:33:31 +03:00
Alex Plate
9d935e47b5
Move compatibility 2022-07-04 09:49:50 +03:00
Alex Plate
a7d5372d06
Move classes to a different package 2022-07-04 09:49:50 +03:00
Alex Plate
a575942c81
Compatibility 2022-07-04 09:49:50 +03:00
aleksei.plate
3cf6c53a8e TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: runners of 'IdeaVim compatibility with external plugins' build configuration were updated 2022-07-04 06:40:47 +00:00
aleksei.plate
91d86680de TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: runners of 'IdeaVim compatibility with external plugins' build configuration were updated 2022-07-04 06:22:54 +00:00
aleksei.plate
d1d082fb99 TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: runners of 'IdeaVim compatibility with external plugins' build configuration were updated 2022-07-04 06:15:19 +00:00
aleksei.plate
2c634d1bf0 TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: runners of 'IdeaVim compatibility with external plugins' build configuration were updated 2022-07-04 06:06:43 +00:00
aleksei.plate
02a6fe4dc9 TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: runners of 'IdeaVim compatibility with external plugins' build configuration were updated 2022-07-04 06:03:46 +00:00
aleksei.plate
223d681526 TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: VCS roots of 'IdeaVim compatibility with external plugins' build configuration were updated 2022-07-04 06:03:33 +00:00
aleksei.plate
f42ef1c2fc TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: VCS roots of 'IdeaVim compatibility with external plugins' build configuration were updated 2022-07-04 06:03:27 +00:00
Alex Plate
f4817b2111
Add compatibility verifier to the repo 2022-07-04 08:59:31 +03:00
Alex Plate
6f5def0abf Update formatting 2022-07-03 00:19:25 +00:00
filipp
f0fcd7f133 Better offset for multiple carets with surround 2022-07-02 18:59:21 +06:00
filipp
6115adb72e Add registers to carets 2022-07-02 18:51:10 +06:00
filipp
bfd0b5fd91 Merge remote-tracking branch 'origin/master' 2022-07-02 11:21:33 +06:00
Alex Plate
6c0a52155b
Add compatibility method 2022-07-01 16:36:30 +03:00
Alex Plate
c7ebce39bf
Make options compatible 2022-07-01 16:10:13 +03:00
Alex Plate
a0dc7a792f
Add more compatibility methods 2022-07-01 15:55:07 +03:00
Alex Plate
fdb09a8f1f
Use vim-engine kotlin settings 2022-07-01 12:18:53 +03:00
Alex Plate
4ac2aa2339
Apply kotlin options to all projects 2022-07-01 11:29:15 +03:00
Alex Plate
ebbc20692a
Add JVM compatibility option to the compiler 2022-07-01 10:58:32 +03:00
Alex Plate
5c82d112c9
More compatibility methods 2022-07-01 10:05:13 +03:00
Alex Plate
40fd50d7f1
Add midding import 2022-07-01 09:27:07 +03:00
Alex Plate
f7b948fee2
Add CommandState compatibility layer and rename our main CommandState to VimStateMachine 2022-07-01 09:04:27 +03:00
Alex Plate
6cdcf133bb
Use snapshot version of gradle plugin 2022-06-30 09:14:29 +03:00
filipp
f3025757b6 Merge remote-tracking branch 'origin/master' 2022-06-30 11:02:41 +06:00
nikita.koshcheev
a49811a3f9 TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: Updated cloud profile 'amazon-48' in project 'project55' 2022-06-29 15:16:26 +00:00
Alex Plate
2ac4b265d1
Add compatibility method 2022-06-29 16:30:26 +03:00
Alex Plate
46e994b563
Fix incorrect inheritance 2022-06-29 11:42:21 +03:00
Alex Plate
81482bd298
Add more compatibility changes 2022-06-29 11:25:11 +03:00
Alex Plate
f1a239c085
Make compatibility function public 2022-06-29 10:42:04 +03:00
Alex Plate
a48e38de7b
Make function static 2022-06-29 10:25:41 +03:00
Alex Plate
0aaacee117
Add more classes for compatibility 2022-06-29 09:54:50 +03:00
Alex Plate
b8373af69f
Move MappingMode to a different package 2022-06-29 09:54:49 +03:00
Alex Plate
e99b2ee73d
Add new method for compatibility 2022-06-29 09:54:49 +03:00
aleksei.plate
705022331a TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: general settings of 'IdeaVim compatibility with external plugins' build configuration were updated 2022-06-28 08:48:58 +00:00
aleksei.plate
bf62d444bf TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: general settings of 'IdeaVim compatibility with external plugin' build configuration were updated 2022-06-28 08:47:35 +00:00
aleksei.plate
5dcff5657b TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: general settings of 'IdeaVim compativility with external plugin' build configuration were updated 2022-06-28 08:47:11 +00:00
Alex Plate
7e79d5a960
Add method for compatibility 2022-06-28 11:13:54 +03:00
Alex Plate
c1b480976d
Include source files into distribution 2022-06-28 11:13:54 +03:00
Alex Plate
ddabbe6891
Use vim-engine as API instead of implementation 2022-06-28 11:13:54 +03:00
Alex Plate
ffa3052b50
Update build version of IJ 2022-06-28 11:13:54 +03:00
Alex Plate
654ea88851
Add collecting of sources to the resulting jar 2022-06-28 11:13:54 +03:00
filipp
4dc7982baa (EA-480768) Better exception message 2022-06-27 16:19:45 +06:00
aleksei.plate
ae2fc1cd85 TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: runners of 'Build' build configuration were updated 2022-06-27 06:17:38 +00:00
aleksei.plate
78bc8666e6 TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: build features of 'Build' build configuration were updated 2022-06-27 06:16:33 +00:00
aleksei.plate
9c2de2cfc7 TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: build configuration was created from URL 2022-06-27 06:16:18 +00:00
aleksei.plate
71e81465f3 TeamCity change in 'IntelliJ IDEA plugins / IdeaVim' project: 'IdeaVimCompatibility' VCS root was created 2022-06-27 06:15:35 +00:00
Alex Plate
885031e086
Fix test class without test methods 2022-06-27 07:59:22 +03:00
Alex Plate
d77c5bb5cf Update formatting 2022-06-26 00:20:17 +00:00
Alex Plate
781bce0000 Update changelog 2022-06-24 05:27:52 +00:00
Alex Plate
a3ca1b965b
Fix(VIM-2691): Save file on :w 2022-06-24 08:26:02 +03:00
Alex Plate
dd20b480a7
Update changelog 2022-06-24 08:26:02 +03:00
filipp
38292e97af Fix context for function argument evaluation 2022-06-24 03:13:07 +06:00
filipp
46ea752164 Add tolower(), toupper(), join() 2022-06-24 02:58:41 +06:00
Alex Plate
194b744361 Update changelog 2022-06-23 15:29:40 +00:00
b50197f7ce Fix(VIM-2227): Wrong behavior when deleting / changing surround with invalid character 2022-06-23 18:19:28 +03:00
Alex Plate
c00703d1d0
Manually define excluded from qodana files 2022-06-23 13:50:35 +03:00
Alex Plate
6e12377116
Remove generated code from qodana 2022-06-23 13:08:53 +03:00
Alex Plate
b0c4391ad8
Remove some files from qodana inspection 2022-06-22 20:30:14 +03:00
Alex Plate
f43ac2538a
Enable dependency checker in qodana 2022-06-22 18:36:08 +03:00
Alex Plate
9eaf8b5d2d
Move some other methods to vim-engine 2022-06-22 18:36:08 +03:00
filipp
e365d0b07c Unsubscribe document listener in UndoRedoHelper 2022-06-20 03:26:40 +06:00
filipp
69c273c4a5 Track more actions 2022-06-19 01:07:18 +06:00
filipp
f7950e7adb Fix(VIM-2683) Pasting from system clipboard multiple lines freezes the main thread 2022-06-18 07:31:44 +06:00
filipp
7c1ae9812e Update formatting 2022-06-18 06:26:11 +06:00
filipp
5c794ac40e Fix(VIM-749) Support for :let command 2022-06-18 06:21:26 +06:00
304 changed files with 7584 additions and 5053 deletions

View File

@ -13,7 +13,11 @@ object Constants {
const val PROPERTY_TESTS = "LATEST-EAP-SNAPSHOT"
const val LONG_RUNNING_TESTS = "LATEST-EAP-SNAPSHOT"
const val QODANA_TESTS = "LATEST-EAP-SNAPSHOT"
const val RELEASE = "2021.3"
const val RELEASE_DEV = "LATEST-EAP-SNAPSHOT"
const val RELEASE_EAP = "LATEST-EAP-SNAPSHOT"
const val RELEASE = "2022.1.3"
// Use LATEST-EAP-SNAPSHOT only when we'll update the minimum version of IJ to 222+
// Because of some API inconcistincies, IdeaVim built on 2022+ won't run on older versions of IJ
const val RELEASE_DEV = "2022.1.3"
const val RELEASE_EAP = "2022.1.3"
}

56
.teamcity/patches/buildTypes/Build.kts vendored Normal file
View File

@ -0,0 +1,56 @@
package patches.buildTypes
import jetbrains.buildServer.configs.kotlin.v2019_2.*
import jetbrains.buildServer.configs.kotlin.v2019_2.BuildType
import jetbrains.buildServer.configs.kotlin.v2019_2.buildFeatures.golang
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.script
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.schedule
import jetbrains.buildServer.configs.kotlin.v2019_2.ui.*
/*
This patch script was generated by TeamCity on settings change in UI.
To apply the patch, create a buildType with id = 'Build'
in the root project, and delete the patch script.
*/
create(DslContext.projectId, BuildType({
id("Build")
name = "IdeaVim compatibility with external plugins"
vcs {
root(DslContext.settingsRoot)
}
steps {
script {
name = "Check"
scriptContent = """
java -jar verifier/verifier-cli-dev-all.jar check-plugin '${'$'}org.jetbrains.IdeaVim-EasyMotion' [latest-IU] -team-city
java -jar verifier/verifier-cli-dev-all.jar check-plugin '${'$'}io.github.mishkun.ideavimsneak' [latest-IU] -team-city
java -jar verifier/verifier-cli-dev-all.jar check-plugin '${'$'}eu.theblob42.idea.whichkey' [latest-IU] -team-city
java -jar verifier/verifier-cli-dev-all.jar check-plugin '${'$'}IdeaVimExtension' [latest-IU] -team-city
# Outdated java -jar verifier/verifier-cli-dev-all.jar check-plugin '${'$'}github.zgqq.intellij-enhance' [latest-IU] -team-city
java -jar verifier/verifier-cli-dev-all.jar check-plugin '${'$'}com.github.copilot' [latest-IU] -team-city
java -jar verifier/verifier-cli-dev-all.jar check-plugin '${'$'}com.github.dankinsoid.multicursor' [latest-IU] -team-city
java -jar verifier/verifier-cli-dev-all.jar check-plugin '${'$'}com.joshestein.ideavim-quickscope' [latest-IU] -team-city
""".trimIndent()
}
}
triggers {
schedule {
schedulingPolicy = daily {
hour = 4
}
branchFilter = ""
triggerBuild = always()
withPendingChangesOnly = false
}
}
features {
golang {
testFormat = "json"
}
}
}))

View File

@ -16,17 +16,12 @@ changeBuildType(RelativeId("Qodana")) {
expectSteps {
qodana {
name = "Qodana"
reportAsTests = true
inspectionProfile = customProfile {
path = ".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", "")

74
.teamcity/patches/projects/_Self.kts vendored Normal file
View File

@ -0,0 +1,74 @@
package patches.projects
import jetbrains.buildServer.configs.kotlin.v2019_2.*
import jetbrains.buildServer.configs.kotlin.v2019_2.AmazonEC2CloudImage
import jetbrains.buildServer.configs.kotlin.v2019_2.AmazonEC2CloudProfile
import jetbrains.buildServer.configs.kotlin.v2019_2.Project
import jetbrains.buildServer.configs.kotlin.v2019_2.amazonEC2CloudImage
import jetbrains.buildServer.configs.kotlin.v2019_2.amazonEC2CloudProfile
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 root project
accordingly, and delete the patch script.
*/
changeProject(DslContext.projectId) {
features {
val feature1 = find<AmazonEC2CloudImage> {
amazonEC2CloudImage {
id = "PROJECT_EXT_768"
profileId = "amazon-48"
agentPoolId = "41"
name = "BuildAgentsIdeaVim"
vpcSubnetId = "subnet-58839511"
keyPairName = ""
instanceType = "c5d.xlarge"
securityGroups = listOf("sg-eda08696", "sg-7332cf0f")
useSpotInstances = true
instanceTags = mapOf(
"project" to "idea-vim"
)
source = Source("ami-0d1a6a32faa92923e")
param("image-instances-limit", "")
param("spot-instance-price", "")
}
}
feature1.apply {
profileId = "amazon-48"
agentPoolId = "41"
name = "BuildAgentsIdeaVim"
vpcSubnetId = "subnet-58839511"
keyPairName = ""
instanceType = "c5d.xlarge"
securityGroups = listOf("sg-eda08696", "sg-7332cf0f")
useSpotInstances = true
instanceTags = mapOf(
"project" to "idea-vim"
)
source = Source("ami-0fa17ce8238eb8868")
}
val feature2 = find<AmazonEC2CloudProfile> {
amazonEC2CloudProfile {
id = "amazon-48"
name = "Cloud Agents - Single Build"
terminateAfterBuild = true
terminateIdleMinutes = 15
region = AmazonEC2CloudProfile.Regions.EU_WEST_DUBLIN
maxInstancesCount = 10
authType = accessKey {
keyId = "credentialsJSON:dbcdb2a2-de5f-4bc9-9421-292b19e83947"
secretKey = "credentialsJSON:65a87fe7-0977-4af9-96f1-344f2b82d269"
}
param("agentPushPreset", "")
}
}
feature2.apply {
name = "Cloud Agents - Single Build"
terminateAfterBuild = true
terminateIdleMinutes = 15
region = AmazonEC2CloudProfile.Regions.EU_WEST_DUBLIN
maxInstancesCount = 10
}
}
}

View File

@ -0,0 +1,25 @@
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 = 'HttpsGithubComAlexPl292IdeaVimCompatibilityRefsHeadsMaster'
in the root project, and delete the patch script.
*/
create(DslContext.projectId, GitVcsRoot({
id("HttpsGithubComAlexPl292IdeaVimCompatibilityRefsHeadsMaster")
name = "https://github.com/AlexPl292/IdeaVimCompatibility#refs/heads/master"
url = "https://github.com/AlexPl292/IdeaVimCompatibility"
branch = "refs/heads/master"
branchSpec = "refs/heads/*"
authMethod = password {
userName = "AlexPl292"
password = "credentialsJSON:43afd6e5-6ad5-4d12-a218-cf1547717a7f"
}
param("oauthProviderId", "PROJECT_EXT_1")
param("useAlternates", "true")
}))

View File

@ -0,0 +1,23 @@
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 = 'IdeaVimCompatibility'
in the root project, and delete the patch script.
*/
create(DslContext.projectId, GitVcsRoot({
id("IdeaVimCompatibility")
name = "IdeaVimCompatibility"
url = "git@github.com:AlexPl292/IdeaVimCompatibility.git"
branch = "refs/heads/master"
authMethod = uploadedKey {
userName = "git"
uploadedKey = "Alex Plate TeamCity key"
}
param("useAlternates", "true")
}))

View File

@ -55,6 +55,8 @@ usual beta standards.
* [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
* [VIM-2227](https://youtrack.jetbrains.com/issue/VIM-2227) Wrong behavior when deleting / changing surround with invalid character
* [VIM-2691](https://youtrack.jetbrains.com/issue/VIM-2691) Save file on :w
### Merged PRs:
* [468](https://github.com/JetBrains/ideavim/pull/468) by [Thomas Schouten](https://github.com/PHPirates): Implement UserDataHolder for EditorDataContext
@ -63,6 +65,7 @@ usual beta standards.
* [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
* [519](https://github.com/JetBrains/ideavim/pull/519) by [chylex](https://github.com/chylex): Fix(VIM-2227): Wrong behavior when deleting / changing surround with invalid character
## 1.10.0, 2022-02-17

View File

@ -24,7 +24,7 @@ plugins {
java
kotlin("jvm") version "1.6.21"
id("org.jetbrains.intellij") version "1.6.0"
id("org.jetbrains.intellij") version "1.7.0-SNAPSHOT"
id("org.jetbrains.changelog") version "1.3.1"
// ktlint linter - read more: https://github.com/JLLeitschuh/ktlint-gradle
@ -70,7 +70,7 @@ dependencies {
runtimeOnly("org.antlr:antlr4-runtime:$antlrVersion")
antlr("org.antlr:antlr4:$antlrVersion")
implementation(project(":vim-engine"))
api(project(":vim-engine"))
}
configurations {
@ -145,6 +145,7 @@ tasks {
kotlinOptions {
jvmTarget = javaVersion
apiVersion = "1.5"
freeCompilerArgs = listOf("-Xjvm-default=all-compatibility")
// allWarningsAsErrors = true
}
}
@ -211,6 +212,25 @@ tasks {
named("compileKotlin") {
dependsOn("generateGrammarSource")
}
// Add plugin open API sources to the plugin ZIP
val createOpenApiSourceJar by registering(Jar::class) {
// Java sources
from(sourceSets.main.get().java) {
include("**/com/maddyhome/idea/vim/**/*.java")
}
// Kotlin sources
from(kotlin.sourceSets.main.get().kotlin) {
include("**/com/maddyhome/idea/vim/**/*.kt")
}
destinationDirectory.set(layout.buildDirectory.dir("libs"))
archiveClassifier.set("src")
}
buildPlugin {
dependsOn(createOpenApiSourceJar)
from(createOpenApiSourceJar) { into("lib/src") }
}
}
// --- Linting

View File

@ -1,6 +1,8 @@
version: 1.0
profile:
name: Qodana
include:
- name: CheckDependencyLicenses
exclude:
- name: MoveVariableDeclarationIntoWhen
- name: PluginXmlValidity
@ -9,12 +11,15 @@ exclude:
- name: UnusedReturnValue
- name: All
paths:
- build.gradle
- build.gradle.kts
- gradle/wrapper/gradle-wrapper.properties
- resources/icons/youtrack.svg
- src/com/maddyhome/idea/vim/ex/vimscript/VimScriptCommandHandler.java
- src/com/maddyhome/idea/vim/helper/SearchHelper.java
- src/com/maddyhome/idea/vim/regexp/RegExp.java
- test/org/jetbrains/plugins/ideavim/propertybased/samples/JavaText.kt
- test/org/jetbrains/plugins/ideavim/propertybased/samples/LoremText.kt
- test/org/jetbrains/plugins/ideavim/propertybased/samples/SimpleText.kt
- src/main/resources/icons/youtrack.svg
- src/main/java/com/maddyhome/idea/vim/helper/SearchHelper.java
- src/main/java/com/maddyhome/idea/vim/regexp/RegExp.kt
- src/test/java/org/jetbrains/plugins/ideavim/propertybased/samples/JavaText.kt
- src/test/java/org/jetbrains/plugins/ideavim/propertybased/samples/LoremText.kt
- src/test/java/org/jetbrains/plugins/ideavim/propertybased/samples/SimpleText.kt
- src/main/java/com/maddyhome/idea/vim/vimscript/parser/generated/VimscriptListener.java
- src/main/java/com/maddyhome/idea/vim/vimscript/parser/generated/VimscriptLexer.java
- src/main/java/com/maddyhome/idea/vim/vimscript/parser/generated/VimscriptParser.java
- src/main/java/com/maddyhome/idea/vim/vimscript/parser/generated/VimscriptVisitor.java

View File

@ -1,3 +1,13 @@
// Set repository for snapshot versions of gradle plugin
pluginManagement {
repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
gradlePluginPortal()
}
}
rootProject.name = 'IdeaVIM'
include 'vim-engine'

View File

@ -146,7 +146,7 @@ rShift: GREATER+;
letCommands:
(WS | COLON)* range? (WS | COLON)* LET WS+ expr WS*
assignmentOperator = (ASSIGN | PLUS_ASSIGN | MINUS_ASSIGN | STAR_ASSIGN | DIV_ASSIGN | MOD_ASSIGN | DOT_ASSIGN)
assignmentOperator
WS* expr WS* ((inline_comment NEW_LINE) | (NEW_LINE | BAR)+)
#Let1Command|
@ -154,6 +154,21 @@ letCommands:
#Let2Command
;
assignmentOperator:
ASSIGN | plusAssign | minusAssign | startAssign | divAssign | modAssign | dotAssign;
plusAssign:
PLUS ASSIGN;
minusAssign:
MINUS ASSIGN;
startAssign:
STAR ASSIGN;
divAssign:
DIV ASSIGN;
modAssign:
MOD ASSIGN;
dotAssign:
DOT ASSIGN;
shortRange:
((QUESTION (~QUESTION)* QUESTION?) | (DIV (~DIV)* DIV?));
range:
@ -778,12 +793,12 @@ IS_NOT_CS: 'isnot#';
// Assignment operators
ASSIGN: '=';
PLUS_ASSIGN: '+=';
MINUS_ASSIGN: '-=';
STAR_ASSIGN: '*=';
DIV_ASSIGN: '/=';
MOD_ASSIGN: '%=';
DOT_ASSIGN: '.=';
//PLUS_ASSIGN: '+=';
//MINUS_ASSIGN: '-=';
//STAR_ASSIGN: '*=';
//DIV_ASSIGN: '/=';
//MOD_ASSIGN: '%=';
//DOT_ASSIGN: '.=';
// Escaped chars
ESCAPED_QUESTION: '\\?';

View File

@ -48,13 +48,13 @@ 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.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 org.jdom.Element;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
@ -226,8 +226,8 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
return (PutGroup)VimInjectorKt.getInjector().getPut();
}
public static @NotNull VimVariableService getVariableService() {
return ApplicationManager.getApplication().getService(VimVariableService.class);
public static @NotNull VariableService getVariableService() {
return ApplicationManager.getApplication().getService(VariableService.class);
}
public static @NotNull OptionService getOptionService() {

View File

@ -34,8 +34,8 @@ 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.helper.vimStateMachine
import com.maddyhome.idea.vim.newapi.ij
import java.util.*
@ -61,7 +61,7 @@ class OperatorAction : VimActionHandler.SingleExecution() {
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
val argument = cmd.argument ?: return false
if (!editor.commandState.isDotRepeatInProgress) {
if (!editor.vimStateMachine.isDotRepeatInProgress) {
argumentCaptured = argument
}
val range = getMotionRange(editor, context, argument, operatorArguments)

View File

@ -25,14 +25,14 @@ 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.commandState
import com.maddyhome.idea.vim.helper.vimStateMachine
import com.maddyhome.idea.vim.newapi.ij
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 {
val state = editor.commandState
val state = editor.vimStateMachine
val lastCommand = VimRepeater.lastChangeCommand
if (lastCommand == null && Extension.lastExtensionHandler == null) return false

View File

@ -0,0 +1,96 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 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.command
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.helper.vimStateMachine
import com.maddyhome.idea.vim.newapi.vim
/**
* COMPATIBILITY-LAYER: Additional class
*/
class CommandState(private val machine: VimStateMachine) {
val isOperatorPending: Boolean
get() = machine.isOperatorPending
val mode: CommandState.Mode
get() = machine.mode.ij
val commandBuilder: CommandBuilder
get() = machine.commandBuilder
val mappingState: MappingState
get() = machine.mappingState
enum class Mode {
// Basic modes
COMMAND, VISUAL, SELECT, INSERT, CMD_LINE, /*EX*/
// Additional modes
OP_PENDING, REPLACE /*, VISUAL_REPLACE*/, INSERT_NORMAL, INSERT_VISUAL, INSERT_SELECT
}
enum class SubMode {
NONE, VISUAL_CHARACTER, VISUAL_LINE, VISUAL_BLOCK
}
companion object {
@JvmStatic
fun getInstance(editor: Editor): CommandState {
return CommandState(editor.vim.vimStateMachine)
}
}
}
val CommandState.SubMode.engine: VimStateMachine.SubMode
get() = when (this) {
CommandState.SubMode.NONE -> VimStateMachine.SubMode.NONE
CommandState.SubMode.VISUAL_CHARACTER -> VimStateMachine.SubMode.VISUAL_CHARACTER
CommandState.SubMode.VISUAL_LINE -> VimStateMachine.SubMode.VISUAL_LINE
CommandState.SubMode.VISUAL_BLOCK -> VimStateMachine.SubMode.VISUAL_BLOCK
}
val CommandState.Mode.engine: VimStateMachine.Mode
get() = when (this) {
CommandState.Mode.COMMAND -> VimStateMachine.Mode.COMMAND
CommandState.Mode.VISUAL -> VimStateMachine.Mode.VISUAL
CommandState.Mode.SELECT -> VimStateMachine.Mode.SELECT
CommandState.Mode.INSERT -> VimStateMachine.Mode.INSERT
CommandState.Mode.CMD_LINE -> VimStateMachine.Mode.CMD_LINE
CommandState.Mode.OP_PENDING -> VimStateMachine.Mode.OP_PENDING
CommandState.Mode.REPLACE -> VimStateMachine.Mode.REPLACE
CommandState.Mode.INSERT_NORMAL -> VimStateMachine.Mode.INSERT_NORMAL
CommandState.Mode.INSERT_VISUAL -> VimStateMachine.Mode.INSERT_VISUAL
CommandState.Mode.INSERT_SELECT -> VimStateMachine.Mode.INSERT_SELECT
}
val VimStateMachine.Mode.ij: CommandState.Mode
get() = when (this) {
VimStateMachine.Mode.COMMAND -> CommandState.Mode.COMMAND
VimStateMachine.Mode.VISUAL -> CommandState.Mode.VISUAL
VimStateMachine.Mode.SELECT -> CommandState.Mode.SELECT
VimStateMachine.Mode.INSERT -> CommandState.Mode.INSERT
VimStateMachine.Mode.CMD_LINE -> CommandState.Mode.CMD_LINE
VimStateMachine.Mode.OP_PENDING -> CommandState.Mode.OP_PENDING
VimStateMachine.Mode.REPLACE -> CommandState.Mode.REPLACE
VimStateMachine.Mode.INSERT_NORMAL -> CommandState.Mode.INSERT_NORMAL
VimStateMachine.Mode.INSERT_VISUAL -> CommandState.Mode.INSERT_VISUAL
VimStateMachine.Mode.INSERT_SELECT -> CommandState.Mode.INSERT_SELECT
}

View File

@ -23,14 +23,15 @@ import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.action.change.Extension
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.common.CommandAlias
import com.maddyhome.idea.vim.common.CommandAliasHandler
import com.maddyhome.idea.vim.common.MappingMode
import com.maddyhome.idea.vim.helper.CommandLineHelper
import com.maddyhome.idea.vim.helper.EditorDataContext
import com.maddyhome.idea.vim.helper.TestInputModel
import com.maddyhome.idea.vim.helper.commandState
import com.maddyhome.idea.vim.helper.vimStateMachine
import com.maddyhome.idea.vim.key.MappingOwner
import com.maddyhome.idea.vim.key.OperatorFunction
import com.maddyhome.idea.vim.newapi.vim
@ -48,6 +49,21 @@ import javax.swing.KeyStroke
object VimExtensionFacade {
/** The 'map' command for mapping keys to handlers defined in extensions. */
@JvmStatic
fun putExtensionHandlerMapping(
modes: Set<MappingMode>,
fromKeys: List<KeyStroke>,
pluginOwner: MappingOwner,
extensionHandler: ExtensionHandler,
recursive: Boolean,
) {
VimPlugin.getKey().putKeyMapping(modes, fromKeys, pluginOwner, extensionHandler, recursive)
}
/**
* COMPATIBILITY-LAYER: Additional method
*/
/** The 'map' command for mapping keys to handlers defined in extensions. */
@JvmStatic
fun putExtensionHandlerMapping(
modes: Set<MappingMode>,
fromKeys: List<KeyStroke>,
@ -129,7 +145,7 @@ object VimExtensionFacade {
/** Returns a single key stroke from the user input similar to 'getchar()'. */
@JvmStatic
fun inputKeyStroke(editor: Editor): KeyStroke {
if (editor.vim.commandState.isDotRepeatInProgress) {
if (editor.vim.vimStateMachine.isDotRepeatInProgress) {
val input = Extension.consumeKeystroke()
return input ?: error("Not enough keystrokes saved: ${Extension.lastExtensionHandler}")
}
@ -137,7 +153,7 @@ object VimExtensionFacade {
val key: KeyStroke? = if (ApplicationManager.getApplication().isUnitTestMode) {
val mappingStack = KeyHandler.getInstance().keyStack
mappingStack.feedSomeStroke() ?: TestInputModel.getInstance(editor).nextKeyStroke()?.also {
if (editor.vim.commandState.isRecording) {
if (editor.vim.vimStateMachine.isRecording) {
KeyHandler.getInstance().modalEntryKeys += it
}
}
@ -167,12 +183,24 @@ object VimExtensionFacade {
return reg.keys
}
@JvmStatic
fun getRegisterForCaret(register: Char, caret: VimCaret): List<KeyStroke>? {
val reg = caret.registerStorage.getRegister(register) ?: return null
return reg.keys
}
/** Set the current contents of the given register */
@JvmStatic
fun setRegister(register: Char, keys: List<KeyStroke?>?) {
VimPlugin.getRegister().setKeys(register, keys?.filterNotNull() ?: emptyList())
}
/** Set the current contents of the given register */
@JvmStatic
fun setRegisterForCaret(register: Char, caret: VimCaret, keys: List<KeyStroke?>?) {
caret.registerStorage.setKeys(register, keys?.filterNotNull() ?: emptyList())
}
/** Set the current contents of the given register */
@JvmStatic
fun setRegister(register: Char, keys: List<KeyStroke?>?, type: SelectionType) {

View File

@ -0,0 +1,38 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.maddyhome.idea.vim.extension
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.newapi.ij
/**
* COMPATIBILITY-LAYER: Created a class, renamed original class
*/
interface VimExtensionHandler : ExtensionHandler {
override fun execute(editor: VimEditor, context: ExecutionContext) {
execute(editor.ij, context.ij)
}
fun execute(editor: Editor, context: DataContext)
abstract class WithCallback : ExtensionHandler.WithCallback(), VimExtensionHandler
}

View File

@ -25,9 +25,9 @@ import com.maddyhome.idea.vim.api.VimExtensionRegistrator
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.ex.ExException
import com.maddyhome.idea.vim.key.MappingOwner.Plugin.Companion.remove
import com.maddyhome.idea.vim.option.ToggleOption
import com.maddyhome.idea.vim.options.OptionChangeListener
import com.maddyhome.idea.vim.options.OptionScope
import com.maddyhome.idea.vim.options.ToggleOption
import com.maddyhome.idea.vim.statistic.PluginState
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType

View File

@ -18,24 +18,21 @@
package com.maddyhome.idea.vim.extension.argtextobj;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.api.*;
import com.maddyhome.idea.vim.command.*;
import com.maddyhome.idea.vim.common.MappingMode;
import com.maddyhome.idea.vim.command.MappingMode;
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.extension.VimExtension;
import com.maddyhome.idea.vim.extension.VimExtensionHandler;
import com.maddyhome.idea.vim.extension.ExtensionHandler;
import com.maddyhome.idea.vim.handler.TextObjectActionHandler;
import com.maddyhome.idea.vim.helper.InlayHelperKt;
import com.maddyhome.idea.vim.helper.MessageHelper;
import com.maddyhome.idea.vim.helper.VimNlsSafe;
import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor;
import com.maddyhome.idea.vim.listener.VimListenerSuppressor;
import com.maddyhome.idea.vim.newapi.IjExecutionContext;
import com.maddyhome.idea.vim.newapi.IjVimCaret;
import com.maddyhome.idea.vim.newapi.IjVimEditor;
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString;
@ -186,7 +183,7 @@ public class VimArgTextObjExtension implements VimExtension {
/**
* A text object for an argument to a function definition or a call.
*/
static class ArgumentHandler implements VimExtensionHandler {
static class ArgumentHandler implements ExtensionHandler {
final boolean isInner;
ArgumentHandler(boolean isInner) {
@ -262,17 +259,17 @@ public class VimArgTextObjExtension implements VimExtension {
public void execute(@NotNull VimEditor editor, @NotNull ExecutionContext context) {
IjVimEditor vimEditor = (IjVimEditor) editor;
@NotNull CommandState commandState = CommandState.getInstance(vimEditor);
int count = Math.max(1, commandState.getCommandBuilder().getCount());
@NotNull VimStateMachine vimStateMachine = VimStateMachine.getInstance(vimEditor);
int count = Math.max(1, vimStateMachine.getCommandBuilder().getCount());
final ArgumentTextObjectHandler textObjectHandler = new ArgumentTextObjectHandler(isInner);
//noinspection DuplicatedCode
if (!commandState.isOperatorPending()) {
if (!vimStateMachine.isOperatorPending()) {
vimEditor.getEditor().getCaretModel().runForEachCaret((Caret caret) -> {
final TextRange range = textObjectHandler.getRange(vimEditor, new IjVimCaret(caret), context, count, 0, null);
if (range != null) {
try (VimListenerSuppressor.Locked ignored = SelectionVimListenerSuppressor.INSTANCE.lock()) {
if (commandState.getMode() == CommandState.Mode.VISUAL) {
if (vimStateMachine.getMode() == VimStateMachine.Mode.VISUAL) {
vimSetSelection(caret, range.getStartOffset(), range.getEndOffset() - 1, true);
} else {
InlayHelperKt.moveToInlayAwareOffset(caret, range.getStartOffset());
@ -282,8 +279,8 @@ public class VimArgTextObjExtension implements VimExtension {
});
} else {
commandState.getCommandBuilder().completeCommandPart(new Argument(new Command(count,
textObjectHandler, Command.Type.MOTION, EnumSet.noneOf(CommandFlags.class))));
vimStateMachine.getCommandBuilder().completeCommandPart(new Argument(new Command(count,
textObjectHandler, Command.Type.MOTION, EnumSet.noneOf(CommandFlags.class))));
}
}
}

View File

@ -34,13 +34,14 @@ import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.command.TextObjectVisualType
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.common.CommandAliasHandler
import com.maddyhome.idea.vim.common.MappingMode
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.ex.ranges.Ranges
import com.maddyhome.idea.vim.extension.ExtensionHandler
import com.maddyhome.idea.vim.extension.VimExtension
import com.maddyhome.idea.vim.extension.VimExtensionFacade.addCommand
import com.maddyhome.idea.vim.extension.VimExtensionFacade.executeNormalWithoutMapping
@ -48,11 +49,10 @@ import com.maddyhome.idea.vim.extension.VimExtensionFacade.putExtensionHandlerMa
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMapping
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMappingIfMissing
import com.maddyhome.idea.vim.extension.VimExtensionFacade.setOperatorFunction
import com.maddyhome.idea.vim.extension.VimExtensionHandler
import com.maddyhome.idea.vim.handler.TextObjectActionHandler
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.PsiHelper
import com.maddyhome.idea.vim.helper.commandState
import com.maddyhome.idea.vim.helper.vimStateMachine
import com.maddyhome.idea.vim.key.OperatorFunction
import com.maddyhome.idea.vim.newapi.IjVimEditor
import com.maddyhome.idea.vim.newapi.ij
@ -63,8 +63,8 @@ class CommentaryExtension : VimExtension {
companion object {
fun doCommentary(editor: VimEditor, context: ExecutionContext, range: TextRange, selectionType: SelectionType, resetCaret: Boolean): Boolean {
val mode = editor.commandState.mode
if (mode !== CommandState.Mode.VISUAL) {
val mode = editor.vimStateMachine.mode
if (mode !== VimStateMachine.Mode.VISUAL) {
editor.ij.selectionModel.setSelection(range.startOffset, range.endOffset)
}
@ -82,7 +82,7 @@ class CommentaryExtension : VimExtension {
injector.actionExecutor.executeAction(actions[1], context)
} finally {
// Remove the selection, if we added it
if (mode !== CommandState.Mode.VISUAL) {
if (mode !== VimStateMachine.Mode.VISUAL) {
editor.removeSelection()
}
@ -129,7 +129,7 @@ class CommentaryExtension : VimExtension {
* E.g. handles the `gc` in `gc_`, by setting the operator function, then invoking `g@` to receive the `_` motion to
* invoke the operator. This object is both the mapping handler and the operator function.
*/
private class CommentaryOperatorHandler : OperatorFunction, VimExtensionHandler {
private class CommentaryOperatorHandler : OperatorFunction, ExtensionHandler {
override val isRepeatable = true
override fun execute(editor: VimEditor, context: ExecutionContext) {
@ -148,11 +148,11 @@ class CommentaryExtension : VimExtension {
*
* This object is both the `<Plug>Commentary` mapping handler and the text object handler
*/
private class CommentaryTextObjectMotionHandler : TextObjectActionHandler(), VimExtensionHandler {
private class CommentaryTextObjectMotionHandler : TextObjectActionHandler(), ExtensionHandler {
override val isRepeatable = true
override fun execute(editor: VimEditor, context: ExecutionContext) {
val commandState = editor.commandState
val commandState = editor.vimStateMachine
val count = maxOf(1, commandState.commandBuilder.count)
val textObjectHandler = this

View File

@ -31,10 +31,11 @@ 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.CommandState
import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.common.MappingMode
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.extension.ExtensionHandler
import com.maddyhome.idea.vim.extension.VimExtension
import com.maddyhome.idea.vim.extension.VimExtensionFacade.executeNormalWithoutMapping
import com.maddyhome.idea.vim.extension.VimExtensionFacade.getRegister
@ -42,7 +43,6 @@ import com.maddyhome.idea.vim.extension.VimExtensionFacade.putExtensionHandlerMa
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMappingIfMissing
import com.maddyhome.idea.vim.extension.VimExtensionFacade.setOperatorFunction
import com.maddyhome.idea.vim.extension.VimExtensionFacade.setRegister
import com.maddyhome.idea.vim.extension.VimExtensionHandler
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.fileSize
import com.maddyhome.idea.vim.helper.moveToInlayAwareLogicalPosition
@ -95,7 +95,7 @@ class VimExchangeExtension : VimExtension {
val EXCHANGE_KEY = Key<Exchange>("exchange")
// End mark has always greater of eq offset than start mark
class Exchange(val type: CommandState.SubMode, val start: Mark, val end: Mark, val text: String) {
class Exchange(val type: VimStateMachine.SubMode, val start: Mark, val end: Mark, val text: String) {
private var myHighlighter: RangeHighlighter? = null
fun setHighlighter(highlighter: RangeHighlighter) {
myHighlighter = highlighter
@ -112,7 +112,7 @@ class VimExchangeExtension : VimExtension {
}
}
private class ExchangeHandler(private val isLine: Boolean) : VimExtensionHandler {
private class ExchangeHandler(private val isLine: Boolean) : ExtensionHandler {
override val isRepeatable = true
override fun execute(editor: VimEditor, context: ExecutionContext) {
@ -121,13 +121,13 @@ class VimExchangeExtension : VimExtension {
}
}
private class ExchangeClearHandler : VimExtensionHandler {
private class ExchangeClearHandler : ExtensionHandler {
override fun execute(editor: VimEditor, context: ExecutionContext) {
clearExchange(editor.ij)
}
}
private class VExchangeHandler : VimExtensionHandler {
private class VExchangeHandler : ExtensionHandler {
override fun execute(editor: VimEditor, context: ExecutionContext) {
runWriteAction {
val subMode = editor.subMode
@ -140,10 +140,10 @@ class VimExchangeExtension : VimExtension {
private class Operator(private val isVisual: Boolean) : OperatorFunction {
fun Editor.getMarkOffset(mark: Mark) = EditorHelper.getOffset(this, mark.logicalLine, mark.col)
fun CommandState.SubMode.getString() = when (this) {
CommandState.SubMode.VISUAL_CHARACTER -> "v"
CommandState.SubMode.VISUAL_LINE -> "V"
CommandState.SubMode.VISUAL_BLOCK -> "\\<C-V>"
fun VimStateMachine.SubMode.getString() = when (this) {
VimStateMachine.SubMode.VISUAL_CHARACTER -> "v"
VimStateMachine.SubMode.VISUAL_LINE -> "V"
VimStateMachine.SubMode.VISUAL_BLOCK -> "\\<C-V>"
else -> error("Invalid SubMode: $this")
}
@ -151,7 +151,7 @@ class VimExchangeExtension : VimExtension {
fun highlightExchange(ex: Exchange): RangeHighlighter {
val attributes = editor.colorsScheme.getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES)
val hlArea = when (ex.type) {
CommandState.SubMode.VISUAL_LINE -> HighlighterTargetArea.LINES_IN_RANGE
VimStateMachine.SubMode.VISUAL_LINE -> HighlighterTargetArea.LINES_IN_RANGE
// TODO: handle other modes
else -> HighlighterTargetArea.EXACT_RANGE
}
@ -274,7 +274,7 @@ class VimExchangeExtension : VimExtension {
x.logicalLine - y.logicalLine
}
return if (x.type == CommandState.SubMode.VISUAL_BLOCK && y.type == CommandState.SubMode.VISUAL_BLOCK) {
return if (x.type == VimStateMachine.SubMode.VISUAL_BLOCK && y.type == VimStateMachine.SubMode.VISUAL_BLOCK) {
when {
intersects(x, y) -> {
ExchangeCompareResult.OVERLAP

View File

@ -33,21 +33,21 @@ import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.command.MotionType
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.common.Direction
import com.maddyhome.idea.vim.common.MappingMode
import com.maddyhome.idea.vim.extension.ExtensionHandler
import com.maddyhome.idea.vim.extension.VimExtension
import com.maddyhome.idea.vim.extension.VimExtensionFacade
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMappingIfMissing
import com.maddyhome.idea.vim.extension.VimExtensionHandler
import com.maddyhome.idea.vim.handler.Motion
import com.maddyhome.idea.vim.handler.MotionActionHandler
import com.maddyhome.idea.vim.handler.toMotionOrError
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.PsiHelper
import com.maddyhome.idea.vim.helper.commandState
import com.maddyhome.idea.vim.helper.enumSetOf
import com.maddyhome.idea.vim.helper.vimStateMachine
import com.maddyhome.idea.vim.newapi.ij
import com.maddyhome.idea.vim.newapi.vim
import java.util.*
@ -94,14 +94,14 @@ class Matchit : VimExtension {
override var motionType: MotionType = MotionType.INCLUSIVE
}
private class MatchitHandler(private val reverse: Boolean) : VimExtensionHandler {
private class MatchitHandler(private val reverse: Boolean) : ExtensionHandler {
override fun execute(editor: VimEditor, context: ExecutionContext) {
val commandState = editor.commandState
val commandState = editor.vimStateMachine
val count = commandState.commandBuilder.count
// Reset the command count so it doesn't transfer onto subsequent commands.
editor.commandState.commandBuilder.resetCount()
editor.vimStateMachine.commandBuilder.resetCount()
// Normally we want to jump to the start of the matching pair. But when moving forward in operator
// pending mode, we want to include the entire match. isInOpPending makes that distinction.

View File

@ -29,13 +29,13 @@ 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.CommandState
import com.maddyhome.idea.vim.common.MappingMode
import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.extension.ExtensionHandler
import com.maddyhome.idea.vim.extension.VimExtension
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putExtensionHandlerMapping
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMappingIfMissing
import com.maddyhome.idea.vim.extension.VimExtensionHandler
import com.maddyhome.idea.vim.group.MotionGroup
import com.maddyhome.idea.vim.group.visual.vimSetSelection
import com.maddyhome.idea.vim.helper.EditorHelper
@ -111,7 +111,7 @@ class VimMultipleCursorsExtension : VimExtension {
putKeyMappingIfMissing(MappingMode.X, injector.parser.parseKeys("<A-p>"), owner, injector.parser.parseKeys(REMOVE_OCCURRENCE), true)
}
abstract class WriteActionHandler : VimExtensionHandler {
abstract class WriteActionHandler : ExtensionHandler {
override fun execute(editor: VimEditor, context: ExecutionContext) {
ApplicationManager.getApplication().runWriteAction {
executeInWriteAction(editor.ij, context.ij)
@ -313,7 +313,7 @@ class VimMultipleCursorsExtension : VimExtension {
private fun enterVisualMode(editor: VimEditor) {
// We need to reset the key handler to make sure we pick up the fact that we're in visual mode
VimPlugin.getVisualMotion().enterVisualMode(editor, CommandState.SubMode.VISUAL_CHARACTER)
VimPlugin.getVisualMotion().enterVisualMode(editor, VimStateMachine.SubMode.VISUAL_CHARACTER)
KeyHandler.getInstance().reset(editor)
}

View File

@ -44,11 +44,11 @@ import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.common.CommandAlias
import com.maddyhome.idea.vim.common.CommandAliasHandler
import com.maddyhome.idea.vim.common.CommandNode
import com.maddyhome.idea.vim.common.CommandPartNode
import com.maddyhome.idea.vim.common.Node
import com.maddyhome.idea.vim.common.RootNode
import com.maddyhome.idea.vim.common.addLeafs
import com.maddyhome.idea.vim.key.CommandNode
import com.maddyhome.idea.vim.key.CommandPartNode
import com.maddyhome.idea.vim.key.Node
import com.maddyhome.idea.vim.key.RootNode
import com.maddyhome.idea.vim.key.addLeafs
import com.maddyhome.idea.vim.ex.ranges.Ranges
import com.maddyhome.idea.vim.extension.VimExtension
import com.maddyhome.idea.vim.group.KeyGroup

View File

@ -23,11 +23,11 @@ import com.intellij.openapi.editor.Editor
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.common.MappingMode
import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.extension.ExtensionHandler
import com.maddyhome.idea.vim.extension.VimExtension
import com.maddyhome.idea.vim.extension.VimExtensionFacade
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMappingIfMissing
import com.maddyhome.idea.vim.extension.VimExtensionHandler
import com.maddyhome.idea.vim.group.MotionGroup
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.SearchHelper
@ -45,7 +45,7 @@ class ParagraphMotion : VimExtension {
putKeyMappingIfMissing(MappingMode.NXO, injector.parser.parseKeys("{"), owner, injector.parser.parseKeys("<Plug>(ParagraphPrevMotion)"), true)
}
private class ParagraphMotionHandler(private val count: Int) : VimExtensionHandler {
private class ParagraphMotionHandler(private val count: Int) : ExtensionHandler {
override fun execute(editor: VimEditor, context: ExecutionContext) {
editor.ij.vimForEachCaret { caret ->
val motion = moveCaretToNextParagraph(editor.ij, caret, count)

View File

@ -25,17 +25,17 @@ 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.CommandState
import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.command.isLine
import com.maddyhome.idea.vim.common.MappingMode
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.extension.ExtensionHandler
import com.maddyhome.idea.vim.extension.VimExtension
import com.maddyhome.idea.vim.extension.VimExtensionFacade
import com.maddyhome.idea.vim.extension.VimExtensionFacade.executeNormalWithoutMapping
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMappingIfMissing
import com.maddyhome.idea.vim.extension.VimExtensionFacade.setOperatorFunction
import com.maddyhome.idea.vim.extension.VimExtensionHandler
import com.maddyhome.idea.vim.group.visual.VimSelection
import com.maddyhome.idea.vim.helper.EditorDataContext
import com.maddyhome.idea.vim.helper.mode
@ -63,22 +63,21 @@ class ReplaceWithRegister : VimExtension {
putKeyMappingIfMissing(MappingMode.X, injector.parser.parseKeys("gr"), owner, injector.parser.parseKeys(RWR_VISUAL), true)
}
private class RwrVisual : VimExtensionHandler {
private class RwrVisual : ExtensionHandler {
override fun execute(editor: VimEditor, context: ExecutionContext) {
val caretsAndSelections = mutableMapOf<VimCaret, VimSelection>()
val typeInEditor = SelectionType.fromSubMode(editor.subMode)
editor.forEachCaret { caret ->
val selectionStart = caret.selectionStart
val selectionEnd = caret.selectionEnd
caretsAndSelections += caret to VimSelection.create(selectionStart, selectionEnd - 1, typeInEditor, editor)
val visualSelection = caret to VimSelection.create(selectionStart, selectionEnd - 1, typeInEditor, editor)
doReplace(editor.ij, caret, PutData.VisualSelection(mapOf(visualSelection), typeInEditor))
}
doReplace(editor.ij, PutData.VisualSelection(caretsAndSelections, typeInEditor))
editor.exitVisualModeNative()
}
}
private class RwrMotion : VimExtensionHandler {
private class RwrMotion : ExtensionHandler {
override val isRepeatable: Boolean = true
override fun execute(editor: VimEditor, context: ExecutionContext) {
@ -87,7 +86,7 @@ class ReplaceWithRegister : VimExtension {
}
}
private class RwrLine : VimExtensionHandler {
private class RwrLine : ExtensionHandler {
override val isRepeatable: Boolean = true
override fun execute(editor: VimEditor, context: ExecutionContext) {
@ -97,11 +96,11 @@ class ReplaceWithRegister : VimExtension {
val lineStart = editor.getLineStartOffset(logicalLine)
val lineEnd = editor.getLineEndOffset(logicalLine, true)
caretsAndSelections += caret to VimSelection.create(lineStart, lineEnd, SelectionType.LINE_WISE, editor)
}
val visualSelection = caret to VimSelection.create(lineStart, lineEnd, SelectionType.LINE_WISE, editor)
caretsAndSelections += visualSelection
val visualSelection = PutData.VisualSelection(caretsAndSelections, SelectionType.LINE_WISE)
doReplace(editor.ij, visualSelection)
doReplace(editor.ij, caret, PutData.VisualSelection(mapOf(visualSelection), SelectionType.LINE_WISE))
}
editor.forEachCaret { caret ->
val vimStart = caretsAndSelections[caret]?.vimStart
@ -126,13 +125,14 @@ class ReplaceWithRegister : VimExtension {
),
selectionType
)
doReplace(editor, visualSelection)
// todo multicaret
doReplace(editor, editor.vim.primaryCaret(), visualSelection)
return true
}
private fun getRange(editor: Editor): TextRange? = when (editor.vim.mode) {
CommandState.Mode.COMMAND -> VimPlugin.getMark().getChangeMarks(editor.vim)
CommandState.Mode.VISUAL -> editor.caretModel.primaryCaret.run { TextRange(selectionStart, selectionEnd) }
VimStateMachine.Mode.COMMAND -> VimPlugin.getMark().getChangeMarks(editor.vim)
VimStateMachine.Mode.VISUAL -> editor.caretModel.primaryCaret.run { TextRange(selectionStart, selectionEnd) }
else -> null
}
}
@ -147,8 +147,9 @@ class ReplaceWithRegister : VimExtension {
@NonNls
private const val RWR_VISUAL = "<Plug>ReplaceWithRegisterVisual"
private fun doReplace(editor: Editor, visualSelection: PutData.VisualSelection) {
val savedRegister = VimPlugin.getRegister().lastRegister ?: return
private fun doReplace(editor: Editor, caret: VimCaret, visualSelection: PutData.VisualSelection) {
val lastRegisterChar = injector.registerGroup.lastRegisterChar
val savedRegister = caret.registerStorage.getRegister(lastRegisterChar) ?: return
var usedType = savedRegister.type
var usedText = savedRegister.text
@ -173,8 +174,8 @@ class ReplaceWithRegister : VimExtension {
VimPlugin.getPut().putText(IjVimEditor(editor), IjExecutionContext(EditorDataContext.init(editor)), putData)
}
VimPlugin.getRegister().saveRegister(savedRegister.name, savedRegister)
VimPlugin.getRegister().saveRegister(VimPlugin.getRegister().defaultRegister, savedRegister)
caret.registerStorage.saveRegister(savedRegister.name, savedRegister)
caret.registerStorage.saveRegister(VimPlugin.getRegister().defaultRegister, savedRegister)
}
}
}

View File

@ -22,30 +22,31 @@ import com.intellij.openapi.application.runWriteAction
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.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.common.MappingMode
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.extension.ExtensionHandler
import com.maddyhome.idea.vim.extension.VimExtension
import com.maddyhome.idea.vim.extension.VimExtensionFacade.executeNormalWithoutMapping
import com.maddyhome.idea.vim.extension.VimExtensionFacade.getRegister
import com.maddyhome.idea.vim.extension.VimExtensionFacade.getRegisterForCaret
import com.maddyhome.idea.vim.extension.VimExtensionFacade.inputKeyStroke
import com.maddyhome.idea.vim.extension.VimExtensionFacade.inputString
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putExtensionHandlerMapping
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMappingIfMissing
import com.maddyhome.idea.vim.extension.VimExtensionFacade.setOperatorFunction
import com.maddyhome.idea.vim.extension.VimExtensionFacade.setRegister
import com.maddyhome.idea.vim.extension.VimExtensionHandler
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.mode
import com.maddyhome.idea.vim.extension.VimExtensionFacade.setRegisterForCaret
import com.maddyhome.idea.vim.helper.editorMode
import com.maddyhome.idea.vim.key.OperatorFunction
import com.maddyhome.idea.vim.newapi.IjVimCaret
import com.maddyhome.idea.vim.newapi.IjVimEditor
import com.maddyhome.idea.vim.newapi.ij
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.options.helpers.ClipboardOptionHelper
import com.maddyhome.idea.vim.put.PutData
import org.jetbrains.annotations.NonNls
import java.awt.event.KeyEvent
import javax.swing.KeyStroke
@ -80,7 +81,7 @@ class VimSurroundExtension : VimExtension {
}
}
private class YSurroundHandler : VimExtensionHandler {
private class YSurroundHandler : ExtensionHandler {
override val isRepeatable = true
override fun execute(editor: VimEditor, context: ExecutionContext) {
@ -89,7 +90,7 @@ class VimSurroundExtension : VimExtension {
}
}
private class VSurroundHandler : VimExtensionHandler {
private class VSurroundHandler : ExtensionHandler {
override fun execute(editor: VimEditor, context: ExecutionContext) {
val selectionStart = editor.ij.caretModel.primaryCaret.selectionStart
// NB: Operator ignores SelectionType anyway
@ -104,7 +105,7 @@ class VimSurroundExtension : VimExtension {
}
}
private class CSurroundHandler : VimExtensionHandler {
private class CSurroundHandler : ExtensionHandler {
override val isRepeatable = true
override fun execute(editor: VimEditor, context: ExecutionContext) {
@ -115,28 +116,70 @@ class VimSurroundExtension : VimExtension {
if (charTo.code == 0) return
val newSurround = getOrInputPair(charTo, editor.ij) ?: return
runWriteAction { change(editor.ij, charFrom, newSurround) }
runWriteAction { change(editor, context, charFrom, newSurround) }
}
companion object {
fun change(editor: Editor, charFrom: Char, newSurround: Pair<String, String>?) {
// We take over the " register, so preserve it
val oldValue: List<KeyStroke>? = getRegister(REGISTER)
// Extract the inner value
perform("di" + pick(charFrom), editor)
val innerValue: MutableList<KeyStroke> = getRegister(REGISTER)?.toMutableList() ?: mutableListOf()
// Delete the surrounding
perform("da" + pick(charFrom), editor)
// Insert the surrounding characters and paste
if (newSurround != null) {
innerValue.addAll(0, injector.parser.parseKeys(newSurround.first))
innerValue.addAll(injector.parser.parseKeys(newSurround.second))
fun change(editor: VimEditor, context: ExecutionContext, charFrom: Char, newSurround: Pair<String, String>?) {
// Save old register values for carets
val surroundings = editor.sortedCarets()
.map {
val oldValue: List<KeyStroke>? = getRegisterForCaret(REGISTER, it)
setRegisterForCaret(REGISTER, it, null)
SurroundingInfo(it, null, oldValue, null)
}
// Delete surrounding's content
perform("di" + pick(charFrom), editor.ij)
// Add info about surrounding's inner text and location
surroundings.forEach {
val registerValue = getRegisterForCaret(REGISTER, it.caret)
val innerValue = if (registerValue.isNullOrEmpty()) null else registerValue
it.innerText = innerValue
val lineEndOffset = injector.engineEditorHelper.getLineEndOffset(editor, it.caret.getLine().line, false)
if (lineEndOffset == it.caret.offset.point) {
it.isLineEnd = true
}
}
// Remove surrounding
perform("da" + pick(charFrom), editor.ij)
surroundings.forEach {
if (it.innerText == null && getRegisterForCaret(REGISTER, it.caret)?.isNotEmpty() == true) {
it.innerText = emptyList()
}
// caret should be placed at the first char of inserted text
// the best solution would be using [ mark after the paste, but marks are not supported by multicaret
// todo
if (it.innerText != null) {
it.offset = it.caret.offset.point
}
}
surroundings
.filter { it.innerText != null } // we do nothing with carets that are not inside the surrounding
.map { surrounding ->
val innerValue = injector.parser.toPrintableString(surrounding.innerText!!)
val text = newSurround?.let { it.first + innerValue + it.second } ?: innerValue
val textData = PutData.TextData(text, SelectionType.CHARACTER_WISE, emptyList())
val putData = PutData(textData, null, 1, insertTextBeforeCaret = !surrounding.isLineEnd, rawIndent = true, caretAfterInsertedText = false)
surrounding.caret to putData
}.forEach {
injector.put.putTextForCaret(editor, it.first, context, it.second)
}
surroundings.forEach {
it.restoreRegister()
}
if (surroundings.size == 1) {
surroundings.first().moveCaret()
}
pasteSurround(innerValue, editor)
// Restore the old value
setRegister(REGISTER, oldValue)
// Jump back to start
executeNormalWithoutMapping(injector.parser.parseKeys("`["), editor)
}
private fun perform(sequence: String, editor: Editor) {
@ -144,21 +187,6 @@ class VimSurroundExtension : VimExtension {
.use { executeNormalWithoutMapping(injector.parser.parseKeys("\"" + REGISTER + sequence), editor) }
}
private fun pasteSurround(
innerValue: List<KeyStroke?>,
editor: Editor,
) { // This logic is direct from vim-surround
val offset = editor.caretModel.offset
val lineEndOffset = EditorHelper.getLineEndForOffset(editor, offset)
val motionEndMark = VimPlugin.getMark().getMark(editor.vim, ']')
val motionEndOffset = if (motionEndMark != null) {
EditorHelper.getOffset(editor, motionEndMark.logicalLine, motionEndMark.col)
} else -1
val pasteCommand = if (motionEndOffset == lineEndOffset && offset + 1 == lineEndOffset) "p" else "P"
setRegister(REGISTER, innerValue)
perform(pasteCommand, editor)
}
private fun pick(charFrom: Char) = when (charFrom) {
'a' -> '>'
'r' -> ']'
@ -167,7 +195,19 @@ class VimSurroundExtension : VimExtension {
}
}
private class DSurroundHandler : VimExtensionHandler {
private data class SurroundingInfo(val caret: VimCaret, var innerText: List<KeyStroke>?, val oldRegisterContent: List<KeyStroke>?, var offset: Int?, var isLineEnd: Boolean = false) {
fun restoreRegister() {
setRegisterForCaret(REGISTER, caret, oldRegisterContent)
}
fun moveCaret() {
if (innerText != null && offset != null) {
caret.moveToOffset(offset!! + if (isLineEnd) 1 else 0)
}
}
}
private class DSurroundHandler : ExtensionHandler {
override val isRepeatable = true
override fun execute(editor: VimEditor, context: ExecutionContext) {
@ -175,7 +215,7 @@ class VimSurroundExtension : VimExtension {
val charFrom = getChar(editor.ij)
if (charFrom.code == 0) return
runWriteAction { CSurroundHandler.change(editor.ij, charFrom, null) }
runWriteAction { CSurroundHandler.change(editor, context, charFrom, null) }
}
}
@ -199,9 +239,9 @@ class VimSurroundExtension : VimExtension {
return true
}
private fun getSurroundRange(editor: Editor): TextRange? = when (editor.mode) {
CommandState.Mode.COMMAND -> VimPlugin.getMark().getChangeMarks(editor.vim)
CommandState.Mode.VISUAL -> editor.caretModel.primaryCaret.run { TextRange(selectionStart, selectionEnd) }
private fun getSurroundRange(editor: Editor): TextRange? = when (editor.editorMode) {
VimStateMachine.Mode.COMMAND -> VimPlugin.getMark().getChangeMarks(editor.vim)
VimStateMachine.Mode.VISUAL -> editor.caretModel.primaryCaret.run { TextRange(selectionStart, selectionEnd) }
else -> null
}
}

View File

@ -18,26 +18,22 @@
package com.maddyhome.idea.vim.extension.textobjentire;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Editor;
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.VimInjectorKt;
import com.maddyhome.idea.vim.command.*;
import com.maddyhome.idea.vim.common.MappingMode;
import com.maddyhome.idea.vim.command.MappingMode;
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.extension.VimExtension;
import com.maddyhome.idea.vim.extension.VimExtensionHandler;
import com.maddyhome.idea.vim.extension.ExtensionHandler;
import com.maddyhome.idea.vim.handler.TextObjectActionHandler;
import com.maddyhome.idea.vim.helper.InlayHelperKt;
import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor;
import com.maddyhome.idea.vim.listener.VimListenerSuppressor;
import com.maddyhome.idea.vim.newapi.IjExecutionContext;
import com.maddyhome.idea.vim.newapi.IjVimCaret;
import com.maddyhome.idea.vim.newapi.IjVimEditor;
import org.apache.tools.ant.taskdefs.Exec;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -88,7 +84,7 @@ public class VimTextObjEntireExtension implements VimExtension {
putKeyMappingIfMissing(MappingMode.XO, VimInjectorKt.getInjector().getParser().parseKeys("ie"), getOwner(), VimInjectorKt.getInjector().getParser().parseKeys("<Plug>textobj-entire-i"), true);
}
static class EntireHandler implements VimExtensionHandler {
static class EntireHandler implements ExtensionHandler {
final boolean ignoreLeadingAndTrailing;
EntireHandler(boolean ignoreLeadingAndTrailing) {
@ -148,17 +144,17 @@ public class VimTextObjEntireExtension implements VimExtension {
@Override
public void execute(@NotNull VimEditor editor, @NotNull ExecutionContext context) {
@NotNull CommandState commandState = CommandState.getInstance(editor);
int count = Math.max(1, commandState.getCommandBuilder().getCount());
@NotNull VimStateMachine vimStateMachine = VimStateMachine.getInstance(editor);
int count = Math.max(1, vimStateMachine.getCommandBuilder().getCount());
final EntireTextObjectHandler textObjectHandler = new EntireTextObjectHandler(ignoreLeadingAndTrailing);
//noinspection DuplicatedCode
if (!commandState.isOperatorPending()) {
if (!vimStateMachine.isOperatorPending()) {
((IjVimEditor) editor).getEditor().getCaretModel().runForEachCaret((Caret caret) -> {
final TextRange range = textObjectHandler.getRange(editor, new IjVimCaret(caret), context, count, 0, null);
if (range != null) {
try (VimListenerSuppressor.Locked ignored = SelectionVimListenerSuppressor.INSTANCE.lock()) {
if (commandState.getMode() == CommandState.Mode.VISUAL) {
if (vimStateMachine.getMode() == VimStateMachine.Mode.VISUAL) {
vimSetSelection(caret, range.getStartOffset(), range.getEndOffset() - 1, true);
} else {
InlayHelperKt.moveToInlayAwareOffset(caret, range.getStartOffset());
@ -168,9 +164,9 @@ public class VimTextObjEntireExtension implements VimExtension {
});
} else {
commandState.getCommandBuilder().completeCommandPart(new Argument(new Command(count,
textObjectHandler, Command.Type.MOTION,
EnumSet.noneOf(CommandFlags.class))));
vimStateMachine.getCommandBuilder().completeCommandPart(new Argument(new Command(count,
textObjectHandler, Command.Type.MOTION,
EnumSet.noneOf(CommandFlags.class))));
}
}
}

View File

@ -18,23 +18,20 @@
package com.maddyhome.idea.vim.extension.textobjindent;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Editor;
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.VimInjectorKt;
import com.maddyhome.idea.vim.command.*;
import com.maddyhome.idea.vim.common.MappingMode;
import com.maddyhome.idea.vim.command.MappingMode;
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.extension.VimExtension;
import com.maddyhome.idea.vim.extension.VimExtensionHandler;
import com.maddyhome.idea.vim.extension.ExtensionHandler;
import com.maddyhome.idea.vim.handler.TextObjectActionHandler;
import com.maddyhome.idea.vim.helper.InlayHelperKt;
import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor;
import com.maddyhome.idea.vim.listener.VimListenerSuppressor;
import com.maddyhome.idea.vim.newapi.IjExecutionContext;
import com.maddyhome.idea.vim.newapi.IjVimCaret;
import com.maddyhome.idea.vim.newapi.IjVimEditor;
import org.jetbrains.annotations.NotNull;
@ -86,7 +83,7 @@ public class VimIndentObject implements VimExtension {
putKeyMapping(MappingMode.XO, VimInjectorKt.getInjector().getParser().parseKeys("ii"), getOwner(), VimInjectorKt.getInjector().getParser().parseKeys("<Plug>textobj-indent-ii"), true);
}
static class IndentObject implements VimExtensionHandler {
static class IndentObject implements ExtensionHandler {
final boolean includeAbove;
final boolean includeBelow;
@ -275,17 +272,17 @@ public class VimIndentObject implements VimExtension {
@Override
public void execute(@NotNull VimEditor editor, @NotNull ExecutionContext context) {
IjVimEditor vimEditor = (IjVimEditor)editor;
@NotNull CommandState commandState = CommandState.getInstance(vimEditor);
int count = Math.max(1, commandState.getCommandBuilder().getCount());
@NotNull VimStateMachine vimStateMachine = VimStateMachine.getInstance(vimEditor);
int count = Math.max(1, vimStateMachine.getCommandBuilder().getCount());
final IndentObjectHandler textObjectHandler = new IndentObjectHandler(includeAbove, includeBelow);
if (!commandState.isOperatorPending()) {
if (!vimStateMachine.isOperatorPending()) {
((IjVimEditor)editor).getEditor().getCaretModel().runForEachCaret((Caret caret) -> {
final TextRange range = textObjectHandler.getRange(vimEditor, new IjVimCaret(caret), context, count, 0, null);
if (range != null) {
try (VimListenerSuppressor.Locked ignored = SelectionVimListenerSuppressor.INSTANCE.lock()) {
if (commandState.getMode() == CommandState.Mode.VISUAL) {
if (vimStateMachine.getMode() == VimStateMachine.Mode.VISUAL) {
vimSetSelection(caret, range.getStartOffset(), range.getEndOffset() - 1, true);
} else {
InlayHelperKt.moveToInlayAwareOffset(caret, range.getStartOffset());
@ -295,9 +292,9 @@ public class VimIndentObject implements VimExtension {
});
} else {
commandState.getCommandBuilder().completeCommandPart(new Argument(new Command(count,
textObjectHandler, Command.Type.MOTION,
EnumSet.noneOf(CommandFlags.class))));
vimStateMachine.getCommandBuilder().completeCommandPart(new Argument(new Command(count,
textObjectHandler, Command.Type.MOTION,
EnumSet.noneOf(CommandFlags.class))));
}
}
}

View File

@ -39,7 +39,6 @@ import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.util.containers.ContainerUtil;
import com.maddyhome.idea.vim.EventFacade;
import com.maddyhome.idea.vim.RegisterActions;
import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.api.*;
import com.maddyhome.idea.vim.command.*;
@ -107,7 +106,7 @@ public class ChangeGroup extends VimChangeGroupBase {
injector.getMotion().moveCaret(editor, caret, VimPlugin.getMotion().moveCaretToLineEnd(editor, caret));
}
UserDataManager.setVimChangeActionSwitchMode(((IjVimEditor) editor).getEditor(), CommandState.Mode.INSERT);
UserDataManager.setVimChangeActionSwitchMode(((IjVimEditor) editor).getEditor(), VimStateMachine.Mode.INSERT);
insertText(editor, caret, "\n" + IndentConfig.create(((IjVimEditor) editor).getEditor()).createIndentBySize(col));
if (firstLiner) {
@ -123,10 +122,10 @@ public class ChangeGroup extends VimChangeGroupBase {
* @param col The column to indent to
*/
private void insertNewLineBelow(@NotNull VimEditor editor, @NotNull VimCaret caret, int col) {
if (((IjVimEditor) editor).getEditor().isOneLineMode()) return;
if (editor.isOneLineMode()) return;
injector.getMotion().moveCaret(editor, caret, VimPlugin.getMotion().moveCaretToLineEnd(editor, caret));
UserDataManager.setVimChangeActionSwitchMode(((IjVimEditor) editor).getEditor(), CommandState.Mode.INSERT);
caret.moveToOffset(injector.getMotion().moveCaretToLineEnd(editor, caret));
editor.setVimChangeActionSwitchMode(VimStateMachine.Mode.INSERT);
insertText(editor, caret, "\n" + IndentConfig.create(((IjVimEditor) editor).getEditor()).createIndentBySize(col));
}
@ -165,41 +164,6 @@ public class ChangeGroup extends VimChangeGroupBase {
}
@Override
public @Nullable Pair<@NotNull TextRange, @NotNull SelectionType> getDeleteRangeAndType(@NotNull VimEditor editor,
@NotNull VimCaret caret,
@NotNull ExecutionContext context,
final @NotNull Argument argument,
boolean isChange,
@NotNull OperatorArguments operatorArguments) {
final TextRange range =
injector.getMotion().getMotionRange(editor, caret, context, argument, operatorArguments);
if (range == null) return null;
// Delete motion commands that are not linewise become linewise if all the following are true:
// 1) The range is across multiple lines
// 2) There is only whitespace before the start of the range
// 3) There is only whitespace after the end of the range
SelectionType type;
if (argument.getMotion().isLinewiseMotion()) {
type = SelectionType.LINE_WISE;
}
else {
type = SelectionType.CHARACTER_WISE;
}
final Command motion = argument.getMotion();
if (!isChange && !motion.isLinewiseMotion()) {
VimLogicalPosition start = editor.offsetToLogicalPosition(range.getStartOffset());
VimLogicalPosition end = editor.offsetToLogicalPosition(range.getEndOffset());
if (start.getLine() != end.getLine()) {
if (!SearchHelper.anyNonWhitespace(((IjVimEditor) editor).getEditor(), range.getStartOffset(), -1) &&
!SearchHelper.anyNonWhitespace(((IjVimEditor) editor).getEditor(), range.getEndOffset(), 1)) {
type = SelectionType.LINE_WISE;
}
}
}
return new Pair<>(range, type);
}
@Override
public @Nullable Pair<@NotNull TextRange, @NotNull SelectionType> getDeleteRangeAndType2(@NotNull VimEditor editor,
@ -236,60 +200,6 @@ public class ChangeGroup extends VimChangeGroupBase {
return new Pair<>(range, type);
}
/**
* Delete the range of text.
*
* @param editor The editor to delete the text from
* @param caret The caret to be moved after deletion
* @param range The range to delete
* @param type The type of deletion
* @param isChange Is from a change action
* @return true if able to delete the text, false if not
*/
@Override
public boolean deleteRange(@NotNull VimEditor editor,
@NotNull VimCaret caret,
@NotNull TextRange range,
@Nullable SelectionType type,
boolean isChange) {
// Update the last column before we delete, or we might be retrieving the data for a line that no longer exists
UserDataManager.setVimLastColumn(((IjVimCaret) caret).getCaret(), InlayHelperKt.getInlayAwareVisualColumn(((IjVimCaret) caret).getCaret()));
boolean removeLastNewLine = removeLastNewLine(editor, range, type);
final boolean res = deleteText(editor, range, type);
if (removeLastNewLine) {
int textLength = ((IjVimEditor) editor).getEditor().getDocument().getTextLength();
((IjVimEditor) editor).getEditor().getDocument().deleteString(textLength - 1, textLength);
}
if (res) {
int pos = EditorHelper.normalizeOffset(((IjVimEditor) editor).getEditor(), range.getStartOffset(), isChange);
if (type == SelectionType.LINE_WISE) {
pos = VimPlugin.getMotion()
.moveCaretToLineWithStartOfLineOption(editor, editor.offsetToLogicalPosition(pos).getLine(),
caret);
}
injector.getMotion().moveCaret(editor, caret, pos);
}
return res;
}
private boolean removeLastNewLine(@NotNull VimEditor editor, @NotNull TextRange range, @Nullable SelectionType type) {
int endOffset = range.getEndOffset();
int fileSize = EditorHelperRt.getFileSize(((IjVimEditor) editor).getEditor());
if (endOffset > fileSize) {
if (injector.getOptionService().isSet(OptionScope.GLOBAL.INSTANCE, OptionConstants.ideastrictmodeName, OptionConstants.ideastrictmodeName)) {
throw new IllegalStateException("Incorrect offset. File size: " + fileSize + ", offset: " + endOffset);
}
endOffset = fileSize;
}
return type == SelectionType.LINE_WISE &&
range.getStartOffset() != 0 &&
((IjVimEditor) editor).getEditor().getDocument().getCharsSequence().charAt(endOffset - 1) != '\n' &&
endOffset == fileSize;
}
@Override
public void insertLineAround(@NotNull VimEditor editor, @NotNull ExecutionContext context, int shift) {
com.maddyhome.idea.vim.newapi.ChangeGroupKt.insertLineAround(editor, context, shift);
@ -303,48 +213,6 @@ public class ChangeGroup extends VimChangeGroupBase {
return com.maddyhome.idea.vim.newapi.ChangeGroupKt.deleteRange(editor, caret, range, type);
}
/**
* Delete count characters and then enter insert mode
*
* @param editor The editor to change
* @param caret The caret to be moved
* @param count The number of characters to change
* @return true if able to delete count characters, false if not
*/
@Override
public boolean changeCharacters(@NotNull VimEditor editor, @NotNull VimCaret caret, int count) {
int len = EditorHelper.getLineLength(((IjVimEditor) editor).getEditor());
int col = ((IjVimCaret) caret).getCaret().getLogicalPosition().column;
if (col + count >= len) {
return changeEndOfLine(editor, caret, 1);
}
boolean res = deleteCharacter(editor, caret, count, true);
if (res) {
UserDataManager.setVimChangeActionSwitchMode(((IjVimEditor) editor).getEditor(), CommandState.Mode.INSERT);
}
return res;
}
/**
* Delete from the cursor to the end of count - 1 lines down and enter insert mode
*
* @param editor The editor to change
* @param caret The caret to perform action on
* @param count The number of lines to change
* @return true if able to delete count lines, false if not
*/
@Override
public boolean changeEndOfLine(@NotNull VimEditor editor, @NotNull VimCaret caret, int count) {
boolean res = deleteEndOfLine(editor, caret, count);
if (res) {
injector.getMotion().moveCaret(editor, caret, VimPlugin.getMotion().moveCaretToLineEnd(editor, caret));
UserDataManager.setVimChangeActionSwitchMode(((IjVimEditor) editor).getEditor(), CommandState.Mode.INSERT);
}
return res;
}
/**
* Delete the text covered by the motion command argument and enter insert mode
@ -368,9 +236,9 @@ public class ChangeGroup extends VimChangeGroupBase {
String id = motion.getAction().getId();
boolean kludge = false;
boolean bigWord = id.equals(VIM_MOTION_BIG_WORD_RIGHT);
final CharSequence chars = ((IjVimEditor) editor).getEditor().getDocument().getCharsSequence();
final int offset = ((IjVimCaret) caret).getCaret().getOffset();
int fileSize = EditorHelperRt.getFileSize(((IjVimEditor) editor).getEditor());
final CharSequence chars = editor.text();
final int offset = caret.getOffset().getPoint();
int fileSize = ((int)editor.fileSize());
if (fileSize > 0 && offset < fileSize) {
final CharacterHelper.CharacterType charType = CharacterHelper.charType(chars.charAt(offset), bigWord);
if (charType != CharacterHelper.CharacterType.WHITESPACE) {
@ -379,24 +247,24 @@ public class ChangeGroup extends VimChangeGroupBase {
if (wordMotions.contains(id) && lastWordChar && motion.getCount() == 1) {
final boolean res = deleteCharacter(editor, caret, 1, true);
if (res) {
UserDataManager.setVimChangeActionSwitchMode(((IjVimEditor) editor).getEditor(), CommandState.Mode.INSERT);
editor.setVimChangeActionSwitchMode(VimStateMachine.Mode.INSERT);
}
return res;
}
switch (id) {
case VIM_MOTION_WORD_RIGHT:
kludge = true;
motion.setAction(RegisterActions.findActionOrDie(VIM_MOTION_WORD_END_RIGHT));
motion.setAction(injector.getActionExecutor().findVimActionOrDie(VIM_MOTION_WORD_END_RIGHT));
break;
case VIM_MOTION_BIG_WORD_RIGHT:
kludge = true;
motion.setAction(RegisterActions.findActionOrDie(VIM_MOTION_BIG_WORD_END_RIGHT));
motion.setAction(injector.getActionExecutor().findVimActionOrDie(VIM_MOTION_BIG_WORD_END_RIGHT));
break;
case VIM_MOTION_CAMEL_RIGHT:
kludge = true;
motion.setAction(RegisterActions.findActionOrDie(VIM_MOTION_CAMEL_END_RIGHT));
motion.setAction(injector.getActionExecutor().findVimActionOrDie(VIM_MOTION_CAMEL_END_RIGHT));
break;
}
@ -405,8 +273,8 @@ public class ChangeGroup extends VimChangeGroupBase {
if (kludge) {
int cnt = operatorArguments.getCount1() * motion.getCount();
int pos1 = SearchHelper.findNextWordEnd(chars, offset, fileSize, cnt, bigWord, false);
int pos2 = SearchHelper.findNextWordEnd(chars, pos1, fileSize, -cnt, bigWord, false);
int pos1 = injector.getSearchHelper().findNextWordEnd(chars, offset, fileSize, cnt, bigWord, false);
int pos2 = injector.getSearchHelper().findNextWordEnd(chars, pos1, fileSize, -cnt, bigWord, false);
if (logger.isDebugEnabled()) {
logger.debug("pos=" + offset);
logger.debug("pos1=" + pos1);
@ -427,11 +295,11 @@ public class ChangeGroup extends VimChangeGroupBase {
}
}
if (VimPlugin.getOptionService().isSet(OptionScope.GLOBAL.INSTANCE, OptionConstants.experimentalapiName, OptionConstants.experimentalapiName)) {
if (injector.getOptionService().isSet(OptionScope.GLOBAL.INSTANCE, OptionConstants.experimentalapiName, OptionConstants.experimentalapiName)) {
Pair<TextRange, SelectionType> deleteRangeAndType =
getDeleteRangeAndType2(editor, caret, context, argument, true, operatorArguments.withCount0(count0));
if (deleteRangeAndType == null) return false;
ChangeGroupKt.changeRange(((IjVimEditor) editor).getEditor(), ((IjVimCaret) caret).getCaret(), deleteRangeAndType.getFirst(), deleteRangeAndType.getSecond(), ((IjExecutionContext) context).getContext());
//ChangeGroupKt.changeRange(((IjVimEditor) editor).getEditor(), ((IjVimCaret) caret).getCaret(), deleteRangeAndType.getFirst(), deleteRangeAndType.getSecond(), ((IjExecutionContext) context).getContext());
return true;
}
else {
@ -442,23 +310,6 @@ public class ChangeGroup extends VimChangeGroupBase {
}
}
/**
* Counts number of lines in the visual block.
* <p>
* The result includes empty and short lines which does not have explicit start position (caret).
*
* @param editor The editor the block was selected in
* @param range The range corresponding to the selected block
* @return total number of lines
*/
public static int getLinesCountInVisualBlock(@NotNull VimEditor editor, @NotNull TextRange range) {
final int[] startOffsets = range.getStartOffsets();
if (startOffsets.length == 0) return 0;
final VimLogicalPosition firstStart = editor.offsetToLogicalPosition(startOffsets[0]);
final VimLogicalPosition lastStart = editor.offsetToLogicalPosition(startOffsets[range.size() - 1]);
return lastStart.getLine() - firstStart.getLine() + 1;
}
/**
* Toggles the case of count characters
*
@ -484,11 +335,11 @@ public class ChangeGroup extends VimChangeGroupBase {
@NotNull TextRange range,
boolean append,
@NotNull OperatorArguments operatorArguments) {
final int lines = getLinesCountInVisualBlock(editor, range);
final int lines = VimChangeGroupBase.Companion.getLinesCountInVisualBlock(editor, range);
final VimLogicalPosition startPosition = editor.offsetToLogicalPosition(range.getStartOffset());
boolean visualBlockMode = operatorArguments.getMode() == CommandState.Mode.VISUAL &&
operatorArguments.getSubMode() == CommandState.SubMode.VISUAL_BLOCK;
boolean visualBlockMode = operatorArguments.getMode() == VimStateMachine.Mode.VISUAL &&
operatorArguments.getSubMode() == VimStateMachine.SubMode.VISUAL_BLOCK;
for (Caret caret : ((IjVimEditor) editor).getEditor().getCaretModel().getAllCarets()) {
final int line = startPosition.getLine();
int column = startPosition.getColumn();
@ -589,24 +440,24 @@ public class ChangeGroup extends VimChangeGroupBase {
int col = 0;
int lines = 0;
if (type == SelectionType.BLOCK_WISE) {
lines = getLinesCountInVisualBlock(editor, range);
lines = VimChangeGroupBase.Companion.getLinesCountInVisualBlock(editor, range);
col = editor.offsetToLogicalPosition(range.getStartOffset()).getColumn();
if (UserDataManager.getVimLastColumn(((IjVimCaret) caret).getCaret()) == VimMotionGroupBase.LAST_COLUMN) {
if (caret.getVimLastColumn() == VimMotionGroupBase.LAST_COLUMN) {
col = VimMotionGroupBase.LAST_COLUMN;
}
}
boolean after = range.getEndOffset() >= EditorHelperRt.getFileSize(((IjVimEditor) editor).getEditor());
boolean after = range.getEndOffset() >= editor.fileSize();
final VimLogicalPosition lp = editor.offsetToLogicalPosition(VimPlugin.getMotion().moveCaretToLineStartSkipLeading(editor, caret));
final VimLogicalPosition lp = editor.offsetToLogicalPosition(injector.getMotion().moveCaretToLineStartSkipLeading(editor, caret));
boolean res = deleteRange(editor, caret, range, type, true);
if (res) {
if (type == SelectionType.LINE_WISE) {
// Please don't use `getDocument().getText().isEmpty()` because it converts CharSequence into String
if (((IjVimEditor) editor).getEditor().getDocument().getTextLength() == 0) {
if (editor.fileSize() == 0) {
insertBeforeCursor(editor, context);
}
else if (after && !EditorHelperRt.endsWithNewLine(((IjVimEditor) editor).getEditor())) {
else if (after && !EngineEditorHelperKt.endsWithNewLine(editor)) {
insertNewLineBelow(editor, caret, lp.getColumn());
}
else {
@ -617,7 +468,7 @@ public class ChangeGroup extends VimChangeGroupBase {
if (type == SelectionType.BLOCK_WISE) {
setInsertRepeat(lines, col, false);
}
UserDataManager.setVimChangeActionSwitchMode(((IjVimEditor) editor).getEditor(), CommandState.Mode.INSERT);
UserDataManager.setVimChangeActionSwitchMode(((IjVimEditor) editor).getEditor(), VimStateMachine.Mode.INSERT);
}
}
else {
@ -824,7 +675,7 @@ public class ChangeGroup extends VimChangeGroupBase {
}
}
if (pos > wsoff) {
deleteText(editor, new TextRange(wsoff, pos), null);
deleteText(editor, new TextRange(wsoff, pos), null, caret);
}
}
}

View File

@ -38,8 +38,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileVisitor;
import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.api.*;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.common.GoalCommand;
import com.maddyhome.idea.vim.command.VimStateMachine;
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.helper.EditorHelper;
import com.maddyhome.idea.vim.helper.EditorHelperRt;
@ -48,7 +47,6 @@ import com.maddyhome.idea.vim.helper.SearchHelper;
import com.maddyhome.idea.vim.newapi.ExecuteExtensionKt;
import com.maddyhome.idea.vim.newapi.IjExecutionContext;
import com.maddyhome.idea.vim.newapi.IjVimEditor;
import com.maddyhome.idea.vim.options.OptionConstants;
import com.maddyhome.idea.vim.options.OptionScope;
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString;
import com.maddyhome.idea.vim.vimscript.services.IjVimOptionService;
@ -290,7 +288,7 @@ public class FileGroup extends VimFileBase {
StringBuilder msg = new StringBuilder();
Document doc = editor.getDocument();
if (CommandState.getInstance(new IjVimEditor(editor)).getMode() != CommandState.Mode.VISUAL) {
if (VimStateMachine.getInstance(new IjVimEditor(editor)).getMode() != VimStateMachine.Mode.VISUAL) {
LogicalPosition lp = editor.getCaretModel().getLogicalPosition();
int col = editor.getCaretModel().getOffset() - doc.getLineStartOffset(lp.line);
int endoff = doc.getLineEndOffset(lp.line);

View File

@ -37,9 +37,8 @@ import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.action.ComplicatedKeysAction;
import com.maddyhome.idea.vim.action.VimShortcutKeyAction;
import com.maddyhome.idea.vim.api.*;
import com.maddyhome.idea.vim.common.MappingMode;
import com.maddyhome.idea.vim.common.Node;
import com.maddyhome.idea.vim.common.NodesKt;
import com.maddyhome.idea.vim.command.MappingMode;
import com.maddyhome.idea.vim.key.Node;
import com.maddyhome.idea.vim.ex.ExOutputModel;
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase;
import com.maddyhome.idea.vim.helper.HelperKt;

View File

@ -44,7 +44,6 @@ import com.maddyhome.idea.vim.helper.EditorHelper;
import com.maddyhome.idea.vim.helper.HelperKt;
import com.maddyhome.idea.vim.mark.*;
import com.maddyhome.idea.vim.newapi.IjVimEditor;
import com.maddyhome.idea.vim.options.OptionConstants;
import com.maddyhome.idea.vim.options.OptionScope;
import com.maddyhome.idea.vim.vimscript.services.IjVimOptionService;
import org.jdom.Element;
@ -60,8 +59,7 @@ import static com.maddyhome.idea.vim.mark.VimMarkConstants.SAVE_FILE_MARKS;
* This class contains all the mark related functionality
*/
@State(name = "VimMarksSettings", storages = {
@Storage(value = "$APP_CONFIG$/vim_settings_local.xml", roamingType = RoamingType.DISABLED)
})
@Storage(value = "$APP_CONFIG$/vim_settings_local.xml", roamingType = RoamingType.DISABLED)})
public class MarkGroup extends VimMarkGroupBase implements PersistentStateComponent<Element> {
public void editorReleased(@NotNull EditorFactoryEvent event) {
// Save off the last caret position of the file before it is closed
@ -92,7 +90,7 @@ public class MarkGroup extends VimMarkGroupBase implements PersistentStateCompon
*
* @param doc The editor to get the marks for
* @return The map of marks. The keys are <code>Character</code>s of the mark names, the values are
* <code>Mark</code>s.
* <code>Mark</code>s.
*/
private @Nullable FileMarks<Character, Mark> getFileMarks(final @NotNull Document doc) {
VirtualFile vf = FileDocumentManager.getInstance().getFile(doc);
@ -127,7 +125,8 @@ public class MarkGroup extends VimMarkGroupBase implements PersistentStateCompon
public void saveData(@NotNull Element element) {
Element marksElem = new Element("globalmarks");
if (!VimPlugin.getOptionService().isSet(OptionScope.GLOBAL.INSTANCE, IjVimOptionService.ideamarksName, IjVimOptionService.ideamarksName)) {
if (!VimPlugin.getOptionService()
.isSet(OptionScope.GLOBAL.INSTANCE, IjVimOptionService.ideamarksName, IjVimOptionService.ideamarksName)) {
for (Mark mark : globalMarks.values()) {
if (!mark.isClear()) {
Element markElem = new Element("mark");
@ -165,8 +164,7 @@ public class MarkGroup extends VimMarkGroupBase implements PersistentStateCompon
fileMarkElem.setAttribute("name", file);
fileMarkElem.setAttribute("timestamp", Long.toString(marks.getMyTimestamp().getTime()));
for (Mark mark : marks.values()) {
if (!mark.isClear() && !Character.isUpperCase(mark.getKey()) &&
SAVE_FILE_MARKS.indexOf(mark.getKey()) >= 0) {
if (!mark.isClear() && !Character.isUpperCase(mark.getKey()) && SAVE_FILE_MARKS.indexOf(mark.getKey()) >= 0) {
Element markElem = new Element("mark");
markElem.setAttribute("key", Character.toString(mark.getKey()));
markElem.setAttribute("line", Integer.toString(mark.getLogicalLine()));
@ -200,14 +198,15 @@ public class MarkGroup extends VimMarkGroupBase implements PersistentStateCompon
// (see com.intellij.openapi.application.Application.runReadAction())
Element marksElem = element.getChild("globalmarks");
if (marksElem != null && !VimPlugin.getOptionService().isSet(OptionScope.GLOBAL.INSTANCE, IjVimOptionService.ideamarksName, IjVimOptionService.ideamarksName)) {
if (marksElem != null &&
!VimPlugin.getOptionService()
.isSet(OptionScope.GLOBAL.INSTANCE, IjVimOptionService.ideamarksName, IjVimOptionService.ideamarksName)) {
List<Element> markList = marksElem.getChildren("mark");
for (Element aMarkList : markList) {
Mark mark = VimMark.create(aMarkList.getAttributeValue("key").charAt(0),
Integer.parseInt(aMarkList.getAttributeValue("line")),
Integer.parseInt(aMarkList.getAttributeValue("column")),
aMarkList.getAttributeValue("filename"),
aMarkList.getAttributeValue("protocol"));
aMarkList.getAttributeValue("filename"), aMarkList.getAttributeValue("protocol"));
if (mark != null) {
globalMarks.put(mark.getKey(), mark);
@ -239,8 +238,7 @@ public class MarkGroup extends VimMarkGroupBase implements PersistentStateCompon
for (Element aMarkList : markList) {
Mark mark = VimMark.create(aMarkList.getAttributeValue("key").charAt(0),
Integer.parseInt(aMarkList.getAttributeValue("line")),
Integer.parseInt(aMarkList.getAttributeValue("column")),
filename,
Integer.parseInt(aMarkList.getAttributeValue("column")), filename,
aMarkList.getAttributeValue("protocol"));
if (mark != null) fmarks.put(mark.getKey(), mark);
@ -290,6 +288,7 @@ public class MarkGroup extends VimMarkGroupBase implements PersistentStateCompon
public static class MarkUpdater implements DocumentListener {
public static MarkUpdater INSTANCE = new MarkUpdater();
/**
* Creates the listener for the supplied editor
*/
@ -313,8 +312,7 @@ public class MarkGroup extends VimMarkGroupBase implements PersistentStateCompon
Editor anEditor = getAnEditor(doc);
VimInjectorKt.getInjector().getMarkGroup()
.updateMarkFromDelete(anEditor == null ? null : new IjVimEditor(anEditor),
VimPlugin.getMark().getAllFileMarks(doc),
event.getOffset(), event.getOldLength());
VimPlugin.getMark().getAllFileMarks(doc), event.getOffset(), event.getOldLength());
// TODO - update jumps
}
@ -361,7 +359,10 @@ public class MarkGroup extends VimMarkGroupBase implements PersistentStateCompon
@Override
public void bookmarkAdded(@NotNull BookmarkGroup group, com.intellij.ide.bookmark.@NotNull Bookmark bookmark) {
if (!VimPlugin.isEnabled()) return;
if (!VimPlugin.getOptionService().isSet(OptionScope.GLOBAL.INSTANCE, IjVimOptionService.ideamarksName, IjVimOptionService.ideamarksName)) return;
if (!VimPlugin.getOptionService()
.isSet(OptionScope.GLOBAL.INSTANCE, IjVimOptionService.ideamarksName, IjVimOptionService.ideamarksName)) {
return;
}
if (!(bookmark instanceof LineBookmark)) return;
BookmarksManager bookmarksManager = BookmarksManager.getInstance(myProject);
@ -378,7 +379,10 @@ public class MarkGroup extends VimMarkGroupBase implements PersistentStateCompon
@Override
public void bookmarkRemoved(@NotNull BookmarkGroup group, com.intellij.ide.bookmark.@NotNull Bookmark bookmark) {
if (!VimPlugin.isEnabled()) return;
if (!VimPlugin.getOptionService().isSet(OptionScope.GLOBAL.INSTANCE, IjVimOptionService.ideamarksName, IjVimOptionService.ideamarksName)) return;
if (!VimPlugin.getOptionService()
.isSet(OptionScope.GLOBAL.INSTANCE, IjVimOptionService.ideamarksName, IjVimOptionService.ideamarksName)) {
return;
}
if (!(bookmark instanceof LineBookmark)) return;
BookmarksManager bookmarksManager = BookmarksManager.getInstance(myProject);
@ -387,7 +391,8 @@ public class MarkGroup extends VimMarkGroupBase implements PersistentStateCompon
if (type == null) return;
char ch = type.getMnemonic();
if (GLOBAL_MARKS.indexOf(ch) != -1) {
FileMarks<Character, Mark> fmarks = VimPlugin.getMark().getFileMarks(((LineBookmark)bookmark).getFile().getPath());
FileMarks<Character, Mark> fmarks =
VimPlugin.getMark().getFileMarks(((LineBookmark)bookmark).getFile().getPath());
fmarks.remove(ch);
VimPlugin.getMark().globalMarks.remove(ch);
}
@ -404,6 +409,16 @@ public class MarkGroup extends VimMarkGroupBase implements PersistentStateCompon
}
}
/**
* COMPATIBILITY-LAYER: Method added
*
* @deprecated Please use method with VimEditor
*/
@Deprecated
public void saveJumpLocation(Editor editor) {
this.saveJumpLocation(new IjVimEditor(editor));
}
private static final int SAVE_MARK_COUNT = 20;
private static final Logger logger = Logger.getInstance(MarkGroup.class.getName());

View File

@ -711,7 +711,7 @@ public class MotionGroup extends VimMotionGroupBase {
}
private static int getScrollJump(@NotNull Editor editor, int height) {
final EnumSet<CommandFlags> flags = CommandState.getInstance(new IjVimEditor(editor)).getExecutingCommandFlags();
final EnumSet<CommandFlags> flags = VimStateMachine.getInstance(new IjVimEditor(editor)).getExecutingCommandFlags();
final boolean scrollJump = !flags.contains(CommandFlags.FLAG_IGNORE_SCROLL_JUMP);
// Default value is 1. Zero is a valid value, but we normalise to 1 - we always want to scroll at least one line
@ -736,7 +736,7 @@ public class MotionGroup extends VimMotionGroupBase {
final int halfWidth = getApproximateScreenWidth(editor) / 2;
final int scrollOffset = getNormalizedSideScrollOffset(editor);
final EnumSet<CommandFlags> flags = CommandState.getInstance(new IjVimEditor(editor)).getExecutingCommandFlags();
final EnumSet<CommandFlags> flags = VimStateMachine.getInstance(new IjVimEditor(editor)).getExecutingCommandFlags();
final boolean allowSidescroll = !flags.contains(CommandFlags.FLAG_IGNORE_SIDE_SCROLL_JUMP);
int sidescroll = ((VimInt) VimPlugin.getOptionService().getOptionValue(new OptionScope.LOCAL(new IjVimEditor(editor)), OptionConstants.sidescrollName, OptionConstants.sidescrollName)).getValue();
@ -1200,7 +1200,7 @@ public class MotionGroup extends VimMotionGroupBase {
if (fileEditor instanceof TextEditor) {
final Editor editor = ((TextEditor)fileEditor).getEditor();
ExOutputModel.getInstance(editor).clear();
if (CommandState.getInstance(new IjVimEditor(editor)).getMode() == CommandState.Mode.VISUAL) {
if (VimStateMachine.getInstance(new IjVimEditor(editor)).getMode() == VimStateMachine.Mode.VISUAL) {
ModeHelper.exitVisualMode(editor);
KeyHandler.getInstance().reset(new IjVimEditor(editor));
}

View File

@ -37,7 +37,7 @@ import com.maddyhome.idea.vim.KeyHandler;
import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.api.*;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.command.VimStateMachine;
import com.maddyhome.idea.vim.ex.ExException;
import com.maddyhome.idea.vim.ex.InvalidCommandException;
import com.maddyhome.idea.vim.helper.UiHelper;
@ -90,7 +90,7 @@ public class ProcessGroup extends VimProcessGroupBase {
if (editor.isOneLineMode()) return;
String initText = getRange(((IjVimEditor) editor).getEditor(), cmd);
CommandState.getInstance(editor).pushModes(CommandState.Mode.CMD_LINE, CommandState.SubMode.NONE);
VimStateMachine.getInstance(editor).pushModes(VimStateMachine.Mode.CMD_LINE, VimStateMachine.SubMode.NONE);
ExEntryPanel panel = ExEntryPanel.getInstance();
panel.activate(((IjVimEditor) editor).getEditor(), ((IjExecutionContext) context).getContext(), ":", initText, 1);
}
@ -108,7 +108,7 @@ public class ProcessGroup extends VimProcessGroupBase {
return true;
}
else {
CommandState.getInstance(editor).popModes();
VimStateMachine.getInstance(editor).popModes();
KeyHandler.getInstance().reset(editor);
return false;
}
@ -119,7 +119,7 @@ public class ProcessGroup extends VimProcessGroupBase {
panel.deactivate(true);
boolean res = true;
try {
CommandState.getInstance(editor).popModes();
VimStateMachine.getInstance(editor).popModes();
logger.debug("processing command");
@ -152,11 +152,11 @@ public class ProcessGroup extends VimProcessGroupBase {
// commands executed from map command / macro should not be added to history
private boolean skipHistory(VimEditor editor) {
return CommandState.getInstance(editor).getMappingState().isExecutingMap() || injector.getMacro().isExecutingMacro();
return VimStateMachine.getInstance(editor).getMappingState().isExecutingMap() || injector.getMacro().isExecutingMacro();
}
public void cancelExEntry(final @NotNull VimEditor editor, boolean resetCaret) {
CommandState.getInstance(editor).popModes();
VimStateMachine.getInstance(editor).popModes();
KeyHandler.getInstance().reset(editor);
ExEntryPanel panel = ExEntryPanel.getInstance();
panel.deactivate(true, resetCaret);
@ -165,14 +165,14 @@ public class ProcessGroup extends VimProcessGroupBase {
@Override
public void startFilterCommand(@NotNull VimEditor editor, ExecutionContext context, @NotNull Command cmd) {
String initText = getRange(((IjVimEditor) editor).getEditor(), cmd) + "!";
CommandState.getInstance(editor).pushModes(CommandState.Mode.CMD_LINE, CommandState.SubMode.NONE);
VimStateMachine.getInstance(editor).pushModes(VimStateMachine.Mode.CMD_LINE, VimStateMachine.SubMode.NONE);
ExEntryPanel panel = ExEntryPanel.getInstance();
panel.activate(((IjVimEditor) editor).getEditor(), ((IjExecutionContext) context).getContext(), ":", initText, 1);
}
private @NotNull String getRange(Editor editor, @NotNull Command cmd) {
String initText = "";
if (CommandState.getInstance(new IjVimEditor(editor)).getMode() == CommandState.Mode.VISUAL) {
if (VimStateMachine.getInstance(new IjVimEditor(editor)).getMode() == VimStateMachine.Mode.VISUAL) {
initText = "'<,'>";
}
else if (cmd.getRawCount() > 0) {

View File

@ -890,6 +890,10 @@ public class SearchGroup extends VimSearchGroupBase implements PersistentStateCo
@Override
public void setLastSearchPattern(@Nullable String lastSearchPattern) {
this.lastSearch = lastSearchPattern;
if (showSearchHighlight) {
resetIncsearchHighlights();
updateSearchHighlights();
}
}
@Override

View File

@ -34,8 +34,8 @@ 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.CommandState
import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.command.isBlock
import com.maddyhome.idea.vim.command.isChar
import com.maddyhome.idea.vim.command.isLine
@ -60,10 +60,14 @@ import java.awt.datatransfer.DataFlavor
import kotlin.math.min
class PutGroup : VimPutBase() {
override fun putTextForCaret(editor: VimEditor, caret: VimCaret, context: ExecutionContext, data: PutData): Boolean {
override fun putTextForCaret(editor: VimEditor, caret: VimCaret, context: ExecutionContext, data: PutData, updateVisualMarks: Boolean): Boolean {
val additionalData = collectPreModificationData(editor, data)
data.visualSelection?.let { deleteSelectedText(editor, data) }
val processedText = processText(editor, data) ?: return false
putForCaret(editor, caret, data, additionalData, context, processedText)
if (editor.primaryCaret() == caret && updateVisualMarks) {
wrapInsertedTextWithVisualMarks(editor, data, processedText)
}
return true
}
@ -75,7 +79,7 @@ class PutGroup : VimPutBase() {
additionalData: Map<String, Any>,
) {
val visualSelection = data.visualSelection
val subMode = visualSelection?.typeInEditor?.toSubMode() ?: CommandState.SubMode.NONE
val subMode = visualSelection?.typeInEditor?.toSubMode() ?: VimStateMachine.SubMode.NONE
if (OptionConstants.clipboard_ideaput in (
injector.optionService
.getOptionValue(OptionScope.GLOBAL, OptionConstants.clipboardName) as VimString
@ -113,12 +117,14 @@ class PutGroup : VimPutBase() {
val startOffsets = prepareDocumentAndGetStartOffsets(editor, caret, text.typeInRegister, data, additionalData)
startOffsets.forEach { startOffset ->
val subMode = data.visualSelection?.typeInEditor?.toSubMode() ?: CommandState.SubMode.NONE
val subMode = data.visualSelection?.typeInEditor?.toSubMode() ?: VimStateMachine.SubMode.NONE
val endOffset = putTextInternal(
editor, caret, context, text.text, text.typeInRegister, subMode,
startOffset, data.count, data.indent, data.caretAfterInsertedText
)
VimPlugin.getMark().setChangeMarks(editor, TextRange(startOffset, endOffset))
if (caret == editor.primaryCaret()) {
VimPlugin.getMark().setChangeMarks(editor, TextRange(startOffset, endOffset))
}
moveCaretToEndPosition(
editor,
caret,
@ -233,7 +239,7 @@ class PutGroup : VimPutBase() {
vimEditor: VimEditor,
vimContext: ExecutionContext,
text: ProcessedTextData,
subMode: CommandState.SubMode,
subMode: VimStateMachine.SubMode,
data: PutData,
additionalData: Map<String, Any>,
) {

View File

@ -18,18 +18,16 @@
package com.maddyhome.idea.vim.group.copy
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.intellij.util.containers.ContainerUtil
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.OperatorArguments
import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.group.MotionGroup
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.fileSize
import com.maddyhome.idea.vim.listener.VimYankListener
@ -46,8 +44,8 @@ class YankGroup : YankGroupBase() {
fun removeListener(listener: VimYankListener) = yankListeners.remove(listener)
private fun notifyListeners(editor: Editor, textRange: TextRange) = yankListeners.forEach {
it.yankPerformed(editor, textRange)
private fun notifyListeners(editor: VimEditor, textRange: TextRange) = yankListeners.forEach {
it.yankPerformed(editor.ij, textRange)
}
/**
@ -67,32 +65,38 @@ class YankGroup : YankGroupBase() {
operatorArguments: OperatorArguments
): Boolean {
val motion = argument.motion
val type = if (motion.isLinewiseMotion()) SelectionType.LINE_WISE else SelectionType.CHARACTER_WISE
val caretModel = editor.ij.caretModel
if (caretModel.caretCount <= 0) return false
val nativeCaretCount = editor.nativeCarets().size
if (nativeCaretCount <= 0) return false
val ranges = ArrayList<Pair<Int, Int>>(caretModel.caretCount)
val carretToRange = HashMap<VimCaret, TextRange>(nativeCaretCount)
val ranges = ArrayList<Pair<Int, Int>>(nativeCaretCount)
// This logic is from original vim
val startOffsets =
if (argument.motion.action is MotionDownLess1FirstNonSpaceAction) null else HashMap<Caret, Int>(caretModel.caretCount)
val startOffsets = if (argument.motion.action is MotionDownLess1FirstNonSpaceAction) null else HashMap<VimCaret, Int>(nativeCaretCount)
for (caret in caretModel.allCarets) {
val motionRange = MotionGroup.getMotionRange(editor.ij, caret, context.ij, argument, operatorArguments)
for (caret in editor.nativeCarets()) {
val motionRange = injector.motion.getMotionRange(editor, caret, context, argument, operatorArguments)
?: continue
assert(motionRange.size() == 1)
ranges.add(motionRange.startOffset to motionRange.endOffset)
startOffsets?.put(caret, motionRange.normalize().startOffset)
carretToRange[caret] = TextRange(motionRange.startOffset, motionRange.endOffset)
}
val type = if (motion.isLinewiseMotion()) SelectionType.LINE_WISE else SelectionType.CHARACTER_WISE
val range = getTextRange(ranges, type) ?: return false
if (range.size() == 0) return false
val selectionType = if (type == SelectionType.CHARACTER_WISE && range.isMultiple) SelectionType.BLOCK_WISE else type
return yankRange(editor.ij, range, selectionType, startOffsets)
return yankRange(
editor,
carretToRange,
range,
type,
startOffsets
)
}
/**
@ -103,19 +107,21 @@ class YankGroup : YankGroupBase() {
* @return true if able to yank the lines, false if not
*/
override fun yankLine(editor: VimEditor, count: Int): Boolean {
val caretModel = editor.ij.caretModel
val ranges = ArrayList<Pair<Int, Int>>(caretModel.caretCount)
for (caret in caretModel.allCarets) {
val start = VimPlugin.getMotion().moveCaretToLineStart(editor, caret.vim)
val end = min(VimPlugin.getMotion().moveCaretToLineEndOffset(editor, caret.vim, count - 1, true) + 1, editor.fileSize().toInt())
val caretCount = editor.nativeCarets().size
val ranges = ArrayList<Pair<Int, Int>>(caretCount)
val caretToRange = HashMap<VimCaret, TextRange>(caretCount)
for (caret in editor.nativeCarets()) {
val start = injector.motion.moveCaretToLineStart(editor, caret)
val end = min(injector.motion.moveCaretToLineEndOffset(editor, caret, count - 1, true) + 1, editor.fileSize().toInt())
if (end == -1) continue
ranges.add(start to end)
caretToRange[caret] = TextRange(start, end)
}
val range = getTextRange(ranges, SelectionType.LINE_WISE) ?: return false
return yankRange(editor.ij, range, SelectionType.LINE_WISE, null)
return yankRange(editor, caretToRange, range, SelectionType.LINE_WISE, null)
}
/**
@ -129,6 +135,7 @@ class YankGroup : YankGroupBase() {
override fun yankRange(editor: VimEditor, range: TextRange?, type: SelectionType, moveCursor: Boolean): Boolean {
range ?: return false
val caretToRange = HashMap<VimCaret, TextRange>()
val selectionType = if (type == SelectionType.CHARACTER_WISE && range.isMultiple) SelectionType.BLOCK_WISE else type
if (type == SelectionType.LINE_WISE) {
@ -143,24 +150,25 @@ class YankGroup : YankGroupBase() {
}
}
val caretModel = editor.ij.caretModel
val rangeStartOffsets = range.startOffsets
val rangeEndOffsets = range.endOffsets
return if (moveCursor) {
val startOffsets = HashMap<Caret, Int>(caretModel.caretCount)
if (type == SelectionType.BLOCK_WISE) {
startOffsets[caretModel.primaryCaret] = range.normalize().startOffset
} else {
val carets = caretModel.allCarets
for (i in carets.indices) {
startOffsets[carets[i]] = TextRange(rangeStartOffsets[i], rangeEndOffsets[i]).normalize().startOffset
}
}
yankRange(editor.ij, range, selectionType, startOffsets)
val startOffsets = HashMap<VimCaret, Int>(editor.nativeCarets().size)
if (type == SelectionType.BLOCK_WISE) {
startOffsets[editor.primaryCaret()] = range.normalize().startOffset
caretToRange[editor.primaryCaret()] = range
} else {
yankRange(editor.ij, range, selectionType, null)
for ((i, caret) in editor.nativeCarets().withIndex()) {
val textRange = TextRange(rangeStartOffsets[i], rangeEndOffsets[i])
startOffsets[caret] = textRange.normalize().startOffset
caretToRange[caret] = textRange
}
}
return if (moveCursor) {
yankRange(editor, caretToRange, range, selectionType, startOffsets)
} else {
yankRange(editor, caretToRange, range, selectionType, null)
}
}
@ -192,15 +200,20 @@ class YankGroup : YankGroupBase() {
}
private fun yankRange(
editor: Editor,
editor: VimEditor,
caretToRange: Map<VimCaret, TextRange>,
range: TextRange,
type: SelectionType,
startOffsets: Map<Caret, Int>?,
startOffsets: Map<VimCaret, Int>?,
): Boolean {
startOffsets?.forEach { (caret, offset) -> MotionGroup.moveCaret(editor, caret, offset) }
startOffsets?.forEach { (caret, offset) -> injector.motion.moveCaret(editor, caret, offset) }
notifyListeners(editor, range)
return VimPlugin.getRegister().storeText(editor.vim, range, type, false)
var result = true
for ((caret, range) in caretToRange) {
result = caret.registerStorage.storeText(editor, range, type, false) && result
}
return result
}
}

View File

@ -23,9 +23,9 @@ import com.intellij.openapi.diagnostic.trace
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.helper.EditorDataContext
import com.maddyhome.idea.vim.helper.commandState
import com.maddyhome.idea.vim.helper.editorMode
import com.maddyhome.idea.vim.helper.exitSelectMode
import com.maddyhome.idea.vim.helper.exitVisualMode
import com.maddyhome.idea.vim.helper.hasVisualSelection
@ -35,8 +35,8 @@ import com.maddyhome.idea.vim.helper.inSelectMode
import com.maddyhome.idea.vim.helper.inVisualMode
import com.maddyhome.idea.vim.helper.isIdeaVimDisabledHere
import com.maddyhome.idea.vim.helper.isTemplateActive
import com.maddyhome.idea.vim.helper.mode
import com.maddyhome.idea.vim.helper.popAllModes
import com.maddyhome.idea.vim.helper.vimStateMachine
import com.maddyhome.idea.vim.listener.VimListenerManager
import com.maddyhome.idea.vim.newapi.IjVimEditor
import com.maddyhome.idea.vim.newapi.vim
@ -58,7 +58,7 @@ object IdeaSelectionControl {
editor: Editor,
selectionSource: VimListenerManager.SelectionSource = VimListenerManager.SelectionSource.OTHER,
) {
VimVisualTimer.singleTask(editor.mode) { initialMode ->
VimVisualTimer.singleTask(editor.editorMode) { initialMode ->
if (editor.isIdeaVimDisabledHere) return@singleTask
@ -80,13 +80,13 @@ object IdeaSelectionControl {
return@singleTask
}
logger.debug("Some carets have selection. State before adjustment: ${editor.vim.commandState.toSimpleString()}")
logger.debug("Some carets have selection. State before adjustment: ${editor.vim.vimStateMachine.toSimpleString()}")
editor.popAllModes()
activateMode(editor, chooseSelectionMode(editor, selectionSource, true))
} else {
logger.debug("None of carets have selection. State before adjustment: ${editor.vim.commandState.toSimpleString()}")
logger.debug("None of carets have selection. State before adjustment: ${editor.vim.vimStateMachine.toSimpleString()}")
if (editor.inVisualMode) editor.exitVisualMode()
if (editor.inSelectMode) editor.exitSelectMode(false)
@ -96,7 +96,7 @@ object IdeaSelectionControl {
}
KeyHandler.getInstance().reset(editor.vim)
logger.debug("${editor.mode} is enabled")
logger.debug("${editor.editorMode} is enabled")
}
}
@ -110,68 +110,68 @@ object IdeaSelectionControl {
* This method is created to improve user experience. It allows avoiding delay in some operations
* (because [controlNonVimSelectionChange] is not executed immediately)
*/
fun predictMode(editor: Editor, selectionSource: VimListenerManager.SelectionSource): CommandState.Mode {
fun predictMode(editor: Editor, selectionSource: VimListenerManager.SelectionSource): VimStateMachine.Mode {
if (editor.selectionModel.hasSelection(true)) {
if (dontChangeMode(editor)) return editor.mode
if (dontChangeMode(editor)) return editor.editorMode
return chooseSelectionMode(editor, selectionSource, false)
} else {
return chooseNonSelectionMode(editor)
}
}
private fun activateMode(editor: Editor, mode: CommandState.Mode) {
private fun activateMode(editor: Editor, mode: VimStateMachine.Mode) {
when (mode) {
CommandState.Mode.VISUAL -> VimPlugin.getVisualMotion()
VimStateMachine.Mode.VISUAL -> VimPlugin.getVisualMotion()
.enterVisualMode(editor.vim, VimPlugin.getVisualMotion().autodetectVisualSubmode(editor.vim))
CommandState.Mode.SELECT -> VimPlugin.getVisualMotion()
VimStateMachine.Mode.SELECT -> VimPlugin.getVisualMotion()
.enterSelectMode(editor.vim, VimPlugin.getVisualMotion().autodetectVisualSubmode(editor.vim))
CommandState.Mode.INSERT -> VimPlugin.getChange().insertBeforeCursor(
VimStateMachine.Mode.INSERT -> VimPlugin.getChange().insertBeforeCursor(
editor.vim,
EditorDataContext.init(editor).vim
)
CommandState.Mode.COMMAND -> Unit
VimStateMachine.Mode.COMMAND -> Unit
else -> error("Unexpected mode: $mode")
}
}
private fun dontChangeMode(editor: Editor): Boolean =
editor.isTemplateActive() && (IdeaRefactorModeHelper.keepMode() || editor.mode.hasVisualSelection)
editor.isTemplateActive() && (IdeaRefactorModeHelper.keepMode() || editor.editorMode.hasVisualSelection)
private fun chooseNonSelectionMode(editor: Editor): CommandState.Mode {
private fun chooseNonSelectionMode(editor: Editor): VimStateMachine.Mode {
val templateActive = editor.isTemplateActive()
if (templateActive && editor.inNormalMode || editor.inInsertMode) {
return CommandState.Mode.INSERT
return VimStateMachine.Mode.INSERT
}
return CommandState.Mode.COMMAND
return VimStateMachine.Mode.COMMAND
}
private fun chooseSelectionMode(
editor: Editor,
selectionSource: VimListenerManager.SelectionSource,
logReason: Boolean,
): CommandState.Mode {
): VimStateMachine.Mode {
val selectmode = (VimPlugin.getOptionService().getOptionValue(OptionScope.LOCAL(IjVimEditor(editor)), OptionConstants.selectmodeName) as VimString).value
return when {
editor.isOneLineMode -> {
if (logReason) logger.debug("Enter select mode. Reason: one line mode")
CommandState.Mode.SELECT
VimStateMachine.Mode.SELECT
}
selectionSource == VimListenerManager.SelectionSource.MOUSE && OptionConstants.selectmode_mouse in selectmode -> {
if (logReason) logger.debug("Enter select mode. Selection source is mouse and selectMode option has mouse")
CommandState.Mode.SELECT
VimStateMachine.Mode.SELECT
}
editor.isTemplateActive() && IdeaRefactorModeHelper.selectMode() -> {
if (logReason) logger.debug("Enter select mode. Template is active and selectMode has template")
CommandState.Mode.SELECT
VimStateMachine.Mode.SELECT
}
selectionSource == VimListenerManager.SelectionSource.OTHER &&
OptionConstants.selectmode_ideaselection in (VimPlugin.getOptionService().getOptionValue(OptionScope.GLOBAL, OptionConstants.selectmodeName) as VimString).value -> {
if (logReason) logger.debug("Enter select mode. Selection source is OTHER and selectMode has refactoring")
CommandState.Mode.SELECT
VimStateMachine.Mode.SELECT
}
else -> {
if (logReason) logger.debug("Enter visual mode")
CommandState.Mode.VISUAL
VimStateMachine.Mode.VISUAL
}
}
}

View File

@ -19,7 +19,7 @@
package com.maddyhome.idea.vim.group.visual
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.group.visual.VimVisualTimer.mode
import com.maddyhome.idea.vim.group.visual.VimVisualTimer.singleTask
import com.maddyhome.idea.vim.options.OptionScope
@ -66,9 +66,9 @@ import javax.swing.Timer
object VimVisualTimer {
var swingTimer: Timer? = null
var mode: CommandState.Mode? = null
var mode: VimStateMachine.Mode? = null
inline fun singleTask(currentMode: CommandState.Mode, crossinline task: (initialMode: CommandState.Mode?) -> Unit) {
inline fun singleTask(currentMode: VimStateMachine.Mode, crossinline task: (initialMode: VimStateMachine.Mode?) -> Unit) {
swingTimer?.stop()
if (mode == null) mode = currentMode
@ -92,7 +92,7 @@ object VimVisualTimer {
}
}
inline fun timerAction(task: (initialMode: CommandState.Mode?) -> Unit) {
inline fun timerAction(task: (initialMode: VimStateMachine.Mode?) -> Unit) {
task(mode)
swingTimer = null
mode = null

View File

@ -23,13 +23,13 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.VisualPosition
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.VimMotionGroupBase
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.editorMode
import com.maddyhome.idea.vim.helper.inBlockSubMode
import com.maddyhome.idea.vim.helper.inSelectMode
import com.maddyhome.idea.vim.helper.inVisualMode
import com.maddyhome.idea.vim.helper.isEndAllowed
import com.maddyhome.idea.vim.helper.mode
import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset
import com.maddyhome.idea.vim.helper.subMode
import com.maddyhome.idea.vim.helper.updateCaretsVisualAttributes
@ -108,7 +108,7 @@ val Caret.vimLeadSelectionOffset: Int
}
}
return if (editor.subMode == CommandState.SubMode.VISUAL_LINE) {
return if (editor.subMode == VimStateMachine.SubMode.VISUAL_LINE) {
val selectionStartLine = editor.offsetToLogicalPosition(selectionStart).line
val caretLine = editor.offsetToLogicalPosition(this.offset).line
if (caretLine == selectionStartLine) {
@ -132,8 +132,8 @@ val Caret.vimLeadSelectionOffset: Int
return caretOffset
}
fun moveCaretOneCharLeftFromSelectionEnd(editor: Editor, predictedMode: CommandState.Mode) {
if (predictedMode != CommandState.Mode.VISUAL) {
fun moveCaretOneCharLeftFromSelectionEnd(editor: Editor, predictedMode: VimStateMachine.Mode) {
if (predictedMode != VimStateMachine.Mode.VISUAL) {
if (!predictedMode.isEndAllowed) {
editor.caretModel.allCarets.forEach { caret ->
val lineEnd = EditorHelper.getLineEndForOffset(editor, caret.offset)
@ -161,18 +161,18 @@ private fun setVisualSelection(selectionStart: Int, selectionEnd: Int, caret: Ca
val (start, end) = if (selectionStart > selectionEnd) selectionEnd to selectionStart else selectionStart to selectionEnd
val editor = caret.editor
val subMode = editor.subMode
val mode = editor.mode
val mode = editor.editorMode
val vimEditor = IjVimEditor(editor)
when (subMode) {
CommandState.SubMode.VISUAL_CHARACTER -> {
VimStateMachine.SubMode.VISUAL_CHARACTER -> {
val (nativeStart, nativeEnd) = charToNativeSelection(vimEditor, start, end, mode)
caret.vimSetSystemSelectionSilently(nativeStart, nativeEnd)
}
CommandState.SubMode.VISUAL_LINE -> {
VimStateMachine.SubMode.VISUAL_LINE -> {
val (nativeStart, nativeEnd) = lineToNativeSelection(vimEditor, start, end)
caret.vimSetSystemSelectionSilently(nativeStart, nativeEnd)
}
CommandState.SubMode.VISUAL_BLOCK -> {
VimStateMachine.SubMode.VISUAL_BLOCK -> {
editor.caretModel.removeSecondaryCarets()
// Set system selection
@ -200,7 +200,7 @@ private fun setVisualSelection(selectionStart: Int, selectionEnd: Int, caret: Ca
// Put right caret position for tab character
aCaret.moveToVisualPosition(visualPosition)
}
if (mode != CommandState.Mode.SELECT &&
if (mode != VimStateMachine.Mode.SELECT &&
!EditorHelper.isLineEmpty(editor, line, false) &&
aCaret.offset == aCaret.selectionEnd &&
aCaret.selectionEnd - 1 >= lineStartOffset &&

View File

@ -19,22 +19,33 @@
package com.maddyhome.idea.vim.group.visual
import com.intellij.find.FindManager
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.VimVisualMotionGroupBase
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.command.engine
import com.maddyhome.idea.vim.newapi.ij
import com.maddyhome.idea.vim.newapi.vim
/**
* @author Alex Plate
*/
class VisualMotionGroup : VimVisualMotionGroupBase() {
override fun autodetectVisualSubmode(editor: VimEditor): CommandState.SubMode {
override fun autodetectVisualSubmode(editor: VimEditor): VimStateMachine.SubMode {
// IJ specific. See https://youtrack.jetbrains.com/issue/VIM-1924.
val project = editor.ij.project
if (project != null && FindManager.getInstance(project).selectNextOccurrenceWasPerformed()) {
return CommandState.SubMode.VISUAL_CHARACTER
return VimStateMachine.SubMode.VISUAL_CHARACTER
}
return super.autodetectVisualSubmode(editor)
}
/**
* COMPATIBILITY-LAYER: Added a method
*/
fun enterVisualMode(editor: Editor, subMode: CommandState.SubMode? = null): Boolean {
return this.enterVisualMode(editor.vim, subMode?.engine)
}
}

View File

@ -21,7 +21,7 @@ package com.maddyhome.idea.vim.handler
import com.intellij.serviceContainer.BaseKeyedLazyInstance
import com.intellij.util.SmartList
import com.intellij.util.xmlb.annotations.Attribute
import com.maddyhome.idea.vim.common.MappingMode
import com.maddyhome.idea.vim.command.MappingMode
import javax.swing.KeyStroke
/**

View File

@ -23,7 +23,7 @@ import com.intellij.openapi.editor.CaretVisualAttributes
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.options.OptionChangeListener
import com.maddyhome.idea.vim.options.helpers.GuiCursorMode
@ -75,7 +75,7 @@ object GuicursorChangeListener : OptionChangeListener<VimDataType> {
}
private fun Editor.guicursorMode(): GuiCursorMode {
if (this.vim.commandState.isReplaceCharacter) {
if (this.vim.vimStateMachine.isReplaceCharacter) {
// Can be true for NORMAL and VISUAL
return GuiCursorMode.REPLACE
}
@ -84,18 +84,18 @@ private fun Editor.guicursorMode(): GuiCursorMode {
// makes much more use of SELECT than Vim does (e.g. it's the default for idearefactormode) so it makes sense for us
// to more visually distinguish VISUAL and SELECT. So we use INSERT; a selection and the insert caret is intuitively
// the same as SELECT
return when (mode) {
CommandState.Mode.COMMAND -> GuiCursorMode.NORMAL
CommandState.Mode.VISUAL -> GuiCursorMode.VISUAL // TODO: VISUAL_EXCLUSIVE
CommandState.Mode.SELECT -> GuiCursorMode.INSERT
CommandState.Mode.INSERT -> GuiCursorMode.INSERT
CommandState.Mode.OP_PENDING -> GuiCursorMode.OP_PENDING
CommandState.Mode.REPLACE -> GuiCursorMode.REPLACE
return when (editorMode) {
VimStateMachine.Mode.COMMAND -> GuiCursorMode.NORMAL
VimStateMachine.Mode.VISUAL -> GuiCursorMode.VISUAL // TODO: VISUAL_EXCLUSIVE
VimStateMachine.Mode.SELECT -> GuiCursorMode.INSERT
VimStateMachine.Mode.INSERT -> GuiCursorMode.INSERT
VimStateMachine.Mode.OP_PENDING -> GuiCursorMode.OP_PENDING
VimStateMachine.Mode.REPLACE -> GuiCursorMode.REPLACE
// This doesn't handle ci and cr, but we don't care - our CMD_LINE will never call this
CommandState.Mode.CMD_LINE -> GuiCursorMode.CMD_LINE
CommandState.Mode.INSERT_NORMAL -> GuiCursorMode.NORMAL
CommandState.Mode.INSERT_VISUAL -> GuiCursorMode.VISUAL
CommandState.Mode.INSERT_SELECT -> GuiCursorMode.INSERT
VimStateMachine.Mode.CMD_LINE -> GuiCursorMode.CMD_LINE
VimStateMachine.Mode.INSERT_NORMAL -> GuiCursorMode.NORMAL
VimStateMachine.Mode.INSERT_VISUAL -> GuiCursorMode.VISUAL
VimStateMachine.Mode.INSERT_SELECT -> GuiCursorMode.INSERT
}
}

View File

@ -34,7 +34,7 @@ class CommandLineHelper : VimCommandLineHelper {
override fun inputString(vimEditor: VimEditor, prompt: String, finishOn: Char?): String? {
val editor = vimEditor.ij
if (vimEditor.commandState.isDotRepeatInProgress) {
if (vimEditor.vimStateMachine.isDotRepeatInProgress) {
val input = Extension.consumeString()
return input ?: error("Not enough strings saved: ${Extension.lastExtensionHandler}")
}

View File

@ -23,89 +23,104 @@ package com.maddyhome.idea.vim.helper
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.command.engine
import com.maddyhome.idea.vim.command.ij
import com.maddyhome.idea.vim.newapi.vim
val Editor.isEndAllowed: Boolean
get() = when (this.mode) {
CommandState.Mode.INSERT, CommandState.Mode.VISUAL, CommandState.Mode.SELECT, CommandState.Mode.INSERT_VISUAL, CommandState.Mode.INSERT_SELECT -> true
CommandState.Mode.COMMAND, CommandState.Mode.CMD_LINE, CommandState.Mode.REPLACE, CommandState.Mode.OP_PENDING, CommandState.Mode.INSERT_NORMAL -> {
get() = when (this.editorMode) {
VimStateMachine.Mode.INSERT, VimStateMachine.Mode.VISUAL, VimStateMachine.Mode.SELECT, VimStateMachine.Mode.INSERT_VISUAL, VimStateMachine.Mode.INSERT_SELECT -> true
VimStateMachine.Mode.COMMAND, VimStateMachine.Mode.CMD_LINE, VimStateMachine.Mode.REPLACE, VimStateMachine.Mode.OP_PENDING, VimStateMachine.Mode.INSERT_NORMAL -> {
// One day we'll use a proper insert_normal mode
if (this.mode.inSingleMode) true else usesVirtualSpace
if (this.editorMode.inSingleMode) true else usesVirtualSpace
}
}
val CommandState.Mode.isEndAllowedIgnoringOnemore: Boolean
val VimStateMachine.Mode.isEndAllowedIgnoringOnemore: Boolean
get() = when (this) {
CommandState.Mode.INSERT, CommandState.Mode.VISUAL, CommandState.Mode.SELECT -> true
CommandState.Mode.COMMAND, CommandState.Mode.CMD_LINE, CommandState.Mode.REPLACE, CommandState.Mode.OP_PENDING -> false
CommandState.Mode.INSERT_NORMAL -> false
CommandState.Mode.INSERT_VISUAL -> true
CommandState.Mode.INSERT_SELECT -> true
VimStateMachine.Mode.INSERT, VimStateMachine.Mode.VISUAL, VimStateMachine.Mode.SELECT -> true
VimStateMachine.Mode.COMMAND, VimStateMachine.Mode.CMD_LINE, VimStateMachine.Mode.REPLACE, VimStateMachine.Mode.OP_PENDING -> false
VimStateMachine.Mode.INSERT_NORMAL -> false
VimStateMachine.Mode.INSERT_VISUAL -> true
VimStateMachine.Mode.INSERT_SELECT -> true
}
val CommandState.Mode.hasVisualSelection
val VimStateMachine.Mode.hasVisualSelection
get() = when (this) {
CommandState.Mode.VISUAL, CommandState.Mode.SELECT -> true
CommandState.Mode.REPLACE, CommandState.Mode.CMD_LINE, CommandState.Mode.COMMAND, CommandState.Mode.INSERT, CommandState.Mode.OP_PENDING -> false
CommandState.Mode.INSERT_NORMAL -> false
CommandState.Mode.INSERT_VISUAL -> true
CommandState.Mode.INSERT_SELECT -> true
VimStateMachine.Mode.VISUAL, VimStateMachine.Mode.SELECT -> true
VimStateMachine.Mode.REPLACE, VimStateMachine.Mode.CMD_LINE, VimStateMachine.Mode.COMMAND, VimStateMachine.Mode.INSERT, VimStateMachine.Mode.OP_PENDING -> false
VimStateMachine.Mode.INSERT_NORMAL -> false
VimStateMachine.Mode.INSERT_VISUAL -> true
VimStateMachine.Mode.INSERT_SELECT -> true
}
val Editor.editorMode
get() = this.vim.vimStateMachine.mode
/**
* COMPATIBILITY-LAYER: New method
*/
val Editor.mode
get() = this.vim.commandState.mode
get() = this.vim.vimStateMachine.mode.ij
/**
* COMPATIBILITY-LAYER: New method
*/
val CommandState.Mode.isEndAllowed: Boolean
get() = this.engine.isEndAllowed
var Editor.subMode
get() = this.vim.commandState.subMode
get() = this.vim.vimStateMachine.subMode
set(value) {
this.vim.commandState.subMode = value
this.vim.vimStateMachine.subMode = value
}
@get:JvmName("inNormalMode")
val Editor.inNormalMode
get() = this.mode.inNormalMode
get() = this.editorMode.inNormalMode
@get:JvmName("inNormalMode")
val CommandState.Mode.inNormalMode
get() = this == CommandState.Mode.COMMAND || this == CommandState.Mode.INSERT_NORMAL
val VimStateMachine.Mode.inNormalMode
get() = this == VimStateMachine.Mode.COMMAND || this == VimStateMachine.Mode.INSERT_NORMAL
@get:JvmName("inInsertMode")
val Editor.inInsertMode
get() = this.mode == CommandState.Mode.INSERT || this.mode == CommandState.Mode.REPLACE
get() = this.editorMode == VimStateMachine.Mode.INSERT || this.editorMode == VimStateMachine.Mode.REPLACE
@get:JvmName("inRepeatMode")
val Editor.inRepeatMode
get() = this.vim.commandState.isDotRepeatInProgress
get() = this.vim.vimStateMachine.isDotRepeatInProgress
@get:JvmName("inVisualMode")
val Editor.inVisualMode
get() = this.mode.inVisualMode
get() = this.editorMode.inVisualMode
@get:JvmName("inSelectMode")
val Editor.inSelectMode
get() = this.mode == CommandState.Mode.SELECT || this.mode == CommandState.Mode.INSERT_SELECT
get() = this.editorMode == VimStateMachine.Mode.SELECT || this.editorMode == VimStateMachine.Mode.INSERT_SELECT
val VimEditor.inSelectMode
get() = this.mode == CommandState.Mode.SELECT || this.mode == CommandState.Mode.INSERT_SELECT
get() = this.mode == VimStateMachine.Mode.SELECT || this.mode == VimStateMachine.Mode.INSERT_SELECT
@get:JvmName("inBlockSubMode")
val Editor.inBlockSubMode
get() = this.subMode == CommandState.SubMode.VISUAL_BLOCK
get() = this.subMode == VimStateMachine.SubMode.VISUAL_BLOCK
@get:JvmName("inSingleCommandMode")
val Editor.inSingleCommandMode: Boolean
get() = this.mode.inSingleMode
get() = this.editorMode.inSingleMode
@get:JvmName("inSingleMode")
val CommandState.Mode.inSingleMode: Boolean
val VimStateMachine.Mode.inSingleMode: Boolean
get() = when (this) {
CommandState.Mode.INSERT_NORMAL, CommandState.Mode.INSERT_SELECT, CommandState.Mode.INSERT_VISUAL -> true
VimStateMachine.Mode.INSERT_NORMAL, VimStateMachine.Mode.INSERT_SELECT, VimStateMachine.Mode.INSERT_VISUAL -> true
else -> false
}
@get:JvmName("inSingleNormalMode")
val CommandState.Mode.inSingleNormalMode: Boolean
val VimStateMachine.Mode.inSingleNormalMode: Boolean
get() = when (this) {
CommandState.Mode.INSERT_NORMAL -> true
VimStateMachine.Mode.INSERT_NORMAL -> true
else -> false
}

View File

@ -152,6 +152,13 @@ public class EditorHelper {
: VimInjectorKt.getInjector().getEngineEditorHelper().logicalLineToVisualLine(editor, count - 1) + 1;
}
/**
* COMPATIBILITY-LAYER: Created a function
*/
public static int getVisualLineCount(final @NotNull Editor editor) {
return getVisualLineCount(new IjVimEditor(editor));
}
/**
* Gets the number of actual lines in the file
*
@ -853,7 +860,7 @@ public class EditorHelper {
if (inlayAwareOffset == vimLastColumn) return vimLastColumn;
Editor editor = caret.getEditor();
boolean isEndAllowed = CommandStateHelper.isEndAllowedIgnoringOnemore(CommandStateHelper.getMode(editor));
boolean isEndAllowed = CommandStateHelper.isEndAllowedIgnoringOnemore(CommandStateHelper.getEditorMode(editor));
final LogicalPosition logicalPosition = caret.getLogicalPosition();
int lastColumn = EditorHelper.lastColumnForLine(editor, logicalPosition.line, isEndAllowed);

View File

@ -21,18 +21,24 @@ package com.maddyhome.idea.vim.helper
import com.intellij.openapi.actionSystem.ActionGroup
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.AnActionResult
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.openapi.actionSystem.PlatformCoreDataKeys
import com.intellij.openapi.actionSystem.PlatformDataKeys
import com.intellij.openapi.actionSystem.Presentation
import com.intellij.openapi.actionSystem.ex.ActionManagerEx
import com.intellij.openapi.actionSystem.ex.ActionUtil
import com.intellij.openapi.command.CommandProcessor
import com.intellij.openapi.command.UndoConfirmationPolicy
import com.intellij.openapi.components.Service
import com.intellij.openapi.editor.actionSystem.DocCommandGroupId
import com.intellij.openapi.project.IndexNotReadyException
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.util.NlsContexts
import com.intellij.util.SlowOperations
import com.maddyhome.idea.vim.RegisterActions
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.NativeAction
@ -95,11 +101,48 @@ class IjActionExecutor : VimActionExecutor {
popup.showInFocusCenter()
return true
} else {
ActionUtil.performActionDumbAwareWithCallbacks(ijAction, event)
performDumbAwareWithCallbacks(ijAction, event) { ijAction.actionPerformed(event) }
return true
}
}
// This is taken directly from ActionUtil.performActionDumbAwareWithCallbacks
// But with one check removed. With this check some actions (like `:w` doesn't work)
// https://youtrack.jetbrains.com/issue/VIM-2691/File-is-not-saved-on-w
private fun performDumbAwareWithCallbacks(
action: AnAction,
event: AnActionEvent,
performRunnable: Runnable,
) {
val project = event.project
var indexError: IndexNotReadyException? = null
val manager = ActionManagerEx.getInstanceEx()
manager.fireBeforeActionPerformed(action, event)
val component = event.getData(PlatformCoreDataKeys.CONTEXT_COMPONENT)
var result: AnActionResult? = null
try {
SlowOperations.allowSlowOperations(SlowOperations.ACTION_PERFORM).use { ignore ->
performRunnable.run()
result = AnActionResult.PERFORMED
}
} catch (ex: IndexNotReadyException) {
indexError = ex
result = AnActionResult.failed(ex)
} catch (ex: RuntimeException) {
result = AnActionResult.failed(ex)
throw ex
} catch (ex: Error) {
result = AnActionResult.failed(ex)
throw ex
} finally {
if (result == null) result = AnActionResult.failed(Throwable())
manager.fireAfterActionPerformed(action, event, result!!)
}
if (indexError != null) {
ActionUtil.showDumbModeWarning(project, event)
}
}
private fun canBePerformed(event: AnActionEvent, action: ActionGroup, context: DataContext): Boolean {
val presentation = event.presentation
return try {
@ -155,6 +198,10 @@ class IjActionExecutor : VimActionExecutor {
return RegisterActions.findAction(id)
}
override fun findVimActionOrDie(id: String): EditorActionHandlerBase {
return RegisterActions.findActionOrDie(id)
}
override fun getAction(actionId: String): NativeAction? {
return ActionManager.getInstance().getAction(actionId)?.let { IjNativeAction(it) }
}

View File

@ -143,4 +143,8 @@ class IjEditorHelper : EngineEditorHelper {
override fun getLeadingWhitespace(editor: VimEditor, line: Int): String {
return EditorHelper.getLeadingWhitespace(editor.ij, line)
}
override fun anyNonWhitespace(editor: VimEditor, offset: Int, dir: Int): Boolean {
return SearchHelper.anyNonWhitespace(editor.ij, offset, dir)
}
}

View File

@ -25,9 +25,9 @@ import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor
import com.maddyhome.idea.vim.newapi.IjExecutionContext
@ -39,8 +39,8 @@ import com.maddyhome.idea.vim.newapi.vim
* Pop all modes, but leave editor state. E.g. editor selection is not removed.
*/
fun Editor.popAllModes() {
val commandState = this.vim.commandState
while (commandState.mode != CommandState.Mode.COMMAND) {
val commandState = this.vim.vimStateMachine
while (commandState.mode != VimStateMachine.Mode.COMMAND) {
commandState.popModes()
}
}
@ -63,7 +63,7 @@ fun Editor.exitVisualMode() {
VimPlugin.getMark().setVisualSelectionMarks(this.vim, TextRange(vimSelectionStart, primaryCaret.offset))
this.caretModel.allCarets.forEach { it.vimSelectionStartClear() }
this.vim.commandState.popModes()
this.vim.vimStateMachine.popModes()
}
}
@ -71,7 +71,7 @@ fun Editor.exitVisualMode() {
fun Editor.exitSelectMode(adjustCaretPosition: Boolean) {
if (!this.inSelectMode) return
this.vim.commandState.popModes()
this.vim.vimStateMachine.popModes()
SelectionVimListenerSuppressor.lock().use {
this.caretModel.allCarets.forEach {
it.removeSelection()
@ -91,7 +91,7 @@ fun Editor.exitSelectMode(adjustCaretPosition: Boolean) {
fun VimEditor.exitSelectMode(adjustCaretPosition: Boolean) {
if (!this.inSelectMode) return
this.commandState.popModes()
this.vimStateMachine.popModes()
SelectionVimListenerSuppressor.lock().use {
this.carets().forEach { vimCaret ->
val caret = (vimCaret as IjVimCaret).caret

View File

@ -31,7 +31,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.command.VimStateMachine;
import com.maddyhome.idea.vim.common.CharacterPosition;
import com.maddyhome.idea.vim.common.Direction;
import com.maddyhome.idea.vim.common.TextRange;
@ -893,8 +893,8 @@ public class SearchHelper {
selectionEndWithoutNewline++;
}
final CommandState.Mode mode = CommandState.getInstance(new IjVimEditor(editor)).getMode();
if (mode == CommandState.Mode.VISUAL) {
final VimStateMachine.Mode mode = VimStateMachine.getInstance(new IjVimEditor(editor)).getMode();
if (mode == VimStateMachine.Mode.VISUAL) {
if (closingTagTextRange.getStartOffset() == selectionEndWithoutNewline &&
openingTag.getEndOffset() == selectionStart) {
// Special case: if the inner tag is already selected we should like isOuter is active

View File

@ -0,0 +1,44 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 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.helper
import com.maddyhome.idea.vim.api.injector
import java.util.*
import java.util.stream.Collectors
import javax.swing.KeyStroke
/**
* COMPATIBILITY-LAYER: Created a helper class
*/
object StringHelper {
@JvmStatic
fun parseKeys(string: String): List<KeyStroke> {
return injector.parser.parseKeys(string)
}
@JvmStatic
fun parseKeys(vararg string: String): List<KeyStroke> {
return Arrays.stream(string).flatMap { o: String -> injector.parser.parseKeys(o).stream() }
.collect(Collectors.toList())
}
@JvmStatic
fun isCloseKeyStroke(stroke: KeyStroke): Boolean {
return stroke.isCloseKeyStroke()
}
}

View File

@ -99,5 +99,6 @@ class UndoRedoHelper : UndoRedoBase() {
while (check() && !changeListener.hasChanged) {
action.run()
}
vimDocument.removeChangeListener(changeListener)
}
}

View File

@ -27,8 +27,9 @@ import com.intellij.openapi.editor.RangeMarker
import com.intellij.openapi.editor.markup.RangeHighlighter
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.UserDataHolder
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.api.CaretRegisterStorageBase
import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.ex.ExOutputModel
import com.maddyhome.idea.vim.group.visual.VisualChange
import com.maddyhome.idea.vim.group.visual.vimLeadSelectionOffset
@ -73,11 +74,12 @@ var Caret.vimInsertStart: RangeMarker by userDataOr {
this.offset
)
}
var Caret.registerStorage: CaretRegisterStorageBase? by userDataCaretToEditor()
// ------------------ Editor
fun unInitializeEditor(editor: Editor) {
editor.vimLastSelectionType = null
editor.vimCommandState = null
editor.vimStateMachine = null
editor.vimMorePanel = null
editor.vimExOutput = null
editor.vimLastHighlighters = null
@ -91,7 +93,7 @@ var Editor.vimIncsearchCurrentMatchOffset: Int? by userData()
* @see :help visualmode()
*/
var Editor.vimLastSelectionType: SelectionType? by userData()
var Editor.vimCommandState: CommandState? by userData()
var Editor.vimStateMachine: VimStateMachine? by userData()
var Editor.vimEditorGroup: Boolean by userDataOr { false }
var Editor.vimLineNumbersInitialState: Boolean by userDataOr { false }
var Editor.vimHasRelativeLineNumbersInstalled: Boolean by userDataOr { false }
@ -103,7 +105,7 @@ var Editor.vimTestInputModel: TestInputModel? by userData()
* Checks whether a keeping visual mode visual operator action is performed on editor.
*/
var Editor.vimKeepingVisualOperatorAction: Boolean by userDataOr { false }
var Editor.vimChangeActionSwitchMode: CommandState.Mode? by userData()
var Editor.vimChangeActionSwitchMode: VimStateMachine.Mode? by userData()
/**
* Function for delegated properties.

View File

@ -19,8 +19,6 @@
package com.maddyhome.idea.vim.key
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.common.Node
import com.maddyhome.idea.vim.common.addLeafs
fun <T> Node<T>.addLeafs(keys: String, actionHolder: T) {
addLeafs(injector.parser.parseKeys(keys), actionHolder)

View File

@ -32,16 +32,17 @@ import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.actionSystem.ex.AnActionListener
import com.intellij.openapi.actionSystem.impl.ProxyShortcutSet
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.DumbAwareToggleAction
import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.group.NotificationService
import com.maddyhome.idea.vim.helper.EditorDataContext
import com.maddyhome.idea.vim.helper.commandState
import com.maddyhome.idea.vim.helper.inNormalMode
import com.maddyhome.idea.vim.helper.isIdeaVimDisabledHere
import com.maddyhome.idea.vim.helper.vimStateMachine
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.options.OptionConstants
import com.maddyhome.idea.vim.options.OptionScope
@ -70,7 +71,7 @@ object IdeaSpecifics {
//region Track action id
if (VimPlugin.getOptionService().isSet(OptionScope.GLOBAL, OptionConstants.trackactionidsName)) {
if (action !is NotificationService.ActionIdNotifier.CopyActionId && action !is NotificationService.ActionIdNotifier.StopTracking) {
val id: String? = ActionManager.getInstance().getId(action)
val id: String? = ActionManager.getInstance().getId(action) ?: (action.shortcutSet as? ProxyShortcutSet)?.actionId
VimPlugin.getNotifications(dataContext.getData(CommonDataKeys.PROJECT)).notifyActionId(id)
}
}
@ -88,8 +89,8 @@ object IdeaSpecifics {
}
) {
editor?.let {
val commandState = it.vim.commandState
while (commandState.mode != CommandState.Mode.COMMAND) {
val commandState = it.vim.vimStateMachine
while (commandState.mode != VimStateMachine.Mode.COMMAND) {
commandState.popModes()
}
VimPlugin.getChange().insertBeforeCursor(it.vim, dataContext.vim)

View File

@ -44,7 +44,7 @@ import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.VimKeyListener
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.VimTypedActionHandler
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.ex.ExOutputModel
import com.maddyhome.idea.vim.group.EditorGroup
import com.maddyhome.idea.vim.group.FileGroup
@ -425,7 +425,7 @@ object VimListenerManager {
ExOutputModel.getInstance(editor).clear()
val caretModel = editor.caretModel
if (editor.subMode != CommandState.SubMode.NONE) {
if (editor.subMode != VimStateMachine.SubMode.NONE) {
caretModel.removeSecondaryCarets()
}

View File

@ -28,11 +28,12 @@ import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.LineDeleteShift
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimChangeGroupBase
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.VimMotionGroupBase
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.common.EditorLine
import com.maddyhome.idea.vim.common.IndentConfig
import com.maddyhome.idea.vim.common.OperatedRange
@ -40,7 +41,6 @@ import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.common.VimRange
import com.maddyhome.idea.vim.common.including
import com.maddyhome.idea.vim.common.offset
import com.maddyhome.idea.vim.group.ChangeGroup
import com.maddyhome.idea.vim.group.MotionGroup
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.inlayAwareVisualColumn
@ -62,7 +62,7 @@ fun changeRange(
var col = 0
var lines = 0
if (type === SelectionType.BLOCK_WISE) {
lines = ChangeGroup.getLinesCountInVisualBlock(IjVimEditor(editor), range)
lines = VimChangeGroupBase.getLinesCountInVisualBlock(IjVimEditor(editor), range)
col = editor.offsetToLogicalPosition(range.startOffset).column
if (caret.vimLastColumn == VimMotionGroupBase.LAST_COLUMN) {
col = VimMotionGroupBase.LAST_COLUMN
@ -103,7 +103,7 @@ fun changeRange(
if (type == SelectionType.BLOCK_WISE) {
VimPlugin.getChange().setInsertRepeat(lines, col, false)
}
editor.vimChangeActionSwitchMode = CommandState.Mode.INSERT
editor.vimChangeActionSwitchMode = VimStateMachine.Mode.INSERT
}
} else {
VimPlugin.getChange().insertBeforeCursor(editor.vim, context.vim)
@ -158,9 +158,9 @@ fun deleteRange(
fun insertLineAround(editor: VimEditor, context: ExecutionContext, shift: Int) {
val project = (editor as IjVimEditor).editor.project
VimPlugin.getChange().initInsert(editor, context, CommandState.Mode.INSERT)
VimPlugin.getChange().initInsert(editor, context, VimStateMachine.Mode.INSERT)
if (!CommandState.getInstance(editor).isDotRepeatInProgress) {
if (!VimStateMachine.getInstance(editor).isDotRepeatInProgress) {
for (vimCaret in editor.carets()) {
val caret = (vimCaret as IjVimCaret).caret
val line = vimCaret.getLine()

View File

@ -22,7 +22,10 @@ import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.LogicalPosition
import com.intellij.openapi.editor.VisualPosition
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.CaretRegisterStorage
import com.maddyhome.idea.vim.api.CaretRegisterStorageBase
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimCaretBase
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.VimLogicalPosition
import com.maddyhome.idea.vim.api.VimVisualPosition
@ -38,13 +41,23 @@ import com.maddyhome.idea.vim.group.visual.vimSetSystemSelectionSilently
import com.maddyhome.idea.vim.group.visual.vimUpdateEditorSelection
import com.maddyhome.idea.vim.helper.inlayAwareVisualColumn
import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset
import com.maddyhome.idea.vim.helper.registerStorage
import com.maddyhome.idea.vim.helper.vimInsertStart
import com.maddyhome.idea.vim.helper.vimLastColumn
import com.maddyhome.idea.vim.helper.vimLastVisualOperatorRange
import com.maddyhome.idea.vim.helper.vimLine
import com.maddyhome.idea.vim.helper.vimSelectionStart
class IjVimCaret(val caret: Caret) : VimCaret {
class IjVimCaret(val caret: Caret) : VimCaretBase() {
override val registerStorage: CaretRegisterStorage
get() {
var storage = this.caret.registerStorage
if (storage == null) {
storage = CaretRegisterStorageBase(editor.primaryCaret().ij == caret)
this.caret.registerStorage = storage
}
return storage
}
override val editor: VimEditor
get() = IjVimEditor(caret.editor)
override val offset: Offset

View File

@ -54,4 +54,4 @@ class IjVimDocument(private val document: Document) : VimDocument {
override fun getOffsetGuard(offset: Offset): LiveRange? {
return document.getOffsetGuard(offset.point)?.vim
}
}
}

View File

@ -38,9 +38,9 @@ import com.maddyhome.idea.vim.api.VimLogicalPosition
import com.maddyhome.idea.vim.api.VimSelectionModel
import com.maddyhome.idea.vim.api.VimVisualPosition
import com.maddyhome.idea.vim.api.VirtualFile
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.common.EditorLine
import com.maddyhome.idea.vim.common.LiveRange
import com.maddyhome.idea.vim.common.Offset
@ -72,7 +72,7 @@ class IjVimEditor(editor: Editor) : MutableLinearEditor() {
val originalEditor = editor
override val lfMakesNewLine: Boolean = true
override var vimChangeActionSwitchMode: CommandState.Mode?
override var vimChangeActionSwitchMode: VimStateMachine.Mode?
get() = editor.vimChangeActionSwitchMode
set(value) {
editor.vimChangeActionSwitchMode = value

View File

@ -3,6 +3,7 @@ package com.maddyhome.idea.vim.newapi
import com.intellij.openapi.components.service
import com.intellij.openapi.components.serviceIfCreated
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.api.EngineEditorHelper
import com.maddyhome.idea.vim.api.ExEntryPanel
import com.maddyhome.idea.vim.api.ExecutionContextManager
@ -39,7 +40,7 @@ import com.maddyhome.idea.vim.api.VimrcFileState
import com.maddyhome.idea.vim.api.VimscriptExecutor
import com.maddyhome.idea.vim.api.VimscriptFunctionService
import com.maddyhome.idea.vim.api.VimscriptParser
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.common.VimMachine
import com.maddyhome.idea.vim.diagnostic.VimLogger
import com.maddyhome.idea.vim.ex.ExOutputModel
@ -63,11 +64,11 @@ import com.maddyhome.idea.vim.helper.IjEditorHelper
import com.maddyhome.idea.vim.helper.IjVimStringParser
import com.maddyhome.idea.vim.helper.UndoRedoHelper
import com.maddyhome.idea.vim.helper.VimCommandLineHelper
import com.maddyhome.idea.vim.helper.vimCommandState
import com.maddyhome.idea.vim.helper.vimStateMachine
import com.maddyhome.idea.vim.history.VimHistory
import com.maddyhome.idea.vim.macro.VimMacro
import com.maddyhome.idea.vim.mark.VimMarkGroup
import com.maddyhome.idea.vim.options.OptionService
import com.maddyhome.idea.vim.vimscript.services.OptionService
import com.maddyhome.idea.vim.put.VimPut
import com.maddyhome.idea.vim.register.VimRegisterGroup
import com.maddyhome.idea.vim.ui.VimRcFileState
@ -75,7 +76,7 @@ import com.maddyhome.idea.vim.undo.VimUndoRedo
import com.maddyhome.idea.vim.vimscript.Executor
import com.maddyhome.idea.vim.vimscript.services.FunctionStorage
import com.maddyhome.idea.vim.vimscript.services.PatternService
import com.maddyhome.idea.vim.vimscript.services.VimVariableService
import com.maddyhome.idea.vim.vimscript.services.VariableService
import com.maddyhome.idea.vim.yank.VimYankGroup
class IjVimInjector : VimInjectorBase() {
@ -160,7 +161,7 @@ class IjVimInjector : VimInjectorBase() {
override val functionService: VimscriptFunctionService
get() = FunctionStorage
override val variableService: VimVariableService
override val variableService: VariableService
get() = service()
override val vimrcFileState: VimrcFileState
get() = VimRcFileState
@ -179,15 +180,23 @@ class IjVimInjector : VimInjectorBase() {
override val vimStorageService: VimStorageService
get() = service()
override fun commandStateFor(editor: VimEditor): CommandState {
var res = editor.ij.vimCommandState
override fun commandStateFor(editor: VimEditor): VimStateMachine {
var res = editor.ij.vimStateMachine
if (res == null) {
res = CommandState(editor)
editor.ij.vimCommandState = res
res = VimStateMachine(editor)
editor.ij.vimStateMachine = res
}
return res
}
override fun commandStateFor(editor: Any): VimStateMachine {
return when (editor) {
is VimEditor -> this.commandStateFor(editor)
is Editor -> this.commandStateFor(IjVimEditor(editor))
else -> error("Unexpected type: $editor")
}
}
override val engineEditorHelper: EngineEditorHelper
get() = service<IjEditorHelper>()
override val editorGroup: VimEditorGroup

View File

@ -110,6 +110,17 @@ class IjVimSearchHelper : VimSearchHelper {
)
}
override fun findNextWordEnd(
chars: CharSequence,
pos: Int,
size: Int,
count: Int,
bigWord: Boolean,
spaceWords: Boolean,
): Int {
return SearchHelper.findNextWordEnd(chars, pos, size, count, bigWord, spaceWords)
}
override fun findNextWord(editor: VimEditor, searchFrom: Int, count: Int, bigWord: Boolean): Int {
return SearchHelper.findNextWord(
(editor as IjVimEditor).editor,

View File

@ -0,0 +1,59 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 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.option
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.options.OptionConstants
import com.maddyhome.idea.vim.options.OptionConstants.Companion.ignorecaseName
import com.maddyhome.idea.vim.options.OptionConstants.Companion.smartcaseName
import com.maddyhome.idea.vim.options.OptionConstants.Companion.timeoutName
import com.maddyhome.idea.vim.options.OptionConstants.Companion.timeoutlenName
import com.maddyhome.idea.vim.options.OptionScope
import com.maddyhome.idea.vim.options.helpers.KeywordOptionHelper
import com.maddyhome.idea.vim.vimscript.services.IjVimOptionService
/**
* COMPATIBILITY-LAYER: Added a class and package
*/
object OptionsManager {
val ignorecase: ToggleOption
get() = (injector.optionService as IjVimOptionService).getRawOption(ignorecaseName) as ToggleOption
val smartcase: ToggleOption
get() = (injector.optionService as IjVimOptionService).getRawOption(smartcaseName) as ToggleOption
val timeout: ToggleOption
get() = (injector.optionService as IjVimOptionService).getRawOption(timeoutName) as ToggleOption
val timeoutlen: NumberOption
get() = (injector.optionService as IjVimOptionService).getRawOption(timeoutlenName) as NumberOption
val iskeyword: KeywordOption
get() = KeywordOption(KeywordOptionHelper)
}
class KeywordOption(val helper: KeywordOptionHelper) {
fun toRegex(): List<String> {
return helper.toRegex()
}
}
object StrictMode {
fun fail(message: String) {
if (injector.optionService.isSet(OptionScope.GLOBAL, OptionConstants.ideastrictmodeName)) {
error(message)
}
}
}

View File

@ -4,7 +4,7 @@ import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.util.containers.MultiMap
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.common.MappingMode
import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.key.MappingOwner
import com.maddyhome.idea.vim.key.ToKeysMappingInfo

View File

@ -20,8 +20,8 @@ package com.maddyhome.idea.vim.ui
import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.helper.commandState
import com.maddyhome.idea.vim.helper.isCloseKeyStroke
import com.maddyhome.idea.vim.helper.vimStateMachine
import java.awt.KeyEventDispatcher
import java.awt.KeyboardFocusManager
import java.awt.Toolkit
@ -62,7 +62,7 @@ object ModalEntry {
} else {
return true
}
if (editor.commandState.isRecording) {
if (editor.vimStateMachine.isRecording) {
KeyHandler.getInstance().modalEntryKeys += stroke
}
if (!processor(stroke)) {

View File

@ -33,7 +33,7 @@ import com.intellij.util.Consumer
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.helper.EngineStringHelper
import com.maddyhome.idea.vim.helper.VimNlsSafe
import com.maddyhome.idea.vim.helper.commandState
import com.maddyhome.idea.vim.helper.vimStateMachine
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.options.OptionChangeListener
import com.maddyhome.idea.vim.options.OptionConstants
@ -70,7 +70,7 @@ object ShowCmd {
fun getFullText(editor: Editor?): String {
if (!VimPlugin.getOptionService().isSet(OptionScope.GLOBAL, OptionConstants.showcmdName) || editor == null || editor.isDisposed) return ""
val editorState = editor.vim.commandState
val editorState = editor.vim.vimStateMachine
return EngineStringHelper.toPrintableCharacters(editorState.commandBuilder.keys + editorState.mappingState.keys)
}
}

View File

@ -0,0 +1,49 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 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.vimscript.model.functions.handlers
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.ex.ExException
import com.maddyhome.idea.vim.vimscript.model.VimLContext
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimList
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString
import com.maddyhome.idea.vim.vimscript.model.expressions.Expression
import com.maddyhome.idea.vim.vimscript.model.functions.FunctionHandler
class JoinFunctionHandler : FunctionHandler() {
override val name: String = "join"
override val minimumNumberOfArguments: Int = 1
override val maximumNumberOfArguments: Int = 2
override fun doFunction(
argumentValues: List<Expression>,
editor: VimEditor,
context: ExecutionContext,
vimContext: VimLContext,
): VimDataType {
val firstArgument = argumentValues[0].evaluate(editor, context, vimContext)
if (firstArgument !is VimList) {
throw ExException("E714: List required")
}
val secondArgument = argumentValues.getOrNull(1)?.evaluate(editor, context, vimContext) ?: VimString(" ")
return VimString(firstArgument.values.joinToString(secondArgument.asString()) { it.toString() })
}
}

View File

@ -0,0 +1,44 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 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.vimscript.model.functions.handlers
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.vimscript.model.VimLContext
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString
import com.maddyhome.idea.vim.vimscript.model.expressions.Expression
import com.maddyhome.idea.vim.vimscript.model.functions.FunctionHandler
import java.util.*
class TolowerFunctionHandler : FunctionHandler() {
override val name: String = "tolower"
override val minimumNumberOfArguments: Int = 1
override val maximumNumberOfArguments: Int = 1
override fun doFunction(
argumentValues: List<Expression>,
editor: VimEditor,
context: ExecutionContext,
vimContext: VimLContext,
): VimDataType {
val argumentString = argumentValues[0].evaluate(editor, context, vimContext).asString()
return VimString(argumentString.lowercase(Locale.getDefault()))
}
}

View File

@ -0,0 +1,44 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2022 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.vimscript.model.functions.handlers
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.vimscript.model.VimLContext
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString
import com.maddyhome.idea.vim.vimscript.model.expressions.Expression
import com.maddyhome.idea.vim.vimscript.model.functions.FunctionHandler
import java.util.*
class ToupperFunctionHandler : FunctionHandler() {
override val name: String = "toupper"
override val minimumNumberOfArguments: Int = 1
override val maximumNumberOfArguments: Int = 1
override fun doFunction(
argumentValues: List<Expression>,
editor: VimEditor,
context: ExecutionContext,
vimContext: VimLContext,
): VimDataType {
val argumentString = argumentValues[0].evaluate(editor, context, vimContext).asString()
return VimString(argumentString.uppercase(Locale.getDefault()))
}
}

View File

@ -25,9 +25,9 @@ import com.intellij.codeInsight.lookup.impl.LookupImpl
import com.intellij.codeInsight.template.impl.TemplateManagerImpl
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.helper.editorMode
import com.maddyhome.idea.vim.helper.hasBlockOrUnderscoreCaret
import com.maddyhome.idea.vim.helper.hasVisualSelection
import com.maddyhome.idea.vim.helper.mode
import com.maddyhome.idea.vim.helper.subMode
import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor
import com.maddyhome.idea.vim.newapi.vim
@ -42,12 +42,12 @@ object IdeaRefactorModeHelper {
fun correctSelection(editor: Editor) {
val action: () -> Unit = {
if (!editor.mode.hasVisualSelection && editor.selectionModel.hasSelection()) {
if (!editor.editorMode.hasVisualSelection && editor.selectionModel.hasSelection()) {
SelectionVimListenerSuppressor.lock().use {
editor.selectionModel.removeSelection()
}
}
if (editor.mode.hasVisualSelection && editor.selectionModel.hasSelection()) {
if (editor.editorMode.hasVisualSelection && editor.selectionModel.hasSelection()) {
val autodetectedSubmode = VimPlugin.getVisualMotion().autodetectVisualSubmode(editor.vim)
if (editor.subMode != autodetectedSubmode) {
// Update the submode

View File

@ -162,7 +162,7 @@ object CommandVisitor : VimscriptBaseVisitor<Command>() {
val ranges = createRange(valueAndOffset.first, valueAndOffset.second, move)
if (ranges == null) {
logger.warn("Could not create a range for node ${ctx.text}")
throw ExException("Could not create a range")
throw ExException("Could not create a range ${ctx.text}")
}
return ranges
}
@ -180,7 +180,7 @@ object CommandVisitor : VimscriptBaseVisitor<Command>() {
override fun visitLet1Command(ctx: VimscriptParser.Let1CommandContext): Command {
val ranges: Ranges = parseRanges(ctx.range())
val variable: Expression = expressionVisitor.visit(ctx.expr(0))
val operator = getByValue(ctx.assignmentOperator.text)
val operator = getByValue(ctx.assignmentOperator().text)
val expression: Expression = expressionVisitor.visit(ctx.expr(1))
return LetCommand(ranges, variable, operator, expression, true)
}

View File

@ -33,7 +33,7 @@ import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString
import com.maddyhome.idea.vim.vimscript.model.expressions.Scope
import com.maddyhome.idea.vim.vimscript.model.expressions.Variable
internal class VimVariableServiceImpl : VimVariableServiceBase() {
class IjVariableService : VimVariableServiceBase() {
override fun storeVariable(variable: Variable, value: VimDataType, editor: VimEditor, context: ExecutionContext, vimContext: VimLContext) {
super.storeVariable(variable, value, editor, context, vimContext)

View File

@ -20,9 +20,9 @@ package com.maddyhome.idea.vim.vimscript.services
import com.intellij.openapi.application.ApplicationNamesInfo
import com.maddyhome.idea.vim.api.VimOptionServiceBase
import com.maddyhome.idea.vim.option.ToggleOption
import com.maddyhome.idea.vim.options.OptionConstants
import com.maddyhome.idea.vim.options.StringOption
import com.maddyhome.idea.vim.options.ToggleOption
internal class IjVimOptionService : VimOptionServiceBase() {

View File

@ -26,13 +26,13 @@
serviceInterface="com.maddyhome.idea.vim.api.VimVisualMotionGroup"/>
<applicationService serviceImplementation="com.maddyhome.idea.vim.group.copy.YankGroup"/>
<applicationService serviceImplementation="com.maddyhome.idea.vim.group.copy.PutGroup"/>
<applicationService serviceImplementation="com.maddyhome.idea.vim.vimscript.services.VimVariableServiceImpl"
serviceInterface="com.maddyhome.idea.vim.vimscript.services.VimVariableService"/>
<applicationService serviceImplementation="com.maddyhome.idea.vim.vimscript.services.IjVariableService"
serviceInterface="com.maddyhome.idea.vim.vimscript.services.VariableService"/>
<applicationService serviceImplementation="com.maddyhome.idea.vim.group.IjStatisticsService"
serviceInterface="com.maddyhome.idea.vim.api.VimStatistics"/>
<applicationService serviceImplementation="com.maddyhome.idea.vim.vimscript.services.IjVimOptionService"
serviceInterface="com.maddyhome.idea.vim.options.OptionService"/>
serviceInterface="com.maddyhome.idea.vim.vimscript.services.OptionService"/>
<applicationService serviceImplementation="com.maddyhome.idea.vim.group.IjVimStorageService"
serviceInterface="com.maddyhome.idea.vim.api.VimStorageService"/>
<applicationService serviceImplementation="com.maddyhome.idea.vim.group.IjVimSystemInfoService"

View File

@ -11,5 +11,8 @@
<vimLibraryFunction implementation="com.maddyhome.idea.vim.vimscript.model.functions.handlers.FuncrefFunctionHandler" name="funcref"/>
<vimLibraryFunction implementation="com.maddyhome.idea.vim.vimscript.model.functions.handlers.HasFunctionHandler" name="has"/>
<vimLibraryFunction implementation="com.maddyhome.idea.vim.vimscript.model.functions.handlers.SubmatchFunctionHandler" name="submatch"/>
<vimLibraryFunction implementation="com.maddyhome.idea.vim.vimscript.model.functions.handlers.TolowerFunctionHandler" name="tolower"/>
<vimLibraryFunction implementation="com.maddyhome.idea.vim.vimscript.model.functions.handlers.ToupperFunctionHandler" name="toupper"/>
<vimLibraryFunction implementation="com.maddyhome.idea.vim.vimscript.model.functions.handlers.JoinFunctionHandler" name="join"/>
</extensions>
</idea-plugin>

View File

@ -24,16 +24,15 @@ import com.intellij.openapi.project.Project;
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
import com.maddyhome.idea.vim.KeyHandler;
import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.command.VimStateMachine;
import com.maddyhome.idea.vim.group.visual.VimVisualTimer;
import com.maddyhome.idea.vim.helper.EditorDataContext;
import com.maddyhome.idea.vim.helper.RunnableHelper;
import com.maddyhome.idea.vim.helper.TestInputModel;
import com.maddyhome.idea.vim.newapi.IjExecutionContext;
import com.maddyhome.idea.vim.newapi.IjVimEditor;
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel;
import com.maddyhome.idea.vim.options.OptionScope;
import com.maddyhome.idea.vim.vimscript.services.VimVariableServiceImpl;
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -63,7 +62,7 @@ public abstract class JavaVimTestCase extends JavaCodeInsightFixtureTestCase {
@Override
protected void tearDown() throws Exception {
ExEntryPanel.getInstance().deactivate(false);
((VimVariableServiceImpl) VimPlugin.getVariableService()).clear();
VimPlugin.getVariableService().clear();
Timer swingTimer = VimVisualTimer.INSTANCE.getSwingTimer();
if (swingTimer != null) {
swingTimer.stop();
@ -107,8 +106,8 @@ public abstract class JavaVimTestCase extends JavaCodeInsightFixtureTestCase {
return editor;
}
public void assertMode(@NotNull CommandState.Mode expectedMode) {
final CommandState.Mode mode = CommandState.getInstance(new IjVimEditor(myFixture.getEditor())).getMode();
public void assertMode(@NotNull VimStateMachine.Mode expectedMode) {
final VimStateMachine.Mode mode = VimStateMachine.getInstance(new IjVimEditor(myFixture.getEditor())).getMode();
assertEquals(expectedMode, mode);
}

View File

@ -28,7 +28,7 @@ import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.common.CharacterPosition
import com.maddyhome.idea.vim.helper.VimBehaviorDiffers
import com.maddyhome.idea.vim.helper.commandState
import com.maddyhome.idea.vim.helper.vimStateMachine
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.register.RegisterConstants.ALTERNATE_BUFFER_REGISTER
import com.maddyhome.idea.vim.register.RegisterConstants.BLACK_HOLE_REGISTER
@ -153,7 +153,7 @@ internal object NeovimTesting {
}
private fun assertMode(editor: Editor) {
val ideavimState = editor.vim.commandState.toVimNotation()
val ideavimState = editor.vim.vimStateMachine.toVimNotation()
val neovimState = neovimApi.mode.get().mode
assertEquals(neovimState, ideavimState)
}

View File

@ -21,10 +21,10 @@ package org.jetbrains.plugins.ideavim
import com.maddyhome.idea.vim.RegisterActions.VIM_ACTIONS_EP
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.common.CommandNode
import com.maddyhome.idea.vim.common.CommandPartNode
import com.maddyhome.idea.vim.common.MappingMode
import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.key.CommandNode
import com.maddyhome.idea.vim.key.CommandPartNode
import com.maddyhome.idea.vim.handler.ActionBeanClass
import junit.framework.TestCase
import javax.swing.KeyStroke
@ -33,7 +33,7 @@ class RegisterActionsTest : VimTestCase() {
fun `test simple action`() {
val before = "I ${c}found it in a legendary land"
val after = "I f${c}ound it in a legendary land"
doTest("l", before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest("l", before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
@TestWithoutNeovim(reason = SkipNeovimReason.EDITOR_MODIFICATION)
@ -44,7 +44,7 @@ class RegisterActionsTest : VimTestCase() {
val keys = injector.parser.parseKeys("jklwB") // just random keys
val before = "I ${c}found it in a legendary land"
val after = "I jklwB${c}found it in a legendary land"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE) {
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE) {
VimPlugin.setEnabled(false)
}
}
@ -54,7 +54,7 @@ class RegisterActionsTest : VimTestCase() {
val keys = injector.parser.parseKeys("l")
val before = "I ${c}found it in a legendary land"
val after = "I f${c}ound it in a legendary land"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE) {
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE) {
VimPlugin.setEnabled(false)
VimPlugin.setEnabled(true)
}
@ -65,7 +65,7 @@ class RegisterActionsTest : VimTestCase() {
val keys = injector.parser.parseKeys("l")
val before = "I ${c}found it in a legendary land"
val after = "I f${c}ound it in a legendary land"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE) {
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE) {
VimPlugin.setEnabled(false)
VimPlugin.setEnabled(true)
VimPlugin.setEnabled(true)
@ -78,7 +78,7 @@ class RegisterActionsTest : VimTestCase() {
val before = "I ${c}found it in a legendary land"
val after = "I f${c}ound it in a legendary land"
var motionRightAction: ActionBeanClass? = null
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE) {
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE) {
motionRightAction = VIM_ACTIONS_EP.extensions().filter { it.actionId == "VimPreviousTabAction" }.findFirst().get()
assertNotNull(getCommandNode())

View File

@ -24,9 +24,9 @@ import com.intellij.openapi.editor.LogicalPosition
import com.intellij.testFramework.EditorTestUtil
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.helper.mode
import com.maddyhome.idea.vim.helper.editorMode
import com.maddyhome.idea.vim.options.OptionConstants
import com.maddyhome.idea.vim.options.OptionScope
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimInt
@ -77,10 +77,10 @@ inline fun waitAndAssert(timeInMillis: Int = 1000, condition: () -> Boolean) {
fun waitAndAssertMode(
fixture: CodeInsightTestFixture,
mode: CommandState.Mode,
mode: VimStateMachine.Mode,
timeInMillis: Int = (VimPlugin.getOptionService().getOptionValue(OptionScope.GLOBAL, OptionConstants.visualdelayName) as VimInt).value + 1000,
) {
waitAndAssert(timeInMillis) { fixture.editor.mode == mode }
waitAndAssert(timeInMillis) { fixture.editor.editorMode == mode }
}
fun assertDoesntChange(timeInMillis: Int = 1000, condition: () -> Boolean) {

View File

@ -50,9 +50,9 @@ import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.action.VimShortcutKeyAction
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.CommandState.SubMode
import com.maddyhome.idea.vim.common.MappingMode
import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.command.VimStateMachine.SubMode
import com.maddyhome.idea.vim.ex.ExException
import com.maddyhome.idea.vim.ex.ExOutputModel.Companion.getInstance
import com.maddyhome.idea.vim.group.visual.VimVisualTimer.swingTimer
@ -61,9 +61,9 @@ import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.GuicursorChangeListener
import com.maddyhome.idea.vim.helper.RunnableHelper.runWriteCommand
import com.maddyhome.idea.vim.helper.TestInputModel
import com.maddyhome.idea.vim.helper.editorMode
import com.maddyhome.idea.vim.helper.getGuiCursorMode
import com.maddyhome.idea.vim.helper.inBlockSubMode
import com.maddyhome.idea.vim.helper.mode
import com.maddyhome.idea.vim.helper.subMode
import com.maddyhome.idea.vim.key.MappingOwner
import com.maddyhome.idea.vim.key.ToKeysMappingInfo
@ -77,7 +77,6 @@ import com.maddyhome.idea.vim.ui.ex.ExEntryPanel
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimFuncref
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimInt
import com.maddyhome.idea.vim.vimscript.parser.errors.IdeavimErrorListener
import com.maddyhome.idea.vim.vimscript.services.VimVariableServiceImpl
import org.assertj.core.api.Assertions
import org.junit.Assert
import java.awt.event.KeyEvent
@ -137,7 +136,7 @@ abstract class VimTestCase : UsefulTestCase() {
}
SelectionVimListenerSuppressor.lock().use { myFixture.tearDown() }
ExEntryPanel.getInstance().deactivate(false)
(VimPlugin.getVariableService() as VimVariableServiceImpl).clear()
VimPlugin.getVariableService().clear()
VimFuncref.lambdaCounter = 0
VimFuncref.anonymousCounter = 0
IdeavimErrorListener.testLogger.clear()
@ -439,8 +438,8 @@ abstract class VimTestCase : UsefulTestCase() {
}
}
fun assertMode(expectedMode: CommandState.Mode) {
val mode = myFixture.editor.mode
fun assertMode(expectedMode: VimStateMachine.Mode) {
val mode = myFixture.editor.editorMode
Assert.assertEquals(expectedMode, mode)
}
@ -505,14 +504,14 @@ abstract class VimTestCase : UsefulTestCase() {
before: String,
after: String,
) {
doTest(keys, before, after, CommandState.Mode.COMMAND, SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, SubMode.NONE)
}
fun doTest(
keys: List<String>,
before: String,
after: String,
modeAfter: CommandState.Mode,
modeAfter: VimStateMachine.Mode,
subModeAfter: SubMode,
) {
doTest(keys.joinToString(separator = ""), before, after, modeAfter, subModeAfter)
@ -522,7 +521,7 @@ abstract class VimTestCase : UsefulTestCase() {
keys: String,
before: String,
after: String,
modeAfter: CommandState.Mode,
modeAfter: VimStateMachine.Mode,
subModeAfter: SubMode,
) {
configureByText(before)
@ -536,7 +535,7 @@ abstract class VimTestCase : UsefulTestCase() {
keys: String,
before: String,
after: String,
modeAfter: CommandState.Mode,
modeAfter: VimStateMachine.Mode,
subModeAfter: SubMode,
fileType: FileType,
) {
@ -554,7 +553,7 @@ abstract class VimTestCase : UsefulTestCase() {
keys: String,
before: String,
after: String,
modeAfter: CommandState.Mode,
modeAfter: VimStateMachine.Mode,
subModeAfter: SubMode,
fileName: String,
) {
@ -568,7 +567,7 @@ abstract class VimTestCase : UsefulTestCase() {
NeovimTesting.assertState(myFixture.editor, this)
}
protected fun performTest(keys: String, after: String, modeAfter: CommandState.Mode, subModeAfter: SubMode) {
protected fun performTest(keys: String, after: String, modeAfter: VimStateMachine.Mode, subModeAfter: SubMode) {
typeText(injector.parser.parseKeys(keys))
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
@Suppress("IdeaVimAssertState")
@ -580,7 +579,7 @@ abstract class VimTestCase : UsefulTestCase() {
keys: List<KeyStroke>,
before: String,
after: String?,
modeAfter: CommandState.Mode,
modeAfter: VimStateMachine.Mode,
subModeAfter: SubMode,
afterEditorInitialized: (Editor) -> Unit,
) {
@ -597,7 +596,7 @@ abstract class VimTestCase : UsefulTestCase() {
NeovimTesting.setRegister(register, keys, this)
}
protected fun assertState(modeAfter: CommandState.Mode, subModeAfter: SubMode) {
protected fun assertState(modeAfter: VimStateMachine.Mode, subModeAfter: SubMode) {
assertMode(modeAfter)
assertSubMode(subModeAfter)
assertCaretsVisualAttributes()

View File

@ -20,7 +20,7 @@ package org.jetbrains.plugins.ideavim.action
import com.intellij.codeInsight.folding.CodeFoldingManager
import com.intellij.codeInsight.folding.impl.FoldingUtil
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.helper.VimBehaviorDiffers
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
@ -33,8 +33,8 @@ class ChangeActionTest : VimTestCase() {
// VIM-620 |i_CTRL-O|
fun testInsertSingleCommandAndInserting() {
doTest(
listOf("i", "<C-O>", "a", "123", "<Esc>", "x"), "abc${c}d\n", "abcd12\n", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
listOf("i", "<C-O>", "a", "123", "<Esc>", "x"), "abc${c}d\n", "abcd12\n", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
@ -42,7 +42,7 @@ class ChangeActionTest : VimTestCase() {
fun testInsertSingleCommandAndNewLineInserting() {
doTest(
listOf("i", "<C-O>", "o", "123", "<Esc>", "x"),
"abc${c}d\n", "abcd\n12\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE
"abc${c}d\n", "abcd\n12\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -50,7 +50,7 @@ class ChangeActionTest : VimTestCase() {
fun testInsertSingleCommandAndNewLineInserting2() {
doTest(
listOf("i", "<C-O>", "v"),
"12${c}345", "12${s}${c}3${se}45", CommandState.Mode.INSERT_VISUAL, CommandState.SubMode.VISUAL_CHARACTER
"12${c}345", "12${s}${c}3${se}45", VimStateMachine.Mode.INSERT_VISUAL, VimStateMachine.SubMode.VISUAL_CHARACTER
)
}
@ -58,7 +58,7 @@ class ChangeActionTest : VimTestCase() {
fun testInsertSingleCommandAndNewLineInserting3() {
doTest(
listOf("i", "<C-O>", "v", "<esc>"),
"12${c}345", "12${c}345", CommandState.Mode.INSERT, CommandState.SubMode.NONE
"12${c}345", "12${c}345", VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -66,7 +66,7 @@ class ChangeActionTest : VimTestCase() {
fun testInsertSingleCommandAndNewLineInserting4() {
doTest(
listOf("i", "<C-O>", "v", "d"),
"12${c}345", "12${c}45", CommandState.Mode.INSERT, CommandState.SubMode.NONE
"12${c}345", "12${c}45", VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -74,7 +74,7 @@ class ChangeActionTest : VimTestCase() {
fun testInsertSingleCommandAndNewLineInserting5() {
doTest(
listOf("i", "<C-O>", "v", "<C-G>"),
"12${c}345", "12${s}3${c}${se}45", CommandState.Mode.INSERT_SELECT, CommandState.SubMode.VISUAL_CHARACTER
"12${c}345", "12${s}3${c}${se}45", VimStateMachine.Mode.INSERT_SELECT, VimStateMachine.SubMode.VISUAL_CHARACTER
)
}
@ -82,7 +82,7 @@ class ChangeActionTest : VimTestCase() {
fun testInsertSingleCommandAndNewLineInserting6() {
doTest(
listOf("i", "<C-O>", "gh"),
"12${c}345", "12${s}3${c}${se}45", CommandState.Mode.INSERT_SELECT, CommandState.SubMode.VISUAL_CHARACTER
"12${c}345", "12${s}3${c}${se}45", VimStateMachine.Mode.INSERT_SELECT, VimStateMachine.SubMode.VISUAL_CHARACTER
)
}
@ -90,7 +90,7 @@ class ChangeActionTest : VimTestCase() {
fun testInsertSingleCommandAndNewLineInserting7() {
doTest(
listOf("i", "<C-O>", "gh", "<esc>"),
"12${c}345", "123${c}45", CommandState.Mode.INSERT, CommandState.SubMode.NONE
"12${c}345", "123${c}45", VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -109,58 +109,58 @@ class ChangeActionTest : VimTestCase() {
fun testInsertSingleCommand() {
doTest(
listOf("i", "def", "<C-O>", "d2h", "x"),
"abc$c.\n", "abcdx.\n", CommandState.Mode.INSERT, CommandState.SubMode.NONE
"abc$c.\n", "abcdx.\n", VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
// VIM-321 |d| |count|
fun testDeleteEmptyRange() {
doTest("d0", "${c}hello\n", "hello\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest("d0", "${c}hello\n", "hello\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-157 |~|
fun testToggleCharCase() {
doTest("~~", "${c}hello world\n", "HEllo world\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest("~~", "${c}hello world\n", "HEllo world\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-157 |~|
fun testToggleCharCaseLineEnd() {
doTest("~~", "hello wor${c}ld\n", "hello worLD\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest("~~", "hello wor${c}ld\n", "hello worLD\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun testToggleCaseMotion() {
doTest("g~w", "${c}FooBar Baz\n", "fOObAR Baz\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest("g~w", "${c}FooBar Baz\n", "fOObAR Baz\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun testChangeUpperCase() {
doTest(
"gUw", "${c}FooBar Baz\n", "FOOBAR Baz\n", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
"gUw", "${c}FooBar Baz\n", "FOOBAR Baz\n", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
fun testChangeLowerCase() {
doTest("guw", "${c}FooBar Baz\n", "foobar Baz\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest("guw", "${c}FooBar Baz\n", "foobar Baz\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun testToggleCaseVisual() {
doTest(
"ve~", "${c}FooBar Baz\n", "fOObAR Baz\n", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
"ve~", "${c}FooBar Baz\n", "fOObAR Baz\n", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
fun testChangeUpperCaseVisual() {
doTest(
"veU", "${c}FooBar Baz\n", "FOOBAR Baz\n", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
"veU", "${c}FooBar Baz\n", "FOOBAR Baz\n", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
fun testChangeLowerCaseVisual() {
doTest(
"veu", "${c}FooBar Baz\n", "foobar Baz\n", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
"veu", "${c}FooBar Baz\n", "foobar Baz\n", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
@ -180,7 +180,7 @@ class ChangeActionTest : VimTestCase() {
four
""".trimIndent(),
CommandState.Mode.INSERT, CommandState.SubMode.NONE
VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -198,7 +198,7 @@ class ChangeActionTest : VimTestCase() {
""".trimIndent(),
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
assertOffset(4)
}
@ -217,8 +217,8 @@ class ChangeActionTest : VimTestCase() {
three
""".trimIndent(),
CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
@ -238,7 +238,7 @@ class ChangeActionTest : VimTestCase() {
three
""".trimIndent(),
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -252,7 +252,7 @@ class ChangeActionTest : VimTestCase() {
"""one
three
""",
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
assertOffset(3)
}
@ -266,16 +266,16 @@ class ChangeActionTest : VimTestCase() {
three four
""".trimIndent(),
"one four\n", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
"one four\n", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
// VIM-1380 |d| |w| |count|
fun testDeleteTwoWordsAtLastChar() {
doTest(
"d2w", "on${c}e two three\n", "on${c}three\n", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
"d2w", "on${c}e two three\n", "on${c}three\n", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
@ -289,8 +289,8 @@ class ChangeActionTest : VimTestCase() {
"""foo
, baz
""",
CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
@ -308,8 +308,8 @@ class ChangeActionTest : VimTestCase() {
baz
""".trimIndent(),
CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
@ -327,7 +327,7 @@ class ChangeActionTest : VimTestCase() {
bar
""".trimIndent(),
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
assertOffset(1)
}
@ -341,7 +341,7 @@ class ChangeActionTest : VimTestCase() {
two
""".trimIndent(),
"two\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE
"two\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -349,8 +349,8 @@ class ChangeActionTest : VimTestCase() {
fun testInsertFromRegister() {
setRegister('a', "World")
doTest(
listOf("A", ", ", "<C-R>", "a", "!"), "${c}Hello\n", "Hello, World!\n", CommandState.Mode.INSERT,
CommandState.SubMode.NONE
listOf("A", ", ", "<C-R>", "a", "!"), "${c}Hello\n", "Hello, World!\n", VimStateMachine.Mode.INSERT,
VimStateMachine.SubMode.NONE
)
}
@ -358,7 +358,7 @@ class ChangeActionTest : VimTestCase() {
fun testInsertNewLineAboveFirstLine() {
doTest(
listOf("O", "bar"),
"fo${c}o\n", "bar\nfoo\n", CommandState.Mode.INSERT, CommandState.SubMode.NONE
"fo${c}o\n", "bar\nfoo\n", VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -366,7 +366,7 @@ class ChangeActionTest : VimTestCase() {
fun testVisualSelectionRightMargin() {
doTest(
listOf("v", "k\$d"),
"foo\n${c}bar\n", "fooar\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE
"foo\n${c}bar\n", "fooar\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -388,7 +388,7 @@ class ChangeActionTest : VimTestCase() {
quux
""".trimIndent(),
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -409,7 +409,7 @@ class ChangeActionTest : VimTestCase() {
quux
""".trimIndent(),
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -424,7 +424,7 @@ quux
""" a 1 b 2 c 3
quux
""",
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -439,7 +439,7 @@ quux
""" a 1 b 2 c 3
quux
""",
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -451,7 +451,7 @@ quux
bar
""".trimIndent(),
"foo bar", CommandState.Mode.COMMAND, CommandState.SubMode.NONE
"foo bar", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -462,7 +462,7 @@ quux
foo
bar
""".trimIndent(),
"foo bar", CommandState.Mode.COMMAND, CommandState.SubMode.NONE
"foo bar", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -477,7 +477,7 @@ quux
""" a 1 b 2 c 3
quux
""",
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -492,14 +492,14 @@ quux
""" a 1 b 2 c 3
quux
""",
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
fun testDeleteCharVisualBlockOnLastCharOfLine() {
doTest(
listOf("<C-V>", "x"),
"fo${c}o\n", "fo\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE
"fo${c}o\n", "fo\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -509,7 +509,7 @@ quux
}
doTest(
listOf("<C-V>", "j", "x"),
"\n\n", "\n\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE
"\n\n", "\n\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -529,7 +529,7 @@ quux
br
""".trimIndent(),
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -550,7 +550,7 @@ quux
br
""".trimIndent(),
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -575,18 +575,18 @@ quux
// |r|
fun testReplaceOneChar() {
doTest("rx", "b${c}ar\n", "b${c}xr\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest("rx", "b${c}ar\n", "b${c}xr\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |r|
@VimBehaviorDiffers(originalVimAfter = "foXX${c}Xr\n")
fun testReplaceMultipleCharsWithCount() {
doTest("3rX", "fo${c}obar\n", "fo${c}XXXr\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest("3rX", "fo${c}obar\n", "fo${c}XXXr\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |r|
fun testReplaceMultipleCharsWithCountPastEndOfLine() {
doTest("6rX", "fo${c}obar\n", "fo${c}obar\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest("6rX", "fo${c}obar\n", "fo${c}obar\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |r|
@ -604,7 +604,7 @@ quux
ZZZZZz
""".trimIndent(),
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -619,7 +619,7 @@ foobaz
bar
foobaz
""",
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -635,20 +635,20 @@ foobaz
r
foobaz
""",
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
// |s|
fun testReplaceOneCharWithText() {
doTest("sxy<Esc>", "b${c}ar\n", "bx${c}yr\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest("sxy<Esc>", "b${c}ar\n", "bx${c}yr\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |s|
fun testReplaceMultipleCharsWithTextWithCount() {
doTest(
"3sxy<Esc>",
"fo${c}obar\n", "fox${c}yr\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE
"fo${c}obar\n", "fox${c}yr\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -666,13 +666,13 @@ foobaz
biff
""".trimIndent(),
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
// |R|
fun testReplaceMode() {
doTest("Rbaz<Esc>", "foo${c}bar\n", "fooba${c}z\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest("Rbaz<Esc>", "foo${c}bar\n", "fooba${c}z\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |R| |i_<Insert>|
@ -680,7 +680,7 @@ foobaz
fun testReplaceModeSwitchToInsertModeAndBack() {
doTest(
"RXXX<Ins>YYY<Ins>ZZZ<Esc>",
"aaa${c}bbbcccddd\n", "aaaXXXYYYZZ${c}Zddd\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE
"aaa${c}bbbcccddd\n", "aaaXXXYYYZZ${c}Zddd\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -689,8 +689,8 @@ foobaz
fun testInsertModeSwitchToReplaceModeAndBack() {
doTest(
"iXXX<Ins>YYY<Ins>ZZZ<Esc>",
"aaa${c}bbbcccddd\n", "aaaXXXYYYZZ${c}Zcccddd\n", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
"aaa${c}bbbcccddd\n", "aaaXXXYYYZZ${c}Zcccddd\n", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
@ -709,7 +709,7 @@ foobaz
fo${c}o quux
""".trimIndent(),
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -917,17 +917,17 @@ and some text after"""
fun testRepeatChangeWordDoesNotBreakNextRepeatFind() {
doTest(
"fXcfYPATATA<Esc>fX.;.", "${c}aaaaXBBBBYaaaaaaaXBBBBYaaaaaaXBBBBYaaaaaaaa\n",
"aaaaPATATAaaaaaaaPATATAaaaaaaPATATAaaaaaaaa\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE
"aaaaPATATAaaaaaaaPATATAaaaaaaPATATAaaaaaaaa\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
fun testRepeatReplace() {
configureByText("${c}foobarbaz spam\n")
typeText(injector.parser.parseKeys("R"))
assertMode(CommandState.Mode.REPLACE)
assertMode(VimStateMachine.Mode.REPLACE)
typeText(injector.parser.parseKeys("FOO" + "<Esc>" + "l" + "2."))
assertState("FOOFOOFO${c}O spam\n")
assertMode(CommandState.Mode.COMMAND)
assertMode(VimStateMachine.Mode.COMMAND)
}
fun testDownMovementAfterDeletionToStart() {
@ -941,8 +941,8 @@ and some text after"""
psum dolor sit amet
${c}lorem ipsum dolor sit amet
""".trimIndent(),
CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
@ -957,8 +957,8 @@ and some text after"""
ipsum dolor sit amet
${c}lorem ipsum dolor sit amet
""".trimIndent(),
CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
@ -973,8 +973,8 @@ and some text after"""
ipsum dolor sit amet
${c}lorem ipsum dolor sit amet
""".trimIndent(),
CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
@ -989,8 +989,8 @@ and some text after"""
ipsum dolor sit amet
${c}lorem ipsum dolor sit amet
""".trimIndent(),
CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
@ -1005,8 +1005,8 @@ and some text after"""
${c}lorem ipsum dolor sit amet
psum dolor sit amet
""".trimIndent(),
CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
@ -1021,8 +1021,8 @@ and some text after"""
${c}lorem ipsum dolor sit amet
ipsum dolor sit amet
""".trimIndent(),
CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
@ -1040,7 +1040,7 @@ and some text after"""
${c}lorem ipsum dolor sit amet
""".trimIndent(),
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -1059,7 +1059,7 @@ and some text after"""
gaganis ${c}gaganis gaganis
""".trimIndent(),
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
@ -1075,7 +1075,7 @@ and some text after"""
line 1
${c}line 3
""".trimIndent(),
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
}

View File

@ -19,7 +19,7 @@
package org.jetbrains.plugins.ideavim.action;
import com.google.common.collect.Lists;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.command.VimStateMachine;
import org.jetbrains.plugins.ideavim.VimTestCase;
/**
@ -27,128 +27,128 @@ import org.jetbrains.plugins.ideavim.VimTestCase;
*/
public class ChangeNumberActionTest extends VimTestCase {
public void testIncrementDecimalZero() {
doTest("<C-A>", "0", "1", CommandState.Mode.COMMAND, CommandState.SubMode.NONE);
doTest("<C-A>", "0", "1", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE);
}
public void testIncrementHexZero() {
doTest("<C-A>", "0x0", "0x1", CommandState.Mode.COMMAND, CommandState.SubMode.NONE);
doTest("<C-A>", "0x0", "0x1", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE);
}
public void testDecrementZero() {
doTest("<C-X>", "0", "-1", CommandState.Mode.COMMAND, CommandState.SubMode.NONE);
doTest("<C-X>", "0", "-1", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE);
}
public void testIncrementDecimal() {
doTest("<C-A>", "199", "200", CommandState.Mode.COMMAND, CommandState.SubMode.NONE);
doTest("<C-A>", "199", "200", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE);
}
public void testDecrementDecimal() {
doTest("<C-X>", "1000", "999", CommandState.Mode.COMMAND, CommandState.SubMode.NONE);
doTest("<C-X>", "1000", "999", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE);
}
public void testIncrementOctal() {
doTest(Lists.newArrayList(":set nf=octal<Enter>", "<C-A>"), "0477", "0500", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE);
doTest(Lists.newArrayList(":set nf=octal<Enter>", "<C-A>"), "0477", "0500", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE);
}
public void testDecrementOctal() {
doTest(Lists.newArrayList(":set nf=octal<Enter>", "<C-X>"), "010", "007", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE);
doTest(Lists.newArrayList(":set nf=octal<Enter>", "<C-X>"), "010", "007", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE);
}
public void testIncrementHex() {
doTest("<C-A>", "0xff", "0x100", CommandState.Mode.COMMAND, CommandState.SubMode.NONE);
doTest("<C-A>", "0xff", "0x100", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE);
}
public void testDecrementHex() {
doTest("<C-X>", "0xa100", "0xa0ff", CommandState.Mode.COMMAND, CommandState.SubMode.NONE);
doTest("<C-X>", "0xa100", "0xa0ff", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE);
}
public void testIncrementNegativeDecimal() {
doTest("<C-A>", "-199", "-198", CommandState.Mode.COMMAND, CommandState.SubMode.NONE);
doTest("<C-A>", "-199", "-198", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE);
}
public void testDecrementNegativeDecimal() {
doTest("<C-X>", "-1000", "-1001", CommandState.Mode.COMMAND, CommandState.SubMode.NONE);
doTest("<C-X>", "-1000", "-1001", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE);
}
public void testIncrementNegativeOctal() {
// Minus isn't processed
doTest(Lists.newArrayList(":set nf=octal<Enter>", "<C-A>"), "-0477", "-0500", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE);
doTest(Lists.newArrayList(":set nf=octal<Enter>", "<C-A>"), "-0477", "-0500", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE);
}
public void testDecrementNegativeOctal() {
// Minus isn't processed
doTest(Lists.newArrayList(":set nf=octal<Enter>", "<C-X>"), "-010", "-007", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE);
doTest(Lists.newArrayList(":set nf=octal<Enter>", "<C-X>"), "-010", "-007", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE);
}
public void testIncrementNegativeHex() {
doTest("<C-A>", "-0xff", "-0x100", CommandState.Mode.COMMAND, CommandState.SubMode.NONE);
doTest("<C-A>", "-0xff", "-0x100", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE);
}
public void testDecrementNegativeHex() {
doTest("<C-X>", "-0xa100", "-0xa0ff", CommandState.Mode.COMMAND, CommandState.SubMode.NONE);
doTest("<C-X>", "-0xa100", "-0xa0ff", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE);
}
public void testIncrementWithCount() {
doTest("123<C-A>", "456", "579", CommandState.Mode.COMMAND, CommandState.SubMode.NONE);
doTest("123<C-A>", "456", "579", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE);
}
public void testDecrementWithCount() {
doTest("200<C-X>", "100", "-100", CommandState.Mode.COMMAND, CommandState.SubMode.NONE);
doTest("200<C-X>", "100", "-100", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE);
}
public void testIncrementAlphaWithoutNumberFormatAlpha() {
doTest("<C-A>", "foo", "foo", CommandState.Mode.COMMAND, CommandState.SubMode.NONE);
doTest("<C-A>", "foo", "foo", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE);
}
public void testIncrementAlphaWithNumberFormatAlpha() {
doTest(Lists.newArrayList(":set nf=alpha<Enter>", "<C-A>"), "foo", "goo", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE);
doTest(Lists.newArrayList(":set nf=alpha<Enter>", "<C-A>"), "foo", "goo", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE);
}
public void testIncrementZWithNumberFormatAlpha() {
doTest(Lists.newArrayList(":set nf=alpha<Enter>", "<C-A>"), "zzz", "zzz", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE);
doTest(Lists.newArrayList(":set nf=alpha<Enter>", "<C-A>"), "zzz", "zzz", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE);
}
public void testIncrementXInHexNumberWithNumberFormatAlphaButNotHex() {
doTest(Lists.newArrayList(":set nf=alpha<Enter>", "<C-A>"), "0<caret>x1", "0y1", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE);
doTest(Lists.newArrayList(":set nf=alpha<Enter>", "<C-A>"), "0<caret>x1", "0y1", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE);
}
public void testIncrementXInHexNumberWithNumberFormatHexAlpha() {
doTest(Lists.newArrayList(":set nf=alpha,hex<Enter>", "<C-A>"), "0<caret>x1", "0x2", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE);
doTest(Lists.newArrayList(":set nf=alpha,hex<Enter>", "<C-A>"), "0<caret>x1", "0x2", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE);
}
public void testIncrementHexNumberWithoutNumberFormatHex() {
doTest(Lists.newArrayList(":set nf=octal<Enter>", "<C-A>"), "0x42", "1x42", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE);
doTest(Lists.newArrayList(":set nf=octal<Enter>", "<C-A>"), "0x42", "1x42", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE);
}
public void testIncrementOctalNumberWithoutNumberFormatOctal() {
doTest(Lists.newArrayList(":set nf=hex<Enter>", "<C-A>"), "077", "078", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE);
doTest(Lists.newArrayList(":set nf=hex<Enter>", "<C-A>"), "077", "078", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE);
}
public void testIncrementNegativeOctalNumberWithoutNumberFormatOctal() {
doTest(Lists.newArrayList(":set nf=hex<Enter>", "<C-A>"), "-077", "-076", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE);
doTest(Lists.newArrayList(":set nf=hex<Enter>", "<C-A>"), "-077", "-076", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE);
}
public void testIncrementHexPreservesCaseOfX() {
doTest("<C-A>", "0X88", "0X89", CommandState.Mode.COMMAND, CommandState.SubMode.NONE);
doTest("<C-A>", "0X88", "0X89", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE);
}
public void testIncrementHexTakesCaseFromLastLetter() {
doTest("<C-A>", "0xaB0", "0xAB1", CommandState.Mode.COMMAND, CommandState.SubMode.NONE);
doTest("<C-A>", "0xaB0", "0xAB1", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE);
}
public void testIncrementLocatesNumberOnTheSameLine() {
doTest("<C-A>", "foo ->* bar 123\n", "foo ->* bar 12<caret>4\n", CommandState.Mode.COMMAND,
CommandState.SubMode.NONE);
doTest("<C-A>", "foo ->* bar 123\n", "foo ->* bar 12<caret>4\n", VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE);
}
}

View File

@ -21,7 +21,7 @@ package org.jetbrains.plugins.ideavim.action;
import com.intellij.openapi.editor.Editor;
import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.api.VimInjectorKt;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.command.VimStateMachine;
import com.maddyhome.idea.vim.register.Register;
import com.maddyhome.idea.vim.ex.ExException;
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString;
@ -129,7 +129,7 @@ public class CopyActionTest extends VimTestCase {
public void testStateAfterYankVisualBlock() {
typeTextInFile(VimInjectorKt.getInjector().getParser().parseKeys("<C-V>" + "jl" + "y"), "<caret>foo\n" + "bar\n");
assertOffset(0);
assertMode(CommandState.Mode.COMMAND);
assertMode(VimStateMachine.Mode.COMMAND);
assertSelection(null);
}

View File

@ -19,7 +19,7 @@
package org.jetbrains.plugins.ideavim.action
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.helper.experimentalApi
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
@ -154,7 +154,7 @@ class GuardedBlocksTest : VimTestCase() {
1234567890
""".trimIndent()
)
assertMode(CommandState.Mode.INSERT)
assertMode(VimStateMachine.Mode.INSERT)
}
@TestWithoutNeovim(reason = SkipNeovimReason.GUARDED_BLOCKS)
@ -176,7 +176,7 @@ class GuardedBlocksTest : VimTestCase() {
1234567890
""".trimIndent()
)
assertMode(CommandState.Mode.INSERT)
assertMode(VimStateMachine.Mode.INSERT)
}
@TestWithoutNeovim(reason = SkipNeovimReason.GUARDED_BLOCKS)
@ -198,7 +198,7 @@ class GuardedBlocksTest : VimTestCase() {
1234567890
""".trimIndent()
)
assertMode(CommandState.Mode.INSERT)
assertMode(VimStateMachine.Mode.INSERT)
}
/*
@ -255,7 +255,7 @@ class GuardedBlocksTest : VimTestCase() {
$c
""".trimIndent()
)
assertMode(CommandState.Mode.INSERT)
assertMode(VimStateMachine.Mode.INSERT)
}
@TestWithoutNeovim(reason = SkipNeovimReason.GUARDED_BLOCKS)
@ -274,7 +274,7 @@ class GuardedBlocksTest : VimTestCase() {
1234567890
""".trimIndent()
)
assertMode(CommandState.Mode.COMMAND)
assertMode(VimStateMachine.Mode.COMMAND)
}
@TestWithoutNeovim(reason = SkipNeovimReason.GUARDED_BLOCKS)
@ -294,7 +294,7 @@ class GuardedBlocksTest : VimTestCase() {
1234567890
""".trimIndent()
)
assertMode(CommandState.Mode.COMMAND)
assertMode(VimStateMachine.Mode.COMMAND)
}
@TestWithoutNeovim(reason = SkipNeovimReason.GUARDED_BLOCKS)
@ -315,7 +315,7 @@ class GuardedBlocksTest : VimTestCase() {
1234567890
""".trimIndent()
)
assertMode(CommandState.Mode.INSERT)
assertMode(VimStateMachine.Mode.INSERT)
}
@TestWithoutNeovim(reason = SkipNeovimReason.GUARDED_BLOCKS)
@ -335,6 +335,6 @@ class GuardedBlocksTest : VimTestCase() {
1234567890
""".trimIndent()
)
assertMode(CommandState.Mode.COMMAND)
assertMode(VimStateMachine.Mode.COMMAND)
}
}

View File

@ -20,7 +20,7 @@ package org.jetbrains.plugins.ideavim.action
import com.intellij.testFramework.PlatformTestUtil
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.helper.commandState
import com.maddyhome.idea.vim.helper.vimStateMachine
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.options.OptionConstants
import com.maddyhome.idea.vim.options.OptionScope
@ -36,7 +36,7 @@ class MacroActionTest : VimTestCase() {
// |q|
fun testRecordMacro() {
val editor = typeTextInFile(injector.parser.parseKeys("qa" + "3l" + "q"), "on<caret>e two three\n")
val commandState = editor.vim.commandState
val commandState = editor.vim.vimStateMachine
assertFalse(commandState.isRecording)
val registerGroup = VimPlugin.getRegister()
val register = registerGroup.getRegister('a')

View File

@ -21,7 +21,7 @@ package org.jetbrains.plugins.ideavim.action;
import com.google.common.collect.Lists;
import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.api.VimInjectorKt;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.command.VimStateMachine;
import com.maddyhome.idea.vim.mark.Mark;
import com.maddyhome.idea.vim.newapi.IjVimEditor;
import org.jetbrains.plugins.ideavim.SkipNeovimReason;
@ -148,6 +148,6 @@ public class MarkTest extends VimTestCase {
// |i| |`]|
public void testGotoLastChangePositionEnd() {
doTest(Lists.newArrayList("yiw", "P", "gg", "`]"), "one two\n" + "<caret>three\n" + "four five\n",
"one two\n" + "thre<caret>ethree\n" + "four five\n", CommandState.Mode.COMMAND, CommandState.SubMode.NONE);
"one two\n" + "thre<caret>ethree\n" + "four five\n", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE);
}
}

View File

@ -19,8 +19,8 @@ package org.jetbrains.plugins.ideavim.action
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.helper.vimCommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.helper.vimStateMachine
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase
@ -31,7 +31,7 @@ import org.jetbrains.plugins.ideavim.VimTestCase
class MotionActionTest : VimTestCase() {
fun testDoubleToggleVisual() {
val contents = "one tw${c}o\n"
doTest("vv", contents, contents, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest("vv", contents, contents, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-198 |v_iw|
@ -41,8 +41,8 @@ class MotionActionTest : VimTestCase() {
"viw",
fileContents,
"one ${s}two${se}\n",
CommandState.Mode.VISUAL,
CommandState.SubMode.VISUAL_CHARACTER
VimStateMachine.Mode.VISUAL,
VimStateMachine.SubMode.VISUAL_CHARACTER
)
}
@ -50,7 +50,7 @@ class MotionActionTest : VimTestCase() {
fun testVisualMotionInnerBigWord() {
val fileContents = "one tw${c}o.three four\n"
val fileContentsAfter = "one ${s}two.thre${c}e$se four\n"
doTest("viW", fileContents, fileContentsAfter, CommandState.Mode.VISUAL, CommandState.SubMode.VISUAL_CHARACTER)
doTest("viW", fileContents, fileContentsAfter, VimStateMachine.Mode.VISUAL, VimStateMachine.SubMode.VISUAL_CHARACTER)
assertSelection("two.three")
}
@ -60,7 +60,7 @@ class MotionActionTest : VimTestCase() {
three
""".trimIndent()
doTest(listOf("f", "<Esc>", "<Esc>"), content, content, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(listOf("f", "<Esc>", "<Esc>"), content, content, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
assertPluginError(true)
assertOffset(2)
}
@ -71,9 +71,9 @@ class MotionActionTest : VimTestCase() {
three
""".trimIndent()
doTest(listOf("12", "<Esc>"), content, content, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(listOf("12", "<Esc>"), content, content, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
assertPluginError(false)
val vimCommandState = myFixture.editor.vimCommandState
val vimCommandState = myFixture.editor.vimStateMachine
kotlin.test.assertNotNull(vimCommandState)
assertEmpty(vimCommandState.commandBuilder.keys.toList())
}
@ -82,7 +82,7 @@ class MotionActionTest : VimTestCase() {
fun testLeftRightMove() {
val before = "on${c}e two three four five six seven\n"
val after = "one two three ${c}four five six seven\n"
doTest(listOf("14l", "2h"), before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(listOf("14l", "2h"), before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |j| |k|
@ -101,7 +101,7 @@ class MotionActionTest : VimTestCase() {
four
""".trimIndent()
doTest(listOf("2j", "k"), before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(listOf("2j", "k"), before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
@TestWithoutNeovim(reason = SkipNeovimReason.UNCLEAR)
@ -114,14 +114,14 @@ class MotionActionTest : VimTestCase() {
fun testForwardToTab() {
val before = "on${c}e two\tthree\nfour\n"
val after = "one two${c}\tthree\nfour\n"
doTest(listOf("f<Tab>"), before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(listOf("f<Tab>"), before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
@TestWithoutNeovim(reason = SkipNeovimReason.UNCLEAR)
fun testIllegalCharArgument() {
typeTextInFile(injector.parser.parseKeys("f<Insert>"), "on${c}e two three four five six seven\n")
assertOffset(2)
assertMode(CommandState.Mode.COMMAND)
assertMode(VimStateMachine.Mode.COMMAND)
}
// |F| |i_CTRL-K|
@ -129,7 +129,7 @@ class MotionActionTest : VimTestCase() {
val before = "Hallo, Öster${c}reich!\n"
val after = "Hallo, ${c}Österreich!\n"
val keys = listOf("F<C-K>O:")
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-771 |t| |;|
@ -137,7 +137,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("t:;")
val before = "$c 1:a 2:b 3:c \n"
val after = " 1:a ${c}2:b 3:c \n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-771 |t| |;|
@ -145,7 +145,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("t:;")
val before = "$c 1:a 2:b 3:c \n"
val after = " 1:a ${c}2:b 3:c \n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-771 |t| |;|
@ -153,7 +153,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("t:2;")
val before = "$c 1:a 2:b 3:c \n"
val after = " 1:a ${c}2:b 3:c \n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-771 |t| |;|
@ -161,7 +161,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("t:3;")
val before = "$c 1:a 2:b 3:c \n"
val after = " 1:a 2:b ${c}3:c \n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-771 |t| |,|
@ -169,7 +169,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("t:,,")
val before = " 1:a 2:b$c 3:c \n"
val after = " 1:${c}a 2:b 3:c \n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-771 |t| |,|
@ -177,7 +177,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("t:,2,")
val before = " 1:a 2:b$c 3:c \n"
val after = " 1:${c}a 2:b 3:c \n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-771 |t| |,|
@ -185,7 +185,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("t:,3,")
val before = " 0:_ 1:a 2:b$c 3:c \n"
val after = " 0:${c}_ 1:a 2:b 3:c \n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-314 |d| |v_iB|
@ -193,7 +193,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("di{")
val before = "{foo, b${c}ar, baz}\n"
val after = "{}\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-314 |d| |v_iB|
@ -201,7 +201,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("di{")
val before = "{foo, ${c}\"bar\", baz}\n"
val after = "{}\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |d| |v_aB|
@ -209,7 +209,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("da{")
val before = "x = {foo, b${c}ar, baz};\n"
val after = "x = ;\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-261 |c| |v_iB|
@ -238,7 +238,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("daw")
val before = "one t${c}wo three\n"
val after = "one three\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |d| |v_aW|
@ -246,7 +246,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("daW")
val before = "one \"t${c}wo\" three\n"
val after = "one three\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |d| |v_is|
@ -254,7 +254,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("dis")
val before = "Hello World! How a${c}re you? Bye.\n"
val after = "Hello World! Bye.\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |d| |v_as|
@ -262,7 +262,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("das")
val before = "Hello World! How a${c}re you? Bye.\n"
val after = "Hello World! Bye.\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |v_as|
@ -280,7 +280,7 @@ class MotionActionTest : VimTestCase() {
P$c.
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |d| |v_ip|
@ -302,7 +302,7 @@ class MotionActionTest : VimTestCase() {
Bye.
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |d| |v_ap|
@ -323,7 +323,7 @@ class MotionActionTest : VimTestCase() {
Bye.
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |d| |v_a]|
@ -336,7 +336,7 @@ class MotionActionTest : VimTestCase() {
];
"""
val after = "foo = ;\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |d| |v_i]|
@ -344,7 +344,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("di]")
val before = "foo = [one, t${c}wo];\n"
val after = "foo = [];\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-1287 |d| |v_i(|
@ -352,7 +352,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("di(")
val before = "(text \"with quotes(and ${c}braces)\")"
val after = "(text \"with quotes()\")"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-1287 |d| |v_i{|
@ -360,7 +360,7 @@ class MotionActionTest : VimTestCase() {
val before = "{\"{foo, ${c}bar\", baz}}"
val keys = listOf("di{")
val after = "{\"{foo, ${c}bar\", baz}}"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-1287 |d| |v_i{|
@ -368,7 +368,7 @@ class MotionActionTest : VimTestCase() {
val before = "a{\"{foo}, ${c}bar\", baz}b}"
val keys = listOf("di{")
val after = "a{$c}b}"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-1008 |c| |v_i{|
@ -376,7 +376,7 @@ class MotionActionTest : VimTestCase() {
val before = "\"{do${c}esn't work}\""
val keys = listOf("ci{")
val after = "\"{$c}\""
doTest(keys, before, after, CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
}
// VIM-1008 |c| |v_i{|
@ -384,7 +384,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("ci{")
val before = "'{does n${c}ot work}'"
val after = "'{$c}'"
doTest(keys, before, after, CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
}
// VIM-1008 |c| |v_i{|
@ -392,7 +392,7 @@ class MotionActionTest : VimTestCase() {
val before = "<p class=\"{{ \$ctrl.so${c}meClassName }}\"></p>"
val keys = listOf("ci{")
val after = "<p class=\"{{$c}}\"></p>"
doTest(keys, before, after, CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
}
// |d| |v_i>|
@ -400,7 +400,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("di>")
val before = "Foo<Foo, B${c}ar> bar\n"
val after = "Foo<> bar\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |d| |v_a>|
@ -408,7 +408,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("da>")
val before = "Foo<Foo, B${c}ar> bar\n"
val after = "Foo bar\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-132 |d| |v_i"|
@ -416,7 +416,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("di\"")
val before = "foo = \"bar b${c}az\";\n"
val after = "foo = \"\";\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-132 |d| |v_a"|
@ -425,7 +425,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("da\"")
val before = "foo = \"bar b${c}az\";\n"
val after = "foo = ;\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-132 |d| |v_i"|
@ -433,7 +433,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("di\"")
val before = "foo = [\"one\", ${c}\"two\", \"three\"];\n"
val after = "foo = [\"one\", \"\", \"three\"];\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-132 |d| |v_i"|
@ -441,7 +441,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("di\"")
val before = "foo = [\"one\", \"two${c}\", \"three\"];\n"
val after = "foo = [\"one\", \"\", \"three\"];\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-132 |d| |v_i"|
@ -449,7 +449,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("di\"")
val before = "foo = \"fo\\\"o b${c}ar\";\n"
val after = "foo = \"\";\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-132 |d| |v_i"|
@ -457,35 +457,35 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("di\"")
val before = "f${c}oo = [\"one\", \"two\", \"three\"];\n"
val after = "foo = [\"\", \"two\", \"three\"];\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun testDeleteDoubleQuotedStringOddNumberOfQuotes() {
val keys = listOf("di\"")
val before = "abc\"def${c}\"gh\"i"
val after = "abc\"\"gh\"i"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun testDeleteDoubleQuotedStringBetweenEvenNumberOfQuotes() {
val keys = listOf("di\"")
val before = "abc\"def\"g${c}h\"ijk\"l"
val after = "abc\"def\"\"ijk\"l"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun testDeleteDoubleQuotedStringOddNumberOfQuotesOnLast() {
val keys = listOf("di\"")
val before = "abcdef\"gh\"ij${c}\"kl"
val after = "abcdef\"gh\"ij\"kl"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun testDeleteDoubleQuotedStringEvenNumberOfQuotesOnLast() {
val keys = listOf("di\"")
val before = "abc\"def\"gh\"ij${c}\"kl"
val after = "abc\"def\"gh\"\"kl"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-132 |v_i"|
@ -493,7 +493,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("vi\"")
val before = "foo = [\"o${c}ne\", \"two\"];\n"
val after = "foo = [\"${s}on${c}e${se}\", \"two\"];\n"
doTest(keys, before, after, CommandState.Mode.VISUAL, CommandState.SubMode.VISUAL_CHARACTER)
doTest(keys, before, after, VimStateMachine.Mode.VISUAL, VimStateMachine.SubMode.VISUAL_CHARACTER)
}
// |c| |v_i"|
@ -501,7 +501,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("ci\"")
val before = "foo = \"${c}\";\n"
val after = "foo = \"\";\n"
doTest(keys, before, after, CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
}
// VIM-132 |d| |v_i'|
@ -509,7 +509,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("di'")
val before = "foo = 'bar b${c}az';\n"
val after = "foo = '';\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-132 |d| |v_i`|
@ -517,7 +517,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("di`")
val before = "foo = `bar b${c}az`;\n"
val after = "foo = ``;\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-132 |d| |v_a'|
@ -526,7 +526,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("da'")
val before = "foo = 'bar b${c}az';\n"
val after = "foo = ;\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-132 |d| |v_a`|
@ -535,7 +535,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("da`")
val before = "foo = `bar b${c}az`;\n"
val after = "foo = ;\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-1427
@ -543,7 +543,7 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("d2at")
val before = "<a><b><c>$c</c></b></a>"
val after = "<a></a>"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-2113
@ -551,14 +551,14 @@ class MotionActionTest : VimTestCase() {
val keys = listOf("cit")
val before = "<a><c>$c</c></a>"
val after = "<a><c></c></a>"
doTest(keys, before, after, CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
}
fun testDeleteToDigraph() {
val keys = listOf("d/<C-K>O:<CR>")
val before = "ab${c}cdÖef"
val after = "abÖef"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |[(|
@ -801,7 +801,7 @@ two
val keys = listOf("viw", "<Esc>", "0", "viw", "gv", "d")
val before = "foo ${c}bar\n"
val after = "foo \n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |CTRL-V|
@ -817,7 +817,7 @@ two
${s}ba${se}r
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.VISUAL, CommandState.SubMode.VISUAL_BLOCK)
doTest(keys, before, after, VimStateMachine.Mode.VISUAL, VimStateMachine.SubMode.VISUAL_BLOCK)
}
// |CTRL-V|
@ -833,7 +833,7 @@ two
b${s}ar$se
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.VISUAL, CommandState.SubMode.VISUAL_BLOCK)
doTest(keys, before, after, VimStateMachine.Mode.VISUAL, VimStateMachine.SubMode.VISUAL_BLOCK)
}
// |CTRL-V|
@ -851,7 +851,7 @@ two
a${s}b$se
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.VISUAL, CommandState.SubMode.VISUAL_BLOCK)
doTest(keys, before, after, VimStateMachine.Mode.VISUAL, VimStateMachine.SubMode.VISUAL_BLOCK)
}
// |v_o|
@ -859,7 +859,7 @@ two
val keys = listOf("v", "l", "o", "l", "d")
val before = "${c}foo\n"
val after = "fo\n"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// VIM-564 |g_|
@ -880,8 +880,8 @@ two
four
""".trimIndent(),
CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
@ -903,8 +903,8 @@ two
four
""".trimIndent(),
CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
@ -924,7 +924,7 @@ two
bar
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
// |v_>| |gv|
@ -948,7 +948,7 @@ two
""".trimIndent()
)
typeText(injector.parser.parseKeys(">"))
assertMode(CommandState.Mode.COMMAND)
assertMode(VimStateMachine.Mode.COMMAND)
assertState(
""" foo
bar
@ -963,7 +963,7 @@ two
"""
)
typeText(injector.parser.parseKeys(">"))
assertMode(CommandState.Mode.COMMAND)
assertMode(VimStateMachine.Mode.COMMAND)
assertState(
""" foo
bar
@ -992,7 +992,7 @@ two
bar
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.VISUAL, CommandState.SubMode.VISUAL_CHARACTER)
doTest(keys, before, after, VimStateMachine.Mode.VISUAL, VimStateMachine.SubMode.VISUAL_CHARACTER)
}
fun testVisualLineSelectDown() {
@ -1006,7 +1006,7 @@ two
""".trimIndent()
)
assertMode(CommandState.Mode.VISUAL)
assertMode(VimStateMachine.Mode.VISUAL)
assertSelection(
"""
bar
@ -1029,7 +1029,7 @@ two
""".trimIndent()
)
assertMode(CommandState.Mode.VISUAL)
assertMode(VimStateMachine.Mode.VISUAL)
assertSelection(
"""
bar

File diff suppressed because it is too large Load Diff

View File

@ -20,8 +20,8 @@ package org.jetbrains.plugins.ideavim.action
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.common.MappingMode
import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.key.MappingOwner
import junit.framework.TestCase
import org.jetbrains.plugins.ideavim.SkipNeovimReason
@ -35,7 +35,7 @@ class ResetModeActionTest : VimTestCase() {
val keys = "<C-\\><C-N>"
val before = "A Discovery"
val after = "A Discovery"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}
@ -43,7 +43,7 @@ class ResetModeActionTest : VimTestCase() {
val keys = listOf("i", "<C-\\><C-N>")
val before = "A Discovery"
val after = "A Discovery"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}
@ -51,7 +51,7 @@ class ResetModeActionTest : VimTestCase() {
val keys = listOf("i", "<C-\\><C-N>")
val before = "A Disc${c}overy"
val after = "A Dis${c}covery"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}
@ -59,7 +59,7 @@ class ResetModeActionTest : VimTestCase() {
val keys = listOf("i", "<C-\\><C-N>", "3l")
val before = "${c}A Discovery"
val after = "A D${c}iscovery"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}
@ -67,7 +67,7 @@ class ResetModeActionTest : VimTestCase() {
val keys = listOf("V", "<C-\\><C-N>")
val before = "A Discovery"
val after = "A Discovery"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}
@ -75,7 +75,7 @@ class ResetModeActionTest : VimTestCase() {
val keys = listOf("gH", "<C-\\><C-N>")
val before = "A Discovery"
val after = "A Discovery"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}
@ -83,7 +83,7 @@ class ResetModeActionTest : VimTestCase() {
val keys = listOf("d", "<C-\\><C-N>")
val before = "A Discovery"
val after = "A Discovery"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}
@ -91,7 +91,7 @@ class ResetModeActionTest : VimTestCase() {
val keys = "d<Esc>dw"
val before = "A Discovery"
val after = "Discovery"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}
@ -99,7 +99,7 @@ class ResetModeActionTest : VimTestCase() {
val keys = listOf("d", "<C-\\><C-N>", "dw")
val before = "A Discovery"
val after = "Discovery"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}
@ -107,7 +107,7 @@ class ResetModeActionTest : VimTestCase() {
val keys = listOf("d", "<Esc>", "dw")
val before = "A Discovery"
val after = "Discovery"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}
@ -115,7 +115,7 @@ class ResetModeActionTest : VimTestCase() {
val keys = listOf("d", "<C-[>", "dw")
val before = "A Discovery"
val after = "Discovery"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}
@ -127,7 +127,7 @@ class ResetModeActionTest : VimTestCase() {
val keys = listOf("d", "<C-D>", "dw")
val before = "A Discovery"
val after = "Discovery"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}
@ -135,7 +135,7 @@ class ResetModeActionTest : VimTestCase() {
val keys = listOf("c", "<C-\\><C-N>", "another")
val before = "A Discovery"
val after = "Another Discovery"
doTest(keys, before, after, CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}
@ -143,7 +143,7 @@ class ResetModeActionTest : VimTestCase() {
val keys = "dt<esc>D"
val before = "A ${c}Discovery"
val after = "A "
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}
}

View File

@ -18,7 +18,7 @@
package org.jetbrains.plugins.ideavim.action.change
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.helper.VimBehaviorDiffers
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
@ -43,7 +43,7 @@ class RepeatChangeActionTest : VimTestCase() {
where it was settled on some sodden sand
hard by the torrent of a mountain pass.
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun `test simple repeat with dollar motion`() {
@ -64,7 +64,7 @@ class RepeatChangeActionTest : VimTestCase() {
where it was settled on some sodden sand
hard by the torrent of a mountain pass.
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun `test repeat to line end`() {
@ -85,7 +85,7 @@ class RepeatChangeActionTest : VimTestCase() {
where it was settled on some sodden sand
hard by the torrent of a mountain pass.
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
@VimBehaviorDiffers(description = "Different caret position")
@ -107,7 +107,7 @@ class RepeatChangeActionTest : VimTestCase() {
whe${c}XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXX by the torrent of a mountain pass.
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun `test count doesn't affect repeat`() {
@ -128,7 +128,7 @@ class RepeatChangeActionTest : VimTestCase() {
where it was settled on some sodden sand
hard by the torrent of a mountain pass.
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
@TestWithoutNeovim(SkipNeovimReason.MULTICARET)
@ -150,7 +150,7 @@ class RepeatChangeActionTest : VimTestCase() {
where XXXXXX settled on some sodden sand
${c}XXXXXXy the torrent of a mountain pass.
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun `test line motion`() {
@ -171,7 +171,7 @@ class RepeatChangeActionTest : VimTestCase() {
where it was settled on some sodden sand
hard by the torrent of a mountain pass.
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
@VimBehaviorDiffers(description = "Wrong caret position")
@ -193,7 +193,7 @@ class RepeatChangeActionTest : VimTestCase() {
where it was settled on some sodden sand
${c}XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
@VimBehaviorDiffers(description = "Wrong caret position")
@ -215,7 +215,7 @@ class RepeatChangeActionTest : VimTestCase() {
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
@VimBehaviorDiffers(description = "Wrong caret position")
@ -237,7 +237,7 @@ class RepeatChangeActionTest : VimTestCase() {
wherXXXt was settled on some sodden sand
hard by the torrent of a mountain pass.
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
@VimBehaviorDiffers(
@ -271,7 +271,7 @@ class RepeatChangeActionTest : VimTestCase() {
XXXXX${c}Xy the torrent of a mountain pass.
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
@TestWithoutNeovim(SkipNeovimReason.UNCLEAR)
@ -293,7 +293,7 @@ class RepeatChangeActionTest : VimTestCase() {
${c}XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun `test repeat with count`() {
@ -314,7 +314,7 @@ class RepeatChangeActionTest : VimTestCase() {
where it was settled on some sodden sand
hard by the torrent of a mountain pass.
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun `test redo register feature`() {
@ -331,7 +331,7 @@ class RepeatChangeActionTest : VimTestCase() {
One
""".trimIndent(),
CommandState.Mode.COMMAND, CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE
)
}
}

View File

@ -18,7 +18,7 @@
package org.jetbrains.plugins.ideavim.action.change
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import org.jetbrains.plugins.ideavim.VimTestCase
class UndoActionTest : VimTestCase() {
@ -33,7 +33,7 @@ class UndoActionTest : VimTestCase() {
hard by the torrent of a mountain pass.
""".trimIndent()
val after = before
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
val editor = myFixture.editor
assertFalse(editor.caretModel.primaryCaret.hasSelection())
}
@ -49,7 +49,7 @@ class UndoActionTest : VimTestCase() {
hard by the torrent of a mountain pass.
""".trimIndent()
val after = before
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
assertFalse(hasSelection())
}
@ -71,7 +71,7 @@ class UndoActionTest : VimTestCase() {
where it was settled on some sodden sand
hard by the torrent of a mountain pass.
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
assertFalse(hasSelection())
}
@ -88,12 +88,12 @@ class UndoActionTest : VimTestCase() {
val after = """
A Discovery
I1 found${c} it in a legendary land
I1 found$c it in a legendary land
all rocks and lavender and tufted grass,
where it was settled on some sodden sand
hard by the torrent of a mountain pass.
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
assertFalse(hasSelection())
}
@ -101,4 +101,4 @@ class UndoActionTest : VimTestCase() {
val editor = myFixture.editor
return editor.caretModel.primaryCaret.hasSelection()
}
}
}

View File

@ -18,7 +18,7 @@
package org.jetbrains.plugins.ideavim.action.change.change
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import org.jetbrains.plugins.ideavim.VimTestCase
class ChangeLineActionTest : VimTestCase() {
@ -26,14 +26,14 @@ class ChangeLineActionTest : VimTestCase() {
setupChecks {
this.neoVim.ignoredRegisters = setOf('1', '"')
}
doTest("cc", "", "", CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest("cc", "", "", VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
}
fun `test on empty file with S`() {
setupChecks {
this.neoVim.ignoredRegisters = setOf('1', '"')
}
doTest("S", "", "", CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest("S", "", "", VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
}
fun `test on last line with S`() {
@ -47,7 +47,7 @@ class ChangeLineActionTest : VimTestCase() {
I found it in a legendary land
$c
""".trimIndent(),
CommandState.Mode.INSERT, CommandState.SubMode.NONE
VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -64,7 +64,7 @@ class ChangeLineActionTest : VimTestCase() {
$c
""".trimIndent(),
CommandState.Mode.INSERT, CommandState.SubMode.NONE
VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -79,7 +79,7 @@ class ChangeLineActionTest : VimTestCase() {
I found it in a legendary land
$c
""".trimIndent(),
CommandState.Mode.INSERT, CommandState.SubMode.NONE
VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -96,7 +96,7 @@ class ChangeLineActionTest : VimTestCase() {
$c
""".trimIndent(),
CommandState.Mode.INSERT, CommandState.SubMode.NONE
VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -111,7 +111,7 @@ class ChangeLineActionTest : VimTestCase() {
$c
all rocks and lavender and tufted grass,
""".trimIndent(),
CommandState.Mode.INSERT, CommandState.SubMode.NONE
VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -128,7 +128,7 @@ class ChangeLineActionTest : VimTestCase() {
$c
""".trimIndent(),
CommandState.Mode.INSERT, CommandState.SubMode.NONE
VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -145,7 +145,7 @@ class ChangeLineActionTest : VimTestCase() {
all rocks and lavender and tufted grass,
$c
""".trimIndent(),
CommandState.Mode.INSERT, CommandState.SubMode.NONE
VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -182,7 +182,7 @@ class ChangeLineActionTest : VimTestCase() {
that priceless mote now dimpling the convex
and limpid teardrop on a lighted slide.
""".trimIndent(),
CommandState.Mode.INSERT, CommandState.SubMode.NONE
VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
}

View File

@ -20,18 +20,18 @@
package org.jetbrains.plugins.ideavim.action.change.change
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import org.jetbrains.plugins.ideavim.VimTestCase
class ChangeMotionActionTest : VimTestCase() {
// VIM-515 |c| |W|
fun `test change big word with punctuation and alpha`() {
doTest("cW", "foo${c}(bar baz\n", "foo baz\n", CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest("cW", "foo${c}(bar baz\n", "foo baz\n", VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
}
// VIM-300 |c| |w|
fun testChangeWordTwoWordsWithoutWhitespace() {
doTest("cw", "${c}\$value\n", "value\n", CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest("cw", "${c}\$value\n", "value\n", VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
}
// VIM-296 |cc|
@ -39,7 +39,7 @@ class ChangeMotionActionTest : VimTestCase() {
doTest(
"cc",
"foo\n" + "${c}bar\n",
"foo\n${c}" + "\n", CommandState.Mode.INSERT, CommandState.SubMode.NONE
"foo\n${c}" + "\n", VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -57,7 +57,7 @@ class ChangeMotionActionTest : VimTestCase() {
....${c}
}
""".trimIndent().dotToSpace(),
CommandState.Mode.INSERT, CommandState.SubMode.NONE
VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -66,7 +66,7 @@ class ChangeMotionActionTest : VimTestCase() {
doTest(
"ccbaz",
"${c}foo\n" + "bar\n",
"baz\n" + "bar\n", CommandState.Mode.INSERT, CommandState.SubMode.NONE
"baz\n" + "bar\n", VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -83,7 +83,7 @@ class ChangeMotionActionTest : VimTestCase() {
${c}
""".trimIndent(),
CommandState.Mode.INSERT, CommandState.SubMode.NONE
VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -91,23 +91,23 @@ class ChangeMotionActionTest : VimTestCase() {
doTest(
"c_baz",
"${c}foo\n" + "bar\n",
"baz\n" + "bar\n", CommandState.Mode.INSERT, CommandState.SubMode.NONE
"baz\n" + "bar\n", VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
// VIM-200 |c| |w|
fun testChangeWordAtLastChar() {
doTest(
"cw", "on${c}e two three\n", "on${c} two three\n", CommandState.Mode.INSERT,
CommandState.SubMode.NONE
"cw", "on${c}e two three\n", "on${c} two three\n", VimStateMachine.Mode.INSERT,
VimStateMachine.SubMode.NONE
)
}
// VIM-1380 |c| |w| |count|
fun testChangeTwoWordsAtLastChar() {
doTest(
"c2w", "on${c}e two three\n", "on${c} three\n", CommandState.Mode.INSERT,
CommandState.SubMode.NONE
"c2w", "on${c}e two three\n", "on${c} three\n", VimStateMachine.Mode.INSERT,
VimStateMachine.SubMode.NONE
)
}
@ -125,15 +125,15 @@ class ChangeMotionActionTest : VimTestCase() {
}
""".trimIndent(),
CommandState.Mode.INSERT, CommandState.SubMode.NONE
VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
// VIM-276 |c| |T|
fun testChangeLinesTillBackwards() {
doTest(
"cT(", "if (condition) ${c}{\n" + "}\n", "if ({\n" + "}\n", CommandState.Mode.INSERT,
CommandState.SubMode.NONE
"cT(", "if (condition) ${c}{\n" + "}\n", "if ({\n" + "}\n", VimStateMachine.Mode.INSERT,
VimStateMachine.SubMode.NONE
)
}
@ -143,7 +143,7 @@ class ChangeMotionActionTest : VimTestCase() {
doTest(
"cFc",
"if (condition) {${c}\n" + "}\n",
"if (\n" + "}\n", CommandState.Mode.INSERT, CommandState.SubMode.NONE
"if (\n" + "}\n", VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -151,7 +151,7 @@ class ChangeMotionActionTest : VimTestCase() {
fun testChangeLastWordInLine() {
doTest(
"cw",
"ab.${c}cd\n", "ab.${c}\n", CommandState.Mode.INSERT, CommandState.SubMode.NONE
"ab.${c}cd\n", "ab.${c}\n", VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
@ -159,16 +159,16 @@ class ChangeMotionActionTest : VimTestCase() {
fun testChangeLastInnerWordInLine() {
doTest(
listOf("c", "iw", "baz"),
"foo bar bo${c}o\n", "foo bar baz\n", CommandState.Mode.INSERT, CommandState.SubMode.NONE
"foo bar bo${c}o\n", "foo bar baz\n", VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE
)
}
// VIM-421 |c| |w|
fun testChangeLastCharInLine() {
doTest("cw", "fo${c}o\n", "fo${c}\n", CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest("cw", "fo${c}o\n", "fo${c}\n", VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
}
fun testLastSymbolInWord() {
doTest("cw", "fo${c}o", "fo${c}", CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest("cw", "fo${c}o", "fo${c}", VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
}
}

View File

@ -21,7 +21,7 @@
package org.jetbrains.plugins.ideavim.action.change.change
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.helper.VimBehaviorDiffers
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
@ -45,7 +45,7 @@ class ChangeVisualActionTest : VimTestCase() {
where it was settled on some sodden sand
hard by the torrent of a mountain pass.
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun `test multiple line change in text middle`() {
@ -65,7 +65,7 @@ class ChangeVisualActionTest : VimTestCase() {
where it was settled on some sodden sand
hard by the torrent of a mountain pass.
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
}
@VimBehaviorDiffers(
@ -97,7 +97,7 @@ class ChangeVisualActionTest : VimTestCase() {
${c}
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
}
fun `test multiple line change till the end with two new lines`() {
@ -123,7 +123,7 @@ class ChangeVisualActionTest : VimTestCase() {
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
}
@VimBehaviorDiffers(description = "Wrong caret position")
@ -145,14 +145,14 @@ class ChangeVisualActionTest : VimTestCase() {
wh|Hello
ha|Hello
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun `test replace first line`() {
val keys = "VcHello<esc>"
val before = "${c}A Discovery"
val after = "Hello"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
@TestWithoutNeovim(SkipNeovimReason.MULTICARET)
@ -161,7 +161,7 @@ class ChangeVisualActionTest : VimTestCase() {
injector.parser.parseKeys("v2lc" + "aaa" + "<ESC>"),
"abcd${c}ffffff${c}abcde${c}aaaa\n"
)
assertMode(CommandState.Mode.COMMAND)
assertMode(VimStateMachine.Mode.COMMAND)
assertState("abcdaa${c}afffaa${c}adeaa${c}aa\n")
}
@ -182,8 +182,8 @@ class ChangeVisualActionTest : VimTestCase() {
ba_quux_bar
""".trimIndent(),
CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
@ -204,8 +204,8 @@ class ChangeVisualActionTest : VimTestCase() {
ba_quux_bar
""".trimIndent(),
CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
}

View File

@ -20,7 +20,7 @@
package org.jetbrains.plugins.ideavim.action.change.change
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.helper.VimBehaviorDiffers
import org.jetbrains.plugins.ideavim.VimTestCase
@ -43,7 +43,7 @@ class ChangeVisualLinesEndActionTest : VimTestCase() {
where it was settled on some sodden sand
${c}
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
}
fun `test last empty line`() {
@ -66,7 +66,7 @@ class ChangeVisualLinesEndActionTest : VimTestCase() {
hard by the torrent of a mountain pass.
${c}
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
}
@VimBehaviorDiffers(
@ -99,6 +99,6 @@ class ChangeVisualLinesEndActionTest : VimTestCase() {
${c}
""".trimIndent()
doTest(keys, before, after, CommandState.Mode.INSERT, CommandState.SubMode.NONE)
doTest(keys, before, after, VimStateMachine.Mode.INSERT, VimStateMachine.SubMode.NONE)
}
}

View File

@ -18,16 +18,16 @@
package org.jetbrains.plugins.ideavim.action.change.change.number
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import org.jetbrains.plugins.ideavim.VimTestCase
class ChangeNumberDecActionTest : VimTestCase() {
fun `test decrement hex to negative value`() {
doTest("<C-X>", "0x0000", "0xffffffffffffffff", CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest("<C-X>", "0x0000", "0xffffffffffffffff", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun `test decrement hex to negative value by 10`() {
doTest("10<C-X>", "0x0005", "0xfffffffffffffffb", CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest("10<C-X>", "0x0005", "0xfffffffffffffffb", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun `test decrement oct to negative value`() {
@ -35,13 +35,13 @@ class ChangeNumberDecActionTest : VimTestCase() {
":set nrformats+=octal<CR><C-X>",
"00000",
"01777777777777777777777",
CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
fun `test decrement incorrect octal`() {
doTest(":set nrformats+=octal<CR><C-X>", "008", "7", CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest(":set nrformats+=octal<CR><C-X>", "008", "7", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
fun `test decrement oct to negative value by 10`() {
@ -49,8 +49,8 @@ class ChangeNumberDecActionTest : VimTestCase() {
":set nrformats+=octal<CR>10<C-X>",
"00005",
"01777777777777777777773",
CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
}

View File

@ -18,13 +18,13 @@
package org.jetbrains.plugins.ideavim.action.change.change.number
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import com.maddyhome.idea.vim.helper.VimBehaviorDiffers
import org.jetbrains.plugins.ideavim.VimTestCase
class ChangeNumberIncActionTest : VimTestCase() {
@VimBehaviorDiffers(originalVimAfter = "11X0")
fun `test inc fancy number`() {
doTest("<C-A>", "1${c}0X0", "10X1", CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
doTest("<C-A>", "1${c}0X0", "10X1", VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}
}

View File

@ -18,7 +18,7 @@
package org.jetbrains.plugins.ideavim.action.change.change.number
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.VimStateMachine
import org.jetbrains.plugins.ideavim.VimTestCase
/**
@ -38,8 +38,8 @@ class ChangeVisualNumberAvalancheDecActionTest : VimTestCase() {
number 1
number 1
""".trimIndent(),
CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
@ -56,8 +56,8 @@ class ChangeVisualNumberAvalancheDecActionTest : VimTestCase() {
number 1
number 1
""".trimIndent(),
CommandState.Mode.COMMAND,
CommandState.SubMode.NONE
VimStateMachine.Mode.COMMAND,
VimStateMachine.SubMode.NONE
)
}
}

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