mirror of
				https://github.com/chylex/IntelliJ-IdeaVim.git
				synced 2025-10-31 02:17:13 +01:00 
			
		
		
		
	Compare commits
	
		
			64 Commits
		
	
	
		
			0f0a73c139
			...
			customized
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| b7c1ba4f02 | |||
| fca7b518b3 | |||
| 8aa4178449 | |||
| 2e035f1260 | |||
| c5f17a68f5 | |||
| 68b7788fe4 | |||
| 3299059ab9 | |||
| 548ed30b5b | |||
| b171ccb96c | |||
| 93affef6d3 | |||
| 0b788153cd | |||
| 70d8167e17 | |||
| 67c3dec51b | |||
| 3dab706f37 | |||
| 5228bca65e | |||
| 853a208eba | |||
| fd9297edb1 | |||
| e01e4d8ecd | |||
| b304692c4e | |||
| 05b9f44a0b | |||
| d878b119c4 | |||
| def57128b0 | |||
| fd4422bf95 | |||
| d10a0c4ee7 | |||
|   | f12b0b04f6 | ||
|   | ea4fc85e5b | ||
|   | 4af8fc1868 | ||
|   | 1482ac0335 | ||
|   | 79168b00f3 | ||
|   | 07990847c6 | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 8c40e19c44 | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 371769c508 | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 7ee34d0b27 | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | d1ec7d617d | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 898fd0537d | ||
|   | 353603b546 | ||
|   | 2f7f0dcacb | ||
|   | af9023af4b | ||
|   | c393c902b2 | ||
|   | c355cb7ed7 | ||
|   | 0803a1c195 | ||
|   | 5208412b46 | ||
|   | 78c463cf7b | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 8f5a44bf44 | ||
|   | 2377408028 | ||
|   | 246425b1fb | ||
|   | 4eadfc1fba | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | d3c945cd6d | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 2ac46129ac | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | c8d40be1ce | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 97159a33fe | ||
|   | 861d585102 | ||
|   | 126925b4eb | ||
|   | 9302c0a057 | ||
|   | ddea72f803 | ||
|   | e991aa922c | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 5ffaa7b084 | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 0d4183129d | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 8a7fbac389 | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | dbab006f83 | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 3149de7b73 | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 28a71f0e09 | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | fc7d4e614b | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 5b1aade876 | 
							
								
								
									
										1
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | * text=auto eol=lf | ||||||
							
								
								
									
										3
									
								
								.idea/runConfigurations/IdeaVim_tests.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										3
									
								
								.idea/runConfigurations/IdeaVim_tests.xml
									
									
									
										generated
									
									
									
								
							| @@ -5,7 +5,7 @@ | |||||||
|       <option name="executionName" /> |       <option name="executionName" /> | ||||||
|       <option name="externalProjectPath" value="$PROJECT_DIR$" /> |       <option name="externalProjectPath" value="$PROJECT_DIR$" /> | ||||||
|       <option name="externalSystemIdString" value="GRADLE" /> |       <option name="externalSystemIdString" value="GRADLE" /> | ||||||
|       <option name="scriptParameters" value="" /> |       <option name="scriptParameters" value="-x :tests:property-tests:test -x :tests:long-running-tests:test" /> | ||||||
|       <option name="taskDescriptions"> |       <option name="taskDescriptions"> | ||||||
|         <list /> |         <list /> | ||||||
|       </option> |       </option> | ||||||
| @@ -19,6 +19,7 @@ | |||||||
|     <ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess> |     <ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess> | ||||||
|     <ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess> |     <ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess> | ||||||
|     <DebugAllEnabled>false</DebugAllEnabled> |     <DebugAllEnabled>false</DebugAllEnabled> | ||||||
|  |     <RunAsTest>false</RunAsTest> | ||||||
|     <method v="2" /> |     <method v="2" /> | ||||||
|   </configuration> |   </configuration> | ||||||
| </component> | </component> | ||||||
							
								
								
									
										1
									
								
								.teamcity/_Self/buildTypes/Compatibility.kt
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.teamcity/_Self/buildTypes/Compatibility.kt
									
									
									
									
										vendored
									
									
								
							| @@ -45,6 +45,7 @@ object Compatibility : IdeaVimBuildType({ | |||||||
|               java -jar verifier1/verifier-cli-dev-all-2.jar check-plugin '${'$'}com.julienphalip.ideavim.functiontextobj' [latest-IU] -team-city |               java -jar verifier1/verifier-cli-dev-all-2.jar check-plugin '${'$'}com.julienphalip.ideavim.functiontextobj' [latest-IU] -team-city | ||||||
|               java -jar verifier1/verifier-cli-dev-all-2.jar check-plugin '${'$'}com.miksuki.HighlightCursor' [latest-IU] -team-city |               java -jar verifier1/verifier-cli-dev-all-2.jar check-plugin '${'$'}com.miksuki.HighlightCursor' [latest-IU] -team-city | ||||||
|               java -jar verifier1/verifier-cli-dev-all-2.jar check-plugin '${'$'}com.ugarosa.idea.edgemotion' [latest-IU] -team-city |               java -jar verifier1/verifier-cli-dev-all-2.jar check-plugin '${'$'}com.ugarosa.idea.edgemotion' [latest-IU] -team-city | ||||||
|  |               java -jar verifier1/verifier-cli-dev-all-2.jar check-plugin '${'$'}cn.mumukehao.plugin' [latest-IU] -team-city | ||||||
|             """.trimIndent() |             """.trimIndent() | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								.teamcity/_Self/buildTypes/LongRunning.kt
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.teamcity/_Self/buildTypes/LongRunning.kt
									
									
									
									
										vendored
									
									
								
							| @@ -25,7 +25,7 @@ object LongRunning : IdeaVimBuildType({ | |||||||
|  |  | ||||||
|   steps { |   steps { | ||||||
|     gradle { |     gradle { | ||||||
|       tasks = "clean :tests:long-running-tests:testLongRunning" |       tasks = "clean :tests:long-running-tests:test" | ||||||
|       buildFile = "" |       buildFile = "" | ||||||
|       enableStacktrace = true |       enableStacktrace = true | ||||||
|       jdkHome = "/usr/lib/jvm/java-21-amazon-corretto" |       jdkHome = "/usr/lib/jvm/java-21-amazon-corretto" | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								.teamcity/_Self/buildTypes/Nvim.kt
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.teamcity/_Self/buildTypes/Nvim.kt
									
									
									
									
										vendored
									
									
								
							| @@ -39,7 +39,7 @@ object Nvim : IdeaVimBuildType({ | |||||||
|               """.trimIndent() |               """.trimIndent() | ||||||
|     } |     } | ||||||
|     gradle { |     gradle { | ||||||
|       tasks = "clean test -Dnvim" |       tasks = "clean test -x :tests:property-tests:test -x :tests:long-running-tests:test -Dnvim" | ||||||
|       buildFile = "" |       buildFile = "" | ||||||
|       enableStacktrace = true |       enableStacktrace = true | ||||||
|       jdkHome = "/usr/lib/jvm/java-21-amazon-corretto" |       jdkHome = "/usr/lib/jvm/java-21-amazon-corretto" | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								.teamcity/_Self/buildTypes/PropertyBased.kt
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.teamcity/_Self/buildTypes/PropertyBased.kt
									
									
									
									
										vendored
									
									
								
							| @@ -25,7 +25,7 @@ object PropertyBased : IdeaVimBuildType({ | |||||||
|   steps { |   steps { | ||||||
|     gradle { |     gradle { | ||||||
|       clearConditions() |       clearConditions() | ||||||
|       tasks = "clean :tests:property-tests:testPropertyBased" |       tasks = "clean :tests:property-tests:test" | ||||||
|       buildFile = "" |       buildFile = "" | ||||||
|       enableStacktrace = true |       enableStacktrace = true | ||||||
|       jdkHome = "/usr/lib/jvm/java-21-amazon-corretto" |       jdkHome = "/usr/lib/jvm/java-21-amazon-corretto" | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								.teamcity/_Self/buildTypes/ReleasePlugin.kt
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.teamcity/_Self/buildTypes/ReleasePlugin.kt
									
									
									
									
										vendored
									
									
								
							| @@ -115,7 +115,7 @@ sealed class ReleasePlugin(private val releaseType: String) : IdeaVimBuildType({ | |||||||
|     } |     } | ||||||
|     script { |     script { | ||||||
|       name = "Run tests" |       name = "Run tests" | ||||||
|       scriptContent = "./gradlew test" |       scriptContent = "./gradlew test -x :tests:property-tests:test -x :tests:long-running-tests:test" | ||||||
|     } |     } | ||||||
|     gradle { |     gradle { | ||||||
|       name = "Publish release" |       name = "Publish release" | ||||||
|   | |||||||
| @@ -40,7 +40,7 @@ open class TestingBuildType( | |||||||
|   steps { |   steps { | ||||||
|     gradle { |     gradle { | ||||||
|       clearConditions() |       clearConditions() | ||||||
|       tasks = "clean test" |       tasks = "clean test -x :tests:property-tests:test -x :tests:long-running-tests:test" | ||||||
|       buildFile = "" |       buildFile = "" | ||||||
|       enableStacktrace = true |       enableStacktrace = true | ||||||
|       jdkHome = "/usr/lib/jvm/java-21-amazon-corretto" |       jdkHome = "/usr/lib/jvm/java-21-amazon-corretto" | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								.teamcity/_Self/subprojects/GitHub.kt
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.teamcity/_Self/subprojects/GitHub.kt
									
									
									
									
										vendored
									
									
								
							| @@ -15,7 +15,7 @@ object GitHub : Project({ | |||||||
|   name = "Pull Requests checks" |   name = "Pull Requests checks" | ||||||
|   description = "Automatic checking of GitHub Pull Requests" |   description = "Automatic checking of GitHub Pull Requests" | ||||||
|  |  | ||||||
|   buildType(GithubBuildType("clean test", "Tests")) |   buildType(GithubBuildType("clean test -x :tests:property-tests:test -x :tests:long-running-tests:test", "Tests")) | ||||||
| }) | }) | ||||||
|  |  | ||||||
| class GithubBuildType(command: String, desc: String) : IdeaVimBuildType({ | class GithubBuildType(command: String, desc: String) : IdeaVimBuildType({ | ||||||
|   | |||||||
| @@ -614,6 +614,14 @@ Contributors: | |||||||
|   [![icon][github]](https://github.com/Malandril) |   [![icon][github]](https://github.com/Malandril) | ||||||
|     |     | ||||||
|   Thomas Canava |   Thomas Canava | ||||||
|  | * [![icon][mail]](mailto:xinhe.wang@jetbrains.com) | ||||||
|  |   [![icon][github]](https://github.com/wxh06) | ||||||
|  |     | ||||||
|  |   Xinhe Wang | ||||||
|  | * [![icon][mail]](mailto:zuber.kuba@gmail.com) | ||||||
|  |   [![icon][github]](https://github.com/zuberol) | ||||||
|  |     | ||||||
|  |   Jakub Zuber | ||||||
|  |  | ||||||
| Previous contributors: | Previous contributors: | ||||||
|  |  | ||||||
|   | |||||||
| @@ -65,7 +65,7 @@ We've prepared some useful configurations for you: | |||||||
| And here are useful gradle commands: | And here are useful gradle commands: | ||||||
|  |  | ||||||
| * `./gradlew runIde` — start the dev version of IntelliJ IDEA with IdeaVim installed. | * `./gradlew runIde` — start the dev version of IntelliJ IDEA with IdeaVim installed. | ||||||
| * `./gradlew test` — run tests. | * `./gradlew test -x :tests:property-tests:test -x :tests:long-running-tests:test` — run tests. | ||||||
| * `./gradlew buildPlugin` — build the plugin. The result will be located in `build/distributions`. This file can be | * `./gradlew buildPlugin` — build the plugin. The result will be located in `build/distributions`. This file can be | ||||||
| installed by using `Settings | Plugin | >Gear Icon< | Install Plugin from Disk...`. You can stay with your personal build | installed by using `Settings | Plugin | >Gear Icon< | Install Plugin from Disk...`. You can stay with your personal build | ||||||
| for a few days or send it to a friend for testing. | for a few days or send it to a friend for testing. | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ | |||||||
|  |  | ||||||
| plugins { | plugins { | ||||||
|   kotlin("jvm") |   kotlin("jvm") | ||||||
|   kotlin("plugin.serialization") version "2.0.21" |   kotlin("plugin.serialization") version "2.2.0" | ||||||
| } | } | ||||||
|  |  | ||||||
| val kotlinxSerializationVersion: String by project | val kotlinxSerializationVersion: String by project | ||||||
| @@ -21,7 +21,7 @@ repositories { | |||||||
| } | } | ||||||
|  |  | ||||||
| dependencies { | dependencies { | ||||||
|   compileOnly("com.google.devtools.ksp:symbol-processing-api:2.1.21-2.0.1") |   compileOnly("com.google.devtools.ksp:symbol-processing-api:2.1.21-2.0.2") | ||||||
|   implementation("org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:$kotlinxSerializationVersion") { |   implementation("org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:$kotlinxSerializationVersion") { | ||||||
|     // kotlin stdlib is provided by IJ, so there is no need to include it into the distribution |     // kotlin stdlib is provided by IJ, so there is no need to include it into the distribution | ||||||
|     exclude("org.jetbrains.kotlin", "kotlin-stdlib") |     exclude("org.jetbrains.kotlin", "kotlin-stdlib") | ||||||
|   | |||||||
| @@ -35,6 +35,8 @@ import org.intellij.markdown.ast.impl.ListCompositeNode | |||||||
| import org.jetbrains.changelog.Changelog | import org.jetbrains.changelog.Changelog | ||||||
| import org.jetbrains.intellij.platform.gradle.TestFrameworkType | import org.jetbrains.intellij.platform.gradle.TestFrameworkType | ||||||
| import org.jetbrains.intellij.platform.gradle.tasks.aware.SplitModeAware | import org.jetbrains.intellij.platform.gradle.tasks.aware.SplitModeAware | ||||||
|  | import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||||||
|  | import org.jetbrains.kotlin.gradle.dsl.KotlinVersion | ||||||
| import org.kohsuke.github.GHUser | import org.kohsuke.github.GHUser | ||||||
| import java.net.HttpURLConnection | import java.net.HttpURLConnection | ||||||
| import java.net.URL | import java.net.URL | ||||||
| @@ -46,19 +48,19 @@ buildscript { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   dependencies { |   dependencies { | ||||||
|     classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21") |     classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.0") | ||||||
|     classpath("com.github.AlexPl292:mark-down-to-slack:1.1.2") |     classpath("com.github.AlexPl292:mark-down-to-slack:1.1.2") | ||||||
|     classpath("org.eclipse.jgit:org.eclipse.jgit:6.6.0.202305301015-r") |     classpath("org.eclipse.jgit:org.eclipse.jgit:6.6.0.202305301015-r") | ||||||
|  |  | ||||||
|     // This is needed for jgit to connect to ssh |     // This is needed for jgit to connect to ssh | ||||||
|     classpath("org.eclipse.jgit:org.eclipse.jgit.ssh.apache:7.2.1.202505142326-r") |     classpath("org.eclipse.jgit:org.eclipse.jgit.ssh.apache:7.3.0.202506031305-r") | ||||||
|     classpath("org.kohsuke:github-api:1.305") |     classpath("org.kohsuke:github-api:1.305") | ||||||
|  |  | ||||||
|     classpath("io.ktor:ktor-client-core:3.1.3") |     classpath("io.ktor:ktor-client-core:3.2.2") | ||||||
|     classpath("io.ktor:ktor-client-cio:3.1.3") |     classpath("io.ktor:ktor-client-cio:3.2.2") | ||||||
|     classpath("io.ktor:ktor-client-auth:3.1.3") |     classpath("io.ktor:ktor-client-auth:3.2.2") | ||||||
|     classpath("io.ktor:ktor-client-content-negotiation:3.1.3") |     classpath("io.ktor:ktor-client-content-negotiation:3.2.2") | ||||||
|     classpath("io.ktor:ktor-serialization-kotlinx-json:3.1.3") |     classpath("io.ktor:ktor-serialization-kotlinx-json:3.2.2") | ||||||
|  |  | ||||||
|     // This comes from the changelog plugin |     // This comes from the changelog plugin | ||||||
| //        classpath("org.jetbrains:markdown:0.3.1") | //        classpath("org.jetbrains:markdown:0.3.1") | ||||||
| @@ -67,7 +69,7 @@ buildscript { | |||||||
|  |  | ||||||
| plugins { | plugins { | ||||||
|   java |   java | ||||||
|   kotlin("jvm") version "2.0.21" |   kotlin("jvm") version "2.2.0" | ||||||
|   application |   application | ||||||
|   id("java-test-fixtures") |   id("java-test-fixtures") | ||||||
|  |  | ||||||
| @@ -79,7 +81,7 @@ plugins { | |||||||
|   id("org.jetbrains.changelog") version "2.2.1" |   id("org.jetbrains.changelog") version "2.2.1" | ||||||
|   id("org.jetbrains.kotlinx.kover") version "0.6.1" |   id("org.jetbrains.kotlinx.kover") version "0.6.1" | ||||||
|   id("com.dorongold.task-tree") version "4.0.1" |   id("com.dorongold.task-tree") version "4.0.1" | ||||||
|   id("com.google.devtools.ksp") version "2.0.21-1.0.25" |   id("com.google.devtools.ksp") version "2.2.0-2.0.2" | ||||||
| } | } | ||||||
|  |  | ||||||
| val moduleSources by configurations.registering | val moduleSources by configurations.registering | ||||||
| @@ -137,8 +139,14 @@ dependencies { | |||||||
|  |  | ||||||
|     // AceJump is an optional dependency. We use their SessionManager class to check if it's active |     // AceJump is an optional dependency. We use their SessionManager class to check if it's active | ||||||
|     plugin("AceJump", "3.8.19") |     plugin("AceJump", "3.8.19") | ||||||
|  |     plugin("com.intellij.classic.ui", "251.23774.318") | ||||||
|  |  | ||||||
|     bundledPlugins("org.jetbrains.plugins.terminal") |     bundledPlugins("org.jetbrains.plugins.terminal") | ||||||
|  |  | ||||||
|  |     // VERSION UPDATE: This module is required since 2025.2 | ||||||
|  |     if (ideaVersion == "LATEST-EAP-SNAPSHOT") { | ||||||
|  |       bundledModule("intellij.spellchecker") | ||||||
|  |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   moduleSources(project(":vim-engine", "sourcesJarArtifacts")) |   moduleSources(project(":vim-engine", "sourcesJarArtifacts")) | ||||||
| @@ -158,19 +166,19 @@ dependencies { | |||||||
|   testFixturesImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion") |   testFixturesImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion") | ||||||
|  |  | ||||||
|   // https://mvnrepository.com/artifact/org.mockito.kotlin/mockito-kotlin |   // https://mvnrepository.com/artifact/org.mockito.kotlin/mockito-kotlin | ||||||
|   testImplementation("org.mockito.kotlin:mockito-kotlin:5.4.0") |   testImplementation("org.mockito.kotlin:mockito-kotlin:6.0.0") | ||||||
|  |  | ||||||
|   testImplementation("org.junit.jupiter:junit-jupiter-api:5.13.0") |   testImplementation("org.junit.jupiter:junit-jupiter-api:5.13.3") | ||||||
|   testImplementation("org.junit.jupiter:junit-jupiter-engine:5.13.0") |   testImplementation("org.junit.jupiter:junit-jupiter-engine:5.13.3") | ||||||
|   testImplementation("org.junit.jupiter:junit-jupiter-params:5.13.0") |   testImplementation("org.junit.jupiter:junit-jupiter-params:5.13.3") | ||||||
|   testFixturesImplementation("org.junit.jupiter:junit-jupiter-api:5.13.0") |   testFixturesImplementation("org.junit.jupiter:junit-jupiter-api:5.13.3") | ||||||
|   testFixturesImplementation("org.junit.jupiter:junit-jupiter-engine:5.13.0") |   testFixturesImplementation("org.junit.jupiter:junit-jupiter-engine:5.13.3") | ||||||
|   testFixturesImplementation("org.junit.jupiter:junit-jupiter-params:5.13.0") |   testFixturesImplementation("org.junit.jupiter:junit-jupiter-params:5.13.3") | ||||||
|  |  | ||||||
|   // Temp workaround suggested in https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-faq.html#junit5-test-framework-refers-to-junit4 |   // Temp workaround suggested in https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-faq.html#junit5-test-framework-refers-to-junit4 | ||||||
|   // Can be removed when IJPL-159134 is fixed |   // Can be removed when IJPL-159134 is fixed | ||||||
| //  testRuntimeOnly("junit:junit:4.13.2") | //  testRuntimeOnly("junit:junit:4.13.2") | ||||||
|   testImplementation("org.junit.vintage:junit-vintage-engine:5.13.0") |   testImplementation("org.junit.vintage:junit-vintage-engine:5.13.2") | ||||||
| //  testFixturesImplementation("org.junit.vintage:junit-vintage-engine:5.10.3") | //  testFixturesImplementation("org.junit.vintage:junit-vintage-engine:5.10.3") | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -220,40 +228,11 @@ tasks { | |||||||
|     options.encoding = "UTF-8" |     options.encoding = "UTF-8" | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   compileKotlin { |  | ||||||
|     kotlinOptions { |  | ||||||
|       jvmTarget = javaVersion |  | ||||||
|       // See https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#kotlin-standard-library |  | ||||||
|       // For the list of bundled versions |  | ||||||
|       apiVersion = "2.0" |  | ||||||
|       freeCompilerArgs = listOf( |  | ||||||
|         "-Xjvm-default=all-compatibility", |  | ||||||
|  |  | ||||||
|         // Needed to compile the AceJump which uses kotlin beta |  | ||||||
|         //  Without these two option compilation fails |  | ||||||
|         "-Xskip-prerelease-check", |  | ||||||
|         "-Xallow-unstable-dependencies", |  | ||||||
|       ) |  | ||||||
| //            allWarningsAsErrors = true |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   compileTestKotlin { |  | ||||||
|     kotlinOptions { |  | ||||||
|       jvmTarget = javaVersion |  | ||||||
|       apiVersion = "2.0" |  | ||||||
|  |  | ||||||
|       // Needed to compile the AceJump which uses kotlin beta |  | ||||||
|       //  Without these two option compilation fails |  | ||||||
|       freeCompilerArgs += listOf("-Xskip-prerelease-check", "-Xallow-unstable-dependencies") |  | ||||||
| //            allWarningsAsErrors = true |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   // Note that this will run the plugin installed in the IDE specified in dependencies. To run in a different IDE, use |   // Note that this will run the plugin installed in the IDE specified in dependencies. To run in a different IDE, use | ||||||
|   // a custom task (see below) |   // a custom task (see below) | ||||||
|   runIde { |   runIde { | ||||||
|     systemProperty("octopus.handler", System.getProperty("octopus.handler") ?: true) |     systemProperty("octopus.handler", System.getProperty("octopus.handler") ?: true) | ||||||
|  |     systemProperty("idea.trust.all.projects", "true") | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Uncomment to run the plugin in a custom IDE, rather than the IDE specified as a compile target in dependencies |   // Uncomment to run the plugin in a custom IDE, rather than the IDE specified as a compile target in dependencies | ||||||
| @@ -322,6 +301,23 @@ kotlin { | |||||||
|   jvmToolchain { |   jvmToolchain { | ||||||
|     languageVersion.set(JavaLanguageVersion.of(javaVersion)) |     languageVersion.set(JavaLanguageVersion.of(javaVersion)) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   compilerOptions { | ||||||
|  |     jvmTarget.set(JvmTarget.fromTarget(javaVersion)) | ||||||
|  |  | ||||||
|  |     // See https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#kotlin-standard-library | ||||||
|  |     // For the list of bundled versions | ||||||
|  |     apiVersion.set(KotlinVersion.KOTLIN_2_0) | ||||||
|  |     freeCompilerArgs = listOf( | ||||||
|  |       "-Xjvm-default=all-compatibility", | ||||||
|  |  | ||||||
|  |       // Needed to compile the AceJump which uses kotlin beta | ||||||
|  |       //  Without these two option compilation fails | ||||||
|  |       "-Xskip-prerelease-check", | ||||||
|  |       "-Xallow-unstable-dependencies", | ||||||
|  |     ) | ||||||
|  | //            allWarningsAsErrors = true | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| gradle.projectsEvaluated { | gradle.projectsEvaluated { | ||||||
|   | |||||||
| @@ -20,7 +20,7 @@ ideaVersion=2025.1 | |||||||
| # Values for type: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#intellij-extension-type | # Values for type: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#intellij-extension-type | ||||||
| ideaType=IC | ideaType=IC | ||||||
| instrumentPluginCode=true | instrumentPluginCode=true | ||||||
| version=SNAPSHOT | version=chylex-50 | ||||||
| javaVersion=21 | javaVersion=21 | ||||||
| remoteRobotVersion=0.11.23 | remoteRobotVersion=0.11.23 | ||||||
| antlrVersion=4.10.1 | antlrVersion=4.10.1 | ||||||
| @@ -28,7 +28,7 @@ antlrVersion=4.10.1 | |||||||
|  |  | ||||||
| # Please don't forget to update kotlin version in buildscript section | # Please don't forget to update kotlin version in buildscript section | ||||||
| # Also update kotlinxSerializationVersion version | # Also update kotlinxSerializationVersion version | ||||||
| kotlinVersion=2.0.21 | kotlinVersion=2.2.0 | ||||||
| publishToken=token | publishToken=token | ||||||
| publishChannels=eap | publishChannels=eap | ||||||
|  |  | ||||||
| @@ -41,7 +41,6 @@ youtrackToken= | |||||||
|  |  | ||||||
| # Gradle settings | # Gradle settings | ||||||
| org.gradle.jvmargs='-Dfile.encoding=UTF-8' | org.gradle.jvmargs='-Dfile.encoding=UTF-8' | ||||||
| org.gradle.configuration-cache=true |  | ||||||
| org.gradle.caching=true | org.gradle.caching=true | ||||||
|  |  | ||||||
| # Disable warning from gradle-intellij-plugin. Kotlin stdlib is included as compileOnly, so the warning is unnecessary | # Disable warning from gradle-intellij-plugin. Kotlin stdlib is included as compileOnly, so the warning is unnecessary | ||||||
|   | |||||||
| @@ -20,27 +20,25 @@ repositories { | |||||||
| } | } | ||||||
|  |  | ||||||
| dependencies { | dependencies { | ||||||
|   compileOnly("org.jetbrains.kotlin:kotlin-stdlib:2.1.21") |   compileOnly("org.jetbrains.kotlin:kotlin-stdlib:2.2.0") | ||||||
|  |  | ||||||
|   implementation("io.ktor:ktor-client-core:3.1.3") |   implementation("io.ktor:ktor-client-core:3.2.2") | ||||||
|   implementation("io.ktor:ktor-client-cio:3.1.3") |   implementation("io.ktor:ktor-client-cio:3.2.2") | ||||||
|   implementation("io.ktor:ktor-client-content-negotiation:3.1.3") |   implementation("io.ktor:ktor-client-content-negotiation:3.2.2") | ||||||
|   implementation("io.ktor:ktor-serialization-kotlinx-json:3.1.3") |   implementation("io.ktor:ktor-serialization-kotlinx-json:3.2.2") | ||||||
|   implementation("io.ktor:ktor-client-auth:3.1.3") |   implementation("io.ktor:ktor-client-auth:3.2.2") | ||||||
|   implementation("org.eclipse.jgit:org.eclipse.jgit:6.6.0.202305301015-r") |   implementation("org.eclipse.jgit:org.eclipse.jgit:6.6.0.202305301015-r") | ||||||
|  |  | ||||||
|   // This is needed for jgit to connect to ssh |   // This is needed for jgit to connect to ssh | ||||||
|   implementation("org.eclipse.jgit:org.eclipse.jgit.ssh.apache:7.2.1.202505142326-r") |   implementation("org.eclipse.jgit:org.eclipse.jgit.ssh.apache:7.3.0.202506031305-r") | ||||||
|   implementation("com.vdurmont:semver4j:3.1.0") |   implementation("com.vdurmont:semver4j:3.1.0") | ||||||
| } | } | ||||||
|  |  | ||||||
| val releaseType: String? by project | val releaseType: String? by project | ||||||
|  |  | ||||||
| tasks { | kotlin { | ||||||
|   compileKotlin { |   compilerOptions { | ||||||
|     kotlinOptions { |     freeCompilerArgs = listOf("-Xjvm-default=all-compatibility") | ||||||
|       freeCompilerArgs = listOf("-Xjvm-default=all-compatibility") |  | ||||||
|     } |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -45,6 +45,8 @@ val knownPlugins = setOf( | |||||||
|   "com.julienphalip.ideavim.functiontextobj", // https://plugins.jetbrains.com/plugin/25897-vim-functiontextobj |   "com.julienphalip.ideavim.functiontextobj", // https://plugins.jetbrains.com/plugin/25897-vim-functiontextobj | ||||||
|   "com.miksuki.HighlightCursor", // https://plugins.jetbrains.com/plugin/26743-highlightcursor |   "com.miksuki.HighlightCursor", // https://plugins.jetbrains.com/plugin/26743-highlightcursor | ||||||
|   "com.ugarosa.idea.edgemotion", // https://plugins.jetbrains.com/plugin/27211-edgemotion |   "com.ugarosa.idea.edgemotion", // https://plugins.jetbrains.com/plugin/27211-edgemotion | ||||||
|  |  | ||||||
|  |   "cn.mumukehao.plugin", | ||||||
| ) | ) | ||||||
|  |  | ||||||
| suspend fun main() { | suspend fun main() { | ||||||
|   | |||||||
| @@ -0,0 +1,67 @@ | |||||||
|  | package com.maddyhome.idea.vim.action.macro | ||||||
|  |  | ||||||
|  | import com.intellij.openapi.command.CommandProcessor | ||||||
|  | import com.intellij.openapi.command.UndoConfirmationPolicy | ||||||
|  | import com.intellij.openapi.command.impl.FinishMarkAction | ||||||
|  | import com.intellij.openapi.command.impl.StartMarkAction | ||||||
|  | import com.intellij.openapi.fileEditor.TextEditor | ||||||
|  | import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx | ||||||
|  | import com.intellij.vim.annotations.CommandOrMotion | ||||||
|  | import com.intellij.vim.annotations.Mode | ||||||
|  | import com.maddyhome.idea.vim.KeyHandler | ||||||
|  | import com.maddyhome.idea.vim.api.ExecutionContext | ||||||
|  | import com.maddyhome.idea.vim.api.VimEditor | ||||||
|  | import com.maddyhome.idea.vim.api.injector | ||||||
|  | import com.maddyhome.idea.vim.command.Argument | ||||||
|  | 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.newapi.ij | ||||||
|  | import com.maddyhome.idea.vim.newapi.vim | ||||||
|  |  | ||||||
|  | @CommandOrMotion(keys = ["z@"], modes = [Mode.NORMAL]) | ||||||
|  | class PlaybackRegisterInOpenFilesAction : VimActionHandler.SingleExecution() { | ||||||
|  |   override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED | ||||||
|  |  | ||||||
|  |   override val argumentType: Argument.Type = Argument.Type.CHARACTER | ||||||
|  |  | ||||||
|  |   private val playbackRegisterAction = PlaybackRegisterAction() | ||||||
|  |    | ||||||
|  |   override fun execute( | ||||||
|  |     editor: VimEditor, | ||||||
|  |     context: ExecutionContext, | ||||||
|  |     cmd: Command, | ||||||
|  |     operatorArguments: OperatorArguments, | ||||||
|  |   ): Boolean { | ||||||
|  |     val argument = cmd.argument as? Argument.Character ?: return false | ||||||
|  |  | ||||||
|  |     val project = editor.ij.project ?: return false | ||||||
|  |     val fileEditorManager = FileEditorManagerEx.getInstanceExIfCreated(project) ?: return false | ||||||
|  |  | ||||||
|  |     val register = argument.character.let { if (it == '@') injector.macro.lastRegister else it } | ||||||
|  |     val commandName = "Execute Macro '$register' in All Open Files" | ||||||
|  |  | ||||||
|  |     val action = Runnable { | ||||||
|  |       CommandProcessor.getInstance().markCurrentCommandAsGlobal(project) | ||||||
|  |        | ||||||
|  |       for (textEditor in fileEditorManager.allEditors.filterIsInstance<TextEditor>()) { | ||||||
|  |         fileEditorManager.openFile(textEditor.file, true) | ||||||
|  |  | ||||||
|  |         val editor = textEditor.editor | ||||||
|  |         val vimEditor = editor.vim | ||||||
|  |  | ||||||
|  |         vimEditor.mode = com.maddyhome.idea.vim.state.mode.Mode.NORMAL() | ||||||
|  |         KeyHandler.Companion.getInstance().reset(vimEditor) | ||||||
|  |  | ||||||
|  |         val startMarkAction = StartMarkAction.start(editor, project, commandName) | ||||||
|  |         playbackRegisterAction.execute(vimEditor, context, cmd, operatorArguments) | ||||||
|  |         FinishMarkAction.finish(project, editor, startMarkAction) | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     CommandProcessor.getInstance() | ||||||
|  |       .executeCommand(project, action, commandName, null, UndoConfirmationPolicy.REQUEST_CONFIRMATION) | ||||||
|  |  | ||||||
|  |     return true | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -221,7 +221,7 @@ object VimExtensionFacade { | |||||||
|     caret: ImmutableVimCaret, |     caret: ImmutableVimCaret, | ||||||
|     keys: List<KeyStroke?>?, |     keys: List<KeyStroke?>?, | ||||||
|   ) { |   ) { | ||||||
|     caret.registerStorage.setKeys(editor, context, register, keys?.filterNotNull() ?: emptyList()) |     caret.registerStorage.setKeys(register, keys?.filterNotNull() ?: emptyList()) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** Set the current contents of the given register */ |   /** Set the current contents of the given register */ | ||||||
|   | |||||||
| @@ -21,9 +21,7 @@ import com.intellij.openapi.editor.markup.TextAttributes | |||||||
| import com.intellij.openapi.util.Disposer | import com.intellij.openapi.util.Disposer | ||||||
| import com.intellij.util.Alarm | import com.intellij.util.Alarm | ||||||
| import com.intellij.util.Alarm.ThreadToUse | import com.intellij.util.Alarm.ThreadToUse | ||||||
| import com.jetbrains.rd.util.first |  | ||||||
| import com.maddyhome.idea.vim.VimPlugin | import com.maddyhome.idea.vim.VimPlugin | ||||||
| import com.maddyhome.idea.vim.api.ImmutableVimCaret |  | ||||||
| import com.maddyhome.idea.vim.api.VimEditor | import com.maddyhome.idea.vim.api.VimEditor | ||||||
| import com.maddyhome.idea.vim.api.injector | import com.maddyhome.idea.vim.api.injector | ||||||
| import com.maddyhome.idea.vim.common.ModeChangeListener | import com.maddyhome.idea.vim.common.ModeChangeListener | ||||||
| @@ -123,9 +121,9 @@ internal class VimHighlightedYank : VimExtension, VimYankListener, ModeChangeLis | |||||||
|     initialised = false |     initialised = false | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   override fun yankPerformed(caretToRange: Map<ImmutableVimCaret, TextRange>) { |   override fun yankPerformed(editor: VimEditor, range: TextRange) { | ||||||
|     ensureInitialised() |     ensureInitialised() | ||||||
|     highlightHandler.highlightYankRange(caretToRange) |     highlightHandler.highlightYankRange(editor.ij, range) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   override fun modeChanged(editor: VimEditor, oldMode: Mode) { |   override fun modeChanged(editor: VimEditor, oldMode: Mode) { | ||||||
| @@ -146,25 +144,22 @@ internal class VimHighlightedYank : VimExtension, VimYankListener, ModeChangeLis | |||||||
|     private var lastEditor: Editor? = null |     private var lastEditor: Editor? = null | ||||||
|     private val highlighters = mutableSetOf<RangeHighlighter>() |     private val highlighters = mutableSetOf<RangeHighlighter>() | ||||||
|  |  | ||||||
|     fun highlightYankRange(caretToRange: Map<ImmutableVimCaret, TextRange>) { |     fun highlightYankRange(editor: Editor, range: TextRange) { | ||||||
|       // from vim-highlightedyank docs: When a new text is yanked or user starts editing, the old highlighting would be deleted |       // from vim-highlightedyank docs: When a new text is yanked or user starts editing, the old highlighting would be deleted | ||||||
|       clearYankHighlighters() |       clearYankHighlighters() | ||||||
|  |  | ||||||
|       val editor = caretToRange.first().key.editor.ij |  | ||||||
|       lastEditor = editor |       lastEditor = editor | ||||||
|  |  | ||||||
|       val attributes = getHighlightTextAttributes(editor) |       val attributes = getHighlightTextAttributes(editor) | ||||||
|       for (range in caretToRange.values) { |       for (i in 0 until range.size()) { | ||||||
|         for (i in 0 until range.size()) { |         val highlighter = editor.markupModel.addRangeHighlighter( | ||||||
|           val highlighter = editor.markupModel.addRangeHighlighter( |           range.startOffsets[i], | ||||||
|             range.startOffsets[i], |           range.endOffsets[i], | ||||||
|             range.endOffsets[i], |           HighlighterLayer.SELECTION, | ||||||
|             HighlighterLayer.SELECTION, |           attributes, | ||||||
|             attributes, |           HighlighterTargetArea.EXACT_RANGE, | ||||||
|             HighlighterTargetArea.EXACT_RANGE, |         ) | ||||||
|           ) |         highlighters.add(highlighter) | ||||||
|           highlighters.add(highlighter) |  | ||||||
|         } |  | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       // from vim-highlightedyank docs: A negative number makes the highlight persistent. |       // from vim-highlightedyank docs: A negative number makes the highlight persistent. | ||||||
|   | |||||||
| @@ -230,7 +230,7 @@ private object FileTypePatterns { | |||||||
|     } else if (fileTypeName == "CMakeLists.txt" || fileName == "CMakeLists") { |     } else if (fileTypeName == "CMakeLists.txt" || fileName == "CMakeLists") { | ||||||
|       this.cMakePatterns |       this.cMakePatterns | ||||||
|     } else { |     } else { | ||||||
|       return null |       this.htmlPatterns | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -455,6 +455,17 @@ internal class NerdTree : VimExtension { | |||||||
|         tree.scrollRowToVisible(expectedRow) |         tree.scrollRowToVisible(expectedRow) | ||||||
|       }, |       }, | ||||||
|     ) |     ) | ||||||
|  |     registerCommand("gg", NerdAction.Code { project, _, _ -> | ||||||
|  |       val tree = ProjectView.getInstance(project).currentProjectViewPane.tree | ||||||
|  |       tree.setSelectionRow(0) | ||||||
|  |       tree.scrollRowToVisible(0) | ||||||
|  |     }) | ||||||
|  |     registerCommand("G", NerdAction.Code { project, _, _ -> | ||||||
|  |       val tree = ProjectView.getInstance(project).currentProjectViewPane.tree | ||||||
|  |       val lastRowIndex = tree.rowCount -1 | ||||||
|  |       tree.setSelectionRow(lastRowIndex) | ||||||
|  |       tree.scrollRowToVisible(lastRowIndex) | ||||||
|  |     }) | ||||||
|     registerCommand( |     registerCommand( | ||||||
|       "NERDTreeMapJumpNextSibling", |       "NERDTreeMapJumpNextSibling", | ||||||
|       "<C-J>", |       "<C-J>", | ||||||
|   | |||||||
| @@ -29,7 +29,6 @@ import com.maddyhome.idea.vim.extension.exportOperatorFunction | |||||||
| import com.maddyhome.idea.vim.group.visual.VimSelection | import com.maddyhome.idea.vim.group.visual.VimSelection | ||||||
| import com.maddyhome.idea.vim.helper.exitVisualMode | import com.maddyhome.idea.vim.helper.exitVisualMode | ||||||
| import com.maddyhome.idea.vim.key.OperatorFunction | import com.maddyhome.idea.vim.key.OperatorFunction | ||||||
| import com.maddyhome.idea.vim.newapi.IjVimCopiedText |  | ||||||
| import com.maddyhome.idea.vim.newapi.IjVimEditor | import com.maddyhome.idea.vim.newapi.IjVimEditor | ||||||
| import com.maddyhome.idea.vim.newapi.ij | import com.maddyhome.idea.vim.newapi.ij | ||||||
| import com.maddyhome.idea.vim.newapi.vim | import com.maddyhome.idea.vim.newapi.vim | ||||||
| @@ -154,8 +153,7 @@ private fun doReplace(editor: Editor, context: DataContext, caret: ImmutableVimC | |||||||
|     usedType = SelectionType.CHARACTER_WISE |     usedType = SelectionType.CHARACTER_WISE | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   val copiedText = IjVimCopiedText(usedText, (savedRegister.copiedText as IjVimCopiedText).transferableData) |   val textData = PutData.TextData(usedText, usedType, savedRegister.transferableData, savedRegister.name) | ||||||
|   val textData = PutData.TextData(savedRegister.name, copiedText, usedType) |  | ||||||
|  |  | ||||||
|   val putData = PutData( |   val putData = PutData( | ||||||
|     textData, |     textData, | ||||||
|   | |||||||
| @@ -0,0 +1,30 @@ | |||||||
|  | package com.maddyhome.idea.vim.extension.surround | ||||||
|  |  | ||||||
|  | import com.intellij.util.text.CharSequenceSubSequence | ||||||
|  |  | ||||||
|  | internal data class RepeatedCharSequence(val text: CharSequence, val count: Int) : CharSequence { | ||||||
|  |   override val length = text.length * count | ||||||
|  |  | ||||||
|  |   override fun get(index: Int): Char { | ||||||
|  |     if (index < 0 || index >= length) throw IndexOutOfBoundsException() | ||||||
|  |     return text[index % text.length] | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   override fun subSequence(startIndex: Int, endIndex: Int): CharSequence { | ||||||
|  |     return CharSequenceSubSequence(this, startIndex, endIndex) | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   override fun toString(): String { | ||||||
|  |     return text.repeat(count) | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   companion object { | ||||||
|  |     fun of(text: CharSequence, count: Int): CharSequence { | ||||||
|  |       return when (count) { | ||||||
|  |         0 -> "" | ||||||
|  |         1 -> text | ||||||
|  |         else -> RepeatedCharSequence(text, count) | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -15,6 +15,7 @@ import com.maddyhome.idea.vim.KeyHandler | |||||||
| import com.maddyhome.idea.vim.VimPlugin | import com.maddyhome.idea.vim.VimPlugin | ||||||
| import com.maddyhome.idea.vim.api.ExecutionContext | import com.maddyhome.idea.vim.api.ExecutionContext | ||||||
| import com.maddyhome.idea.vim.api.VimCaret | import com.maddyhome.idea.vim.api.VimCaret | ||||||
|  | import com.maddyhome.idea.vim.api.VimChangeGroup | ||||||
| import com.maddyhome.idea.vim.api.VimEditor | import com.maddyhome.idea.vim.api.VimEditor | ||||||
| import com.maddyhome.idea.vim.api.endsWithNewLine | import com.maddyhome.idea.vim.api.endsWithNewLine | ||||||
| import com.maddyhome.idea.vim.api.getLeadingCharacterOffset | import com.maddyhome.idea.vim.api.getLeadingCharacterOffset | ||||||
| @@ -37,7 +38,10 @@ import com.maddyhome.idea.vim.extension.VimExtensionFacade.setRegisterForCaret | |||||||
| import com.maddyhome.idea.vim.extension.exportOperatorFunction | import com.maddyhome.idea.vim.extension.exportOperatorFunction | ||||||
| import com.maddyhome.idea.vim.group.findBlockRange | import com.maddyhome.idea.vim.group.findBlockRange | ||||||
| import com.maddyhome.idea.vim.helper.exitVisualMode | import com.maddyhome.idea.vim.helper.exitVisualMode | ||||||
|  | import com.maddyhome.idea.vim.helper.runWithEveryCaretAndRestore | ||||||
| import com.maddyhome.idea.vim.key.OperatorFunction | 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.ij | ||||||
| import com.maddyhome.idea.vim.newapi.vim | import com.maddyhome.idea.vim.newapi.vim | ||||||
| import com.maddyhome.idea.vim.options.helpers.ClipboardOptionHelper | import com.maddyhome.idea.vim.options.helpers.ClipboardOptionHelper | ||||||
| @@ -80,7 +84,7 @@ internal class VimSurroundExtension : VimExtension { | |||||||
|       putKeyMappingIfMissing(MappingMode.XO, injector.parser.parseKeys("S"), owner, injector.parser.parseKeys("<Plug>VSurround"), true) |       putKeyMappingIfMissing(MappingMode.XO, injector.parser.parseKeys("S"), owner, injector.parser.parseKeys("<Plug>VSurround"), true) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     VimExtensionFacade.exportOperatorFunction(OPERATOR_FUNC, Operator()) |     VimExtensionFacade.exportOperatorFunction(OPERATOR_FUNC, Operator(supportsMultipleCursors = false, count = 1)) // TODO | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   private class YSurroundHandler : ExtensionHandler { |   private class YSurroundHandler : ExtensionHandler { | ||||||
| @@ -108,7 +112,7 @@ internal class VimSurroundExtension : VimExtension { | |||||||
|         val lastNonWhiteSpaceOffset = getLastNonWhitespaceCharacterOffset(editor.text(), lineStartOffset, lineEndOffset) |         val lastNonWhiteSpaceOffset = getLastNonWhitespaceCharacterOffset(editor.text(), lineStartOffset, lineEndOffset) | ||||||
|         if (lastNonWhiteSpaceOffset != null) { |         if (lastNonWhiteSpaceOffset != null) { | ||||||
|           val range = TextRange(lineStartOffset, lastNonWhiteSpaceOffset + 1) |           val range = TextRange(lineStartOffset, lastNonWhiteSpaceOffset + 1) | ||||||
|           performSurround(pair, range, it) |           performSurround(pair, range, it, count = operatorArguments.count1) | ||||||
|         } |         } | ||||||
| //        it.moveToOffset(lineStartOffset) | //        it.moveToOffset(lineStartOffset) | ||||||
|       } |       } | ||||||
| @@ -131,15 +135,13 @@ internal class VimSurroundExtension : VimExtension { | |||||||
|  |  | ||||||
|   private class VSurroundHandler : ExtensionHandler { |   private class VSurroundHandler : ExtensionHandler { | ||||||
|     override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) { |     override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) { | ||||||
|       val selectionStart = editor.ij.caretModel.primaryCaret.selectionStart |  | ||||||
|       // NB: Operator ignores SelectionType anyway |       // NB: Operator ignores SelectionType anyway | ||||||
|       if (!Operator().apply(editor, context, editor.mode.selectionType)) { |       if (!Operator(supportsMultipleCursors = true, count = operatorArguments.count1).apply(editor, context, editor.mode.selectionType)) { | ||||||
|         return |         return | ||||||
|       } |       } | ||||||
|       runWriteAction { |       runWriteAction { | ||||||
|         // Leave visual mode |         // Leave visual mode | ||||||
|         editor.exitVisualMode() |         editor.exitVisualMode() | ||||||
|         editor.ij.caretModel.moveToOffset(selectionStart) |  | ||||||
|          |          | ||||||
|         // Reset the key handler so that the command trie is updated for the new mode (Normal) |         // Reset the key handler so that the command trie is updated for the new mode (Normal) | ||||||
|         // TODO: This should probably be handled by ToHandlerMapping.execute |         // TODO: This should probably be handled by ToHandlerMapping.execute | ||||||
| @@ -164,6 +166,10 @@ internal class VimSurroundExtension : VimExtension { | |||||||
|  |  | ||||||
|     companion object { |     companion object { | ||||||
|       fun change(editor: VimEditor, context: ExecutionContext, charFrom: Char, newSurround: SurroundPair?) { |       fun change(editor: VimEditor, context: ExecutionContext, charFrom: Char, newSurround: SurroundPair?) { | ||||||
|  |         editor.ij.runWithEveryCaretAndRestore { changeAtCaret(editor, context, charFrom, newSurround) } | ||||||
|  |       } | ||||||
|  |        | ||||||
|  |       fun changeAtCaret(editor: VimEditor, context: ExecutionContext, charFrom: Char, newSurround: SurroundPair?) { | ||||||
|         // Save old register values for carets |         // Save old register values for carets | ||||||
|         val surroundings = editor.sortedCarets() |         val surroundings = editor.sortedCarets() | ||||||
|           .map { |           .map { | ||||||
| @@ -206,7 +212,7 @@ internal class VimSurroundExtension : VimExtension { | |||||||
|               val trimmedValue = if (newSurround.shouldTrim) innerValue.trim() else innerValue |               val trimmedValue = if (newSurround.shouldTrim) innerValue.trim() else innerValue | ||||||
|               it.first + trimmedValue + it.second |               it.first + trimmedValue + it.second | ||||||
|             } ?: innerValue |             } ?: innerValue | ||||||
|             val textData = PutData.TextData(null, injector.clipboardManager.dumbCopiedText(text), SelectionType.CHARACTER_WISE) |             val textData = PutData.TextData(text, SelectionType.CHARACTER_WISE, emptyList(), null) | ||||||
|             val putData = PutData(textData, null, 1, insertTextBeforeCaret = true, rawIndent = true, caretAfterInsertedText = false) |             val putData = PutData(textData, null, 1, insertTextBeforeCaret = true, rawIndent = true, caretAfterInsertedText = false) | ||||||
|  |  | ||||||
|             surrounding.caret to putData |             surrounding.caret to putData | ||||||
| @@ -284,21 +290,42 @@ internal class VimSurroundExtension : VimExtension { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   private class Operator : OperatorFunction { |   private class Operator(private val supportsMultipleCursors: Boolean, private val count: Int) : OperatorFunction { | ||||||
|     override fun apply(editor: VimEditor, context: ExecutionContext, selectionType: SelectionType?): Boolean { |     override fun apply(vimEditor: VimEditor, context: ExecutionContext, selectionType: SelectionType?): Boolean { | ||||||
|       val ijEditor = editor.ij |       val ijEditor = vimEditor.ij | ||||||
|       val c = getChar(ijEditor) |       val c = getChar(ijEditor) | ||||||
|       if (c.code == 0) return true |       if (c.code == 0) return true | ||||||
|  |  | ||||||
|       val pair = getOrInputPair(c, ijEditor, context.ij) ?: return false |       val pair = getOrInputPair(c, ijEditor, context.ij) ?: return false | ||||||
|       // XXX: Will it work with line-wise or block-wise selections? |  | ||||||
|       val range = getSurroundRange(editor.currentCaret()) ?: return false |       runWriteAction { | ||||||
|       performSurround(pair, range, editor.currentCaret(), selectionType == SelectionType.LINE_WISE) |         val change = VimPlugin.getChange() | ||||||
|       // Jump back to start |         if (supportsMultipleCursors) { | ||||||
|       executeNormalWithoutMapping(injector.parser.parseKeys("`["), ijEditor) |           ijEditor.runWithEveryCaretAndRestore { | ||||||
|  |             applyOnce(ijEditor, change, pair, count) | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |           applyOnce(ijEditor, change, pair, count) | ||||||
|  |           // Jump back to start | ||||||
|  |           executeNormalWithoutMapping(injector.parser.parseKeys("`["), ijEditor) | ||||||
|  |         } | ||||||
|  |       } | ||||||
|       return true |       return true | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     private fun applyOnce(editor: Editor, change: VimChangeGroup, pair: SurroundPair, count: Int) { | ||||||
|  |       // XXX: Will it work with line-wise or block-wise selections? | ||||||
|  |       val primaryCaret = editor.caretModel.primaryCaret | ||||||
|  |       val range = getSurroundRange(primaryCaret.vim) | ||||||
|  |       if (range != null) { | ||||||
|  |         val start = RepeatedCharSequence.of(pair.first, count) | ||||||
|  |         val end = RepeatedCharSequence.of(pair.second, count) | ||||||
|  |         change.insertText(IjVimEditor(editor), IjVimCaret(primaryCaret), range.startOffset, start) | ||||||
|  |         change.insertText(IjVimEditor(editor), IjVimCaret(primaryCaret), range.endOffset + start.length, end) | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     private fun getSurroundRange(caret: VimCaret): TextRange? { |     private fun getSurroundRange(caret: VimCaret): TextRange? { | ||||||
|       val editor = caret.editor |       val editor = caret.editor | ||||||
|       if (editor.mode is Mode.CMD_LINE) { |       if (editor.mode is Mode.CMD_LINE) { | ||||||
| @@ -398,15 +425,15 @@ private fun getChar(editor: Editor): Char { | |||||||
|   return res |   return res | ||||||
| } | } | ||||||
|  |  | ||||||
| private fun performSurround(pair: SurroundPair, range: TextRange, caret: VimCaret, tagsOnNewLines: Boolean = false) { | private fun performSurround(pair: SurroundPair, range: TextRange, caret: VimCaret, count: Int, tagsOnNewLines: Boolean = false) { | ||||||
|   runWriteAction { |   runWriteAction { | ||||||
|     val editor = caret.editor |     val editor = caret.editor | ||||||
|     val change = VimPlugin.getChange() |     val change = VimPlugin.getChange() | ||||||
|     val leftSurround = pair.first + if (tagsOnNewLines) "\n" else "" |     val leftSurround = RepeatedCharSequence.of(pair.first + if (tagsOnNewLines) "\n" else "", count) | ||||||
|  |  | ||||||
|     val isEOF = range.endOffset == editor.text().length |     val isEOF = range.endOffset == editor.text().length | ||||||
|     val hasNewLine = editor.endsWithNewLine() |     val hasNewLine = editor.endsWithNewLine() | ||||||
|     val rightSurround = if (tagsOnNewLines) { |     val rightSurround = (if (tagsOnNewLines) { | ||||||
|       if (isEOF && !hasNewLine) { |       if (isEOF && !hasNewLine) { | ||||||
|         "\n" + pair.second |         "\n" + pair.second | ||||||
|       } else { |       } else { | ||||||
| @@ -414,7 +441,7 @@ private fun performSurround(pair: SurroundPair, range: TextRange, caret: VimCare | |||||||
|       } |       } | ||||||
|     } else { |     } else { | ||||||
|       pair.second |       pair.second | ||||||
|     } |     }).let { RepeatedCharSequence.of(it, count) } | ||||||
|  |  | ||||||
|     change.insertText(editor, caret, range.startOffset, leftSurround) |     change.insertText(editor, caret, range.startOffset, leftSurround) | ||||||
|     change.insertText(editor, caret, range.endOffset + leftSurround.length, rightSurround) |     change.insertText(editor, caret, range.endOffset + leftSurround.length, rightSurround) | ||||||
|   | |||||||
| @@ -43,7 +43,6 @@ import com.maddyhome.idea.vim.newapi.ij | |||||||
| import com.maddyhome.idea.vim.state.mode.Mode | import com.maddyhome.idea.vim.state.mode.Mode | ||||||
| import com.maddyhome.idea.vim.undo.VimKeyBasedUndoService | import com.maddyhome.idea.vim.undo.VimKeyBasedUndoService | ||||||
| import com.maddyhome.idea.vim.undo.VimTimestampBasedUndoService | import com.maddyhome.idea.vim.undo.VimTimestampBasedUndoService | ||||||
| import kotlin.math.min |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Provides all the insert/replace related functionality |  * Provides all the insert/replace related functionality | ||||||
| @@ -156,6 +155,7 @@ class ChangeGroup : VimChangeGroupBase() { | |||||||
|     context: ExecutionContext, |     context: ExecutionContext, | ||||||
|     range: TextRange, |     range: TextRange, | ||||||
|   ) { |   ) { | ||||||
|  |     val startPos = editor.offsetToBufferPosition(caret.offset) | ||||||
|     val startOffset = editor.getLineStartForOffset(range.startOffset) |     val startOffset = editor.getLineStartForOffset(range.startOffset) | ||||||
|     val endOffset = editor.getLineEndForOffset(range.endOffset) |     val endOffset = editor.getLineEndForOffset(range.endOffset) | ||||||
|     val ijEditor = (editor as IjVimEditor).editor |     val ijEditor = (editor as IjVimEditor).editor | ||||||
| @@ -165,7 +165,7 @@ class ChangeGroup : VimChangeGroupBase() { | |||||||
|     var copiedText: IjVimCopiedText? = null |     var copiedText: IjVimCopiedText? = null | ||||||
|     try { |     try { | ||||||
|       if (injector.registerGroup.isPrimaryRegisterSupported()) { |       if (injector.registerGroup.isPrimaryRegisterSupported()) { | ||||||
|         copiedText = injector.clipboardManager.getPrimaryContent(editor, context) as IjVimCopiedText |         copiedText = injector.clipboardManager.getPrimaryContent() as IjVimCopiedText | ||||||
|       } |       } | ||||||
|     } catch (e: Exception) { |     } catch (e: Exception) { | ||||||
|       // FIXME: [isPrimaryRegisterSupported()] is not implemented perfectly, so there might be thrown an exception after trying to access the primary selection |       // FIXME: [isPrimaryRegisterSupported()] is not implemented perfectly, so there might be thrown an exception after trying to access the primary selection | ||||||
| @@ -180,11 +180,7 @@ class ChangeGroup : VimChangeGroupBase() { | |||||||
|       } |       } | ||||||
|     } |     } | ||||||
|     val afterAction = { |     val afterAction = { | ||||||
|       val firstLine = editor.offsetToBufferPosition( |       caret.moveToOffset(injector.motion.moveCaretToLineStartSkipLeading(editor, startPos.line)) | ||||||
|         min(startOffset.toDouble(), endOffset.toDouble()).toInt() |  | ||||||
|       ).line |  | ||||||
|       val newOffset = injector.motion.moveCaretToLineStartSkipLeading(editor, firstLine) |  | ||||||
|       caret.moveToOffset(newOffset) |  | ||||||
|       restoreCursor(editor, caret, (caret as IjVimCaret).caret.logicalPosition.line) |       restoreCursor(editor, caret, (caret as IjVimCaret).caret.logicalPosition.line) | ||||||
|     } |     } | ||||||
|     if (project != null) { |     if (project != null) { | ||||||
|   | |||||||
| @@ -141,7 +141,7 @@ object IjOptions { | |||||||
|   // Temporary feature flags during development, not really intended for external use |   // Temporary feature flags during development, not really intended for external use | ||||||
|   val closenotebooks: ToggleOption = |   val closenotebooks: ToggleOption = | ||||||
|     addOption(ToggleOption("closenotebooks", GLOBAL, "closenotebooks", true, isHidden = true)) |     addOption(ToggleOption("closenotebooks", GLOBAL, "closenotebooks", true, isHidden = true)) | ||||||
|   val oldundo: ToggleOption = addOption(ToggleOption("oldundo", GLOBAL, "oldundo", false, isHidden = true)) |   val oldundo: ToggleOption = addOption(ToggleOption("oldundo", GLOBAL, "oldundo", true, isHidden = true)) | ||||||
|   val unifyjumps: ToggleOption = addOption(ToggleOption("unifyjumps", GLOBAL, "unifyjumps", true, isHidden = true)) |   val unifyjumps: ToggleOption = addOption(ToggleOption("unifyjumps", GLOBAL, "unifyjumps", true, isHidden = true)) | ||||||
|  |  | ||||||
|   // This needs to be Option<out VimDataType> so that it can work with derived option types, such as NumberOption, which |   // This needs to be Option<out VimDataType> so that it can work with derived option types, such as NumberOption, which | ||||||
|   | |||||||
| @@ -0,0 +1,68 @@ | |||||||
|  | package com.maddyhome.idea.vim.group | ||||||
|  |  | ||||||
|  | import com.intellij.codeInsight.daemon.ReferenceImporter | ||||||
|  | import com.intellij.openapi.actionSystem.CommonDataKeys | ||||||
|  | import com.intellij.openapi.actionSystem.DataContext | ||||||
|  | import com.intellij.openapi.application.ApplicationManager | ||||||
|  | import com.intellij.openapi.application.ReadAction | ||||||
|  | import com.intellij.openapi.command.WriteCommandAction | ||||||
|  | import com.intellij.openapi.editor.Editor | ||||||
|  | import com.intellij.openapi.fileEditor.FileDocumentManager | ||||||
|  | import com.intellij.openapi.progress.ProgressIndicator | ||||||
|  | import com.intellij.openapi.progress.ProgressManager | ||||||
|  | import com.intellij.openapi.progress.Task | ||||||
|  | import com.intellij.psi.PsiDocumentManager | ||||||
|  | import com.intellij.psi.PsiElement | ||||||
|  | import com.intellij.psi.PsiRecursiveElementWalkingVisitor | ||||||
|  | import java.util.function.BooleanSupplier | ||||||
|  |  | ||||||
|  | internal object MacroAutoImport { | ||||||
|  |   fun run(editor: Editor, dataContext: DataContext) { | ||||||
|  |     val project = CommonDataKeys.PROJECT.getData(dataContext) ?: return | ||||||
|  |     val file = PsiDocumentManager.getInstance(project).getPsiFile(editor.document) ?: return | ||||||
|  |  | ||||||
|  |     if (!FileDocumentManager.getInstance().requestWriting(editor.document, project)) { | ||||||
|  |       return | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     val importers = ReferenceImporter.EP_NAME.extensionList | ||||||
|  |     if (importers.isEmpty()) { | ||||||
|  |       return | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     ProgressManager.getInstance().run(object : Task.Backgroundable(project, "Auto import", true) { | ||||||
|  |       override fun run(indicator: ProgressIndicator) { | ||||||
|  |         val fixes = ReadAction.nonBlocking<List<BooleanSupplier>> { | ||||||
|  |           val fixes = mutableListOf<BooleanSupplier>() | ||||||
|  |  | ||||||
|  |           file.accept(object : PsiRecursiveElementWalkingVisitor() { | ||||||
|  |             override fun visitElement(element: PsiElement) { | ||||||
|  |               for (reference in element.references) { | ||||||
|  |                 if (reference.resolve() != null) { | ||||||
|  |                   continue | ||||||
|  |                 } | ||||||
|  |                 for (importer in importers) { | ||||||
|  |                   importer.computeAutoImportAtOffset(editor, file, element.textRange.startOffset, true) | ||||||
|  |                     ?.let(fixes::add) | ||||||
|  |                 } | ||||||
|  |               } | ||||||
|  |               super.visitElement(element) | ||||||
|  |             } | ||||||
|  |           }) | ||||||
|  |  | ||||||
|  |           return@nonBlocking fixes | ||||||
|  |         }.executeSynchronously() | ||||||
|  |  | ||||||
|  |         ApplicationManager.getApplication().invokeAndWait { | ||||||
|  |           WriteCommandAction.writeCommandAction(project) | ||||||
|  |             .withName("Auto Import") | ||||||
|  |             .withGroupId("IdeaVimAutoImportAfterMacro") | ||||||
|  |             .shouldRecordActionForActiveDocument(true) | ||||||
|  |             .run<RuntimeException> { | ||||||
|  |               fixes.forEach { it.asBoolean } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     }) | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -21,6 +21,7 @@ import com.maddyhome.idea.vim.api.injector | |||||||
| import com.maddyhome.idea.vim.helper.MessageHelper.message | import com.maddyhome.idea.vim.helper.MessageHelper.message | ||||||
| import com.maddyhome.idea.vim.macro.VimMacroBase | import com.maddyhome.idea.vim.macro.VimMacroBase | ||||||
| import com.maddyhome.idea.vim.newapi.IjVimEditor | import com.maddyhome.idea.vim.newapi.IjVimEditor | ||||||
|  | import com.maddyhome.idea.vim.newapi.ij | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Used to handle playback of macros |  * Used to handle playback of macros | ||||||
| @@ -89,6 +90,9 @@ internal class MacroGroup : VimMacroBase() { | |||||||
|         } finally { |         } finally { | ||||||
|           keyStack.removeFirst() |           keyStack.removeFirst() | ||||||
|         } |         } | ||||||
|  |         if (!isInternalMacro) { | ||||||
|  |           MacroAutoImport.run(editor.ij, context.ij) | ||||||
|  |         } | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       if (isInternalMacro) { |       if (isInternalMacro) { | ||||||
|   | |||||||
| @@ -89,6 +89,9 @@ internal class MotionGroup : VimMotionGroupBase() { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   override fun moveCaretToCurrentDisplayLineStart(editor: VimEditor, caret: ImmutableVimCaret): Motion { |   override fun moveCaretToCurrentDisplayLineStart(editor: VimEditor, caret: ImmutableVimCaret): Motion { | ||||||
|  |     if (editor.ij.softWrapModel.isSoftWrappingEnabled) { | ||||||
|  |       return AbsoluteOffset(caret.ij.visualLineStart) | ||||||
|  |     } | ||||||
|     val col = EditorHelper.getVisualColumnAtLeftOfDisplay(editor.ij, caret.getVisualPosition().line) |     val col = EditorHelper.getVisualColumnAtLeftOfDisplay(editor.ij, caret.getVisualPosition().line) | ||||||
|     return moveCaretToColumn(editor, caret, col, false) |     return moveCaretToColumn(editor, caret, col, false) | ||||||
|   } |   } | ||||||
| @@ -97,6 +100,15 @@ internal class MotionGroup : VimMotionGroupBase() { | |||||||
|     editor: VimEditor, |     editor: VimEditor, | ||||||
|     caret: ImmutableVimCaret, |     caret: ImmutableVimCaret, | ||||||
|   ): @Range(from = 0, to = Int.MAX_VALUE.toLong()) Int { |   ): @Range(from = 0, to = Int.MAX_VALUE.toLong()) Int { | ||||||
|  |     if (editor.ij.softWrapModel.isSoftWrappingEnabled) { | ||||||
|  |       val offset = caret.ij.visualLineStart | ||||||
|  |       val line = editor.offsetToBufferPosition(offset).line | ||||||
|  |       return if (offset == editor.getLineStartOffset(line)) { | ||||||
|  |         editor.getLeadingCharacterOffset(line, 0) | ||||||
|  |       } else { | ||||||
|  |         offset | ||||||
|  |       } | ||||||
|  |     } | ||||||
|     val col = EditorHelper.getVisualColumnAtLeftOfDisplay(editor.ij, caret.getVisualPosition().line) |     val col = EditorHelper.getVisualColumnAtLeftOfDisplay(editor.ij, caret.getVisualPosition().line) | ||||||
|     val bufferLine = caret.getLine() |     val bufferLine = caret.getLine() | ||||||
|     return editor.getLeadingCharacterOffset(bufferLine, col) |     return editor.getLeadingCharacterOffset(bufferLine, col) | ||||||
| @@ -107,6 +119,9 @@ internal class MotionGroup : VimMotionGroupBase() { | |||||||
|     caret: ImmutableVimCaret, |     caret: ImmutableVimCaret, | ||||||
|     allowEnd: Boolean, |     allowEnd: Boolean, | ||||||
|   ): Motion { |   ): Motion { | ||||||
|  |     if (editor.ij.softWrapModel.isSoftWrappingEnabled) { | ||||||
|  |       return AbsoluteOffset(caret.ij.visualLineEnd - 1) | ||||||
|  |     } | ||||||
|     val col = EditorHelper.getVisualColumnAtRightOfDisplay(editor.ij, caret.getVisualPosition().line) |     val col = EditorHelper.getVisualColumnAtRightOfDisplay(editor.ij, caret.getVisualPosition().line) | ||||||
|     return moveCaretToColumn(editor, caret, col, allowEnd) |     return moveCaretToColumn(editor, caret, col, allowEnd) | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -33,7 +33,6 @@ import com.intellij.openapi.ui.Messages | |||||||
| import com.intellij.openapi.util.SystemInfo | import com.intellij.openapi.util.SystemInfo | ||||||
| import com.maddyhome.idea.vim.VimPlugin | import com.maddyhome.idea.vim.VimPlugin | ||||||
| import com.maddyhome.idea.vim.api.VimEditor | import com.maddyhome.idea.vim.api.VimEditor | ||||||
| import com.maddyhome.idea.vim.api.globalOptions |  | ||||||
| import com.maddyhome.idea.vim.api.injector | import com.maddyhome.idea.vim.api.injector | ||||||
| import com.maddyhome.idea.vim.handler.KeyMapIssue | import com.maddyhome.idea.vim.handler.KeyMapIssue | ||||||
| import com.maddyhome.idea.vim.helper.MessageHelper | import com.maddyhome.idea.vim.helper.MessageHelper | ||||||
| @@ -41,8 +40,6 @@ import com.maddyhome.idea.vim.icons.VimIcons | |||||||
| import com.maddyhome.idea.vim.key.ShortcutOwner | import com.maddyhome.idea.vim.key.ShortcutOwner | ||||||
| import com.maddyhome.idea.vim.key.ShortcutOwnerInfo | import com.maddyhome.idea.vim.key.ShortcutOwnerInfo | ||||||
| import com.maddyhome.idea.vim.newapi.globalIjOptions | import com.maddyhome.idea.vim.newapi.globalIjOptions | ||||||
| import com.maddyhome.idea.vim.newapi.ijOptions |  | ||||||
| import com.maddyhome.idea.vim.options.OptionConstants |  | ||||||
| import com.maddyhome.idea.vim.statistic.ActionTracker | import com.maddyhome.idea.vim.statistic.ActionTracker | ||||||
| import com.maddyhome.idea.vim.ui.VimEmulationConfigurable | import com.maddyhome.idea.vim.ui.VimEmulationConfigurable | ||||||
| import com.maddyhome.idea.vim.vimscript.services.VimRcService | import com.maddyhome.idea.vim.vimscript.services.VimRcService | ||||||
| @@ -62,55 +59,11 @@ internal class NotificationService(private val project: Project?) { | |||||||
|   @Suppress("unused") |   @Suppress("unused") | ||||||
|   constructor() : this(null) |   constructor() : this(null) | ||||||
|  |  | ||||||
|   fun notifyAboutIdeaPut() { |   fun notifyAboutNewUndo() {} | ||||||
|     val notification = Notification( |  | ||||||
|       IDEAVIM_NOTIFICATION_ID, |  | ||||||
|       IDEAVIM_NOTIFICATION_TITLE, |  | ||||||
|       """Add <code>ideaput</code> to <code>clipboard</code> option to perform a put via the IDE<br/><b><code>set clipboard+=ideaput</code></b>""", |  | ||||||
|       NotificationType.INFORMATION, |  | ||||||
|     ) |  | ||||||
|  |  | ||||||
|     notification.addAction(OpenIdeaVimRcAction(notification)) |   fun notifyAboutIdeaPut() {} | ||||||
|  |  | ||||||
|     notification.addAction( |   fun notifyAboutIdeaJoin(editor: VimEditor) {} | ||||||
|       AppendToIdeaVimRcAction( |  | ||||||
|         notification, |  | ||||||
|         "set clipboard^=ideaput", |  | ||||||
|         "ideaput", |  | ||||||
|       ) { |  | ||||||
|         // Technically, we're supposed to prepend values to clipboard so that it's not added to the "exclude" item. |  | ||||||
|         // Since we don't handle exclude, it's safe to append. But let's be clean. |  | ||||||
|         injector.globalOptions().clipboard.prependValue(OptionConstants.clipboard_ideaput) |  | ||||||
|       }, |  | ||||||
|     ) |  | ||||||
|  |  | ||||||
|     notification.notify(project) |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   fun notifyAboutIdeaJoin(editor: VimEditor) { |  | ||||||
|     val notification = Notification( |  | ||||||
|       IDEAVIM_NOTIFICATION_ID, |  | ||||||
|       IDEAVIM_NOTIFICATION_TITLE, |  | ||||||
|       """Put <b><code>set ideajoin</code></b> into your <code>~/.ideavimrc</code> to perform a join via the IDE""", |  | ||||||
|       NotificationType.INFORMATION, |  | ||||||
|     ) |  | ||||||
|  |  | ||||||
|     notification.addAction(OpenIdeaVimRcAction(notification)) |  | ||||||
|  |  | ||||||
|     notification.addAction( |  | ||||||
|       AppendToIdeaVimRcAction( |  | ||||||
|         notification, |  | ||||||
|         "set ideajoin", |  | ||||||
|         "ideajoin" |  | ||||||
|       ) { |  | ||||||
|         // This is a global-local option. Setting it will always set the global value |  | ||||||
|         injector.ijOptions(editor).ideajoin = true |  | ||||||
|       }, |  | ||||||
|     ) |  | ||||||
|  |  | ||||||
|     notification.addAction(HelpLink(ideajoinExamplesUrl)) |  | ||||||
|     notification.notify(project) |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   fun enableRepeatingMode() = Messages.showYesNoDialog( |   fun enableRepeatingMode() = Messages.showYesNoDialog( | ||||||
|     "Do you want to enable repeating keys in macOS on press and hold?\n\n" + |     "Do you want to enable repeating keys in macOS on press and hold?\n\n" + | ||||||
| @@ -305,16 +258,16 @@ internal class NotificationService(private val project: Project?) { | |||||||
|  |  | ||||||
|       notification = |       notification = | ||||||
|         Notification(IDEAVIM_NOTIFICATION_ID, IDEAVIM_NOTIFICATION_TITLE, content, NotificationType.INFORMATION).also { |         Notification(IDEAVIM_NOTIFICATION_ID, IDEAVIM_NOTIFICATION_TITLE, content, NotificationType.INFORMATION).also { | ||||||
|           it.whenExpired { notification = null } |         it.whenExpired { notification = null } | ||||||
|           it.addAction(StopTracking()) |         it.addAction(StopTracking()) | ||||||
|  |  | ||||||
|           if (id != null || possibleIDs?.size == 1) { |         if (id != null || possibleIDs?.size == 1) { | ||||||
|             it.addAction(CopyActionId(id ?: possibleIDs?.get(0), project)) |           it.addAction(CopyActionId(id ?: possibleIDs?.get(0), project)) | ||||||
|           } |  | ||||||
|  |  | ||||||
|           it.notify(project) |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         it.notify(project) | ||||||
|  |       } | ||||||
|  |  | ||||||
|       if (id != null) { |       if (id != null) { | ||||||
|         ActionTracker.Util.logTrackedAction(id) |         ActionTracker.Util.logTrackedAction(id) | ||||||
|       } |       } | ||||||
|   | |||||||
| @@ -25,10 +25,9 @@ import org.jetbrains.annotations.Nullable; | |||||||
| import javax.swing.*; | import javax.swing.*; | ||||||
| import java.awt.event.KeyEvent; | import java.awt.event.KeyEvent; | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
|  | import java.util.Collections; | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  |  | ||||||
| import static com.maddyhome.idea.vim.api.VimInjectorKt.injector; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * This group works with command associated with copying and pasting text |  * This group works with command associated with copying and pasting text | ||||||
|  */ |  */ | ||||||
| @@ -128,7 +127,7 @@ public class RegisterGroup extends VimRegisterGroupBase implements PersistentSta | |||||||
|           final String text = VimPlugin.getXML().getSafeXmlText(textElement); |           final String text = VimPlugin.getXML().getSafeXmlText(textElement); | ||||||
|           if (text != null) { |           if (text != null) { | ||||||
|             logger.trace("Register data parsed"); |             logger.trace("Register data parsed"); | ||||||
|             register = new Register(key, injector.getClipboardManager().dumbCopiedText(text), type); |             register = new Register(key, type, text, Collections.emptyList()); | ||||||
|           } |           } | ||||||
|           else { |           else { | ||||||
|             logger.trace("Cannot parse register data"); |             logger.trace("Cannot parse register data"); | ||||||
|   | |||||||
| @@ -37,7 +37,6 @@ import com.maddyhome.idea.vim.ide.isClionNova | |||||||
| import com.maddyhome.idea.vim.ide.isRider | import com.maddyhome.idea.vim.ide.isRider | ||||||
| import com.maddyhome.idea.vim.mark.VimMarkConstants.MARK_CHANGE_POS | import com.maddyhome.idea.vim.mark.VimMarkConstants.MARK_CHANGE_POS | ||||||
| import com.maddyhome.idea.vim.newapi.IjVimCaret | import com.maddyhome.idea.vim.newapi.IjVimCaret | ||||||
| import com.maddyhome.idea.vim.newapi.IjVimCopiedText |  | ||||||
| import com.maddyhome.idea.vim.newapi.IjVimEditor | import com.maddyhome.idea.vim.newapi.IjVimEditor | ||||||
| import com.maddyhome.idea.vim.newapi.ij | import com.maddyhome.idea.vim.newapi.ij | ||||||
| import com.maddyhome.idea.vim.newapi.vim | import com.maddyhome.idea.vim.newapi.vim | ||||||
| @@ -128,7 +127,7 @@ internal class PutGroup : VimPutBase() { | |||||||
|       point.dispose() |       point.dispose() | ||||||
|       if (!caret.isValid) return@forEach |       if (!caret.isValid) return@forEach | ||||||
|  |  | ||||||
|       val caretPossibleEndOffset = lastPastedRegion?.endOffset ?: (startOffset + text.copiedText.text.length) |       val caretPossibleEndOffset = lastPastedRegion?.endOffset ?: (startOffset + text.text.length) | ||||||
|       val endOffset = if (data.indent) { |       val endOffset = if (data.indent) { | ||||||
|         doIndent( |         doIndent( | ||||||
|           vimEditor, |           vimEditor, | ||||||
| @@ -180,10 +179,12 @@ internal class PutGroup : VimPutBase() { | |||||||
|     val allContentsBefore = CopyPasteManager.getInstance().allContents |     val allContentsBefore = CopyPasteManager.getInstance().allContents | ||||||
|     val sizeBeforeInsert = allContentsBefore.size |     val sizeBeforeInsert = allContentsBefore.size | ||||||
|     val firstItemBefore = allContentsBefore.firstOrNull() |     val firstItemBefore = allContentsBefore.firstOrNull() | ||||||
|     logger.debug { "Copied text: ${text.copiedText}" } |     logger.debug { "Transferable classes: ${text.transferableData.joinToString { it.javaClass.name }}" } | ||||||
|     val (textContent, transferableData) = text.copiedText as IjVimCopiedText |  | ||||||
|     val origContent: TextBlockTransferable = |     val origContent: TextBlockTransferable = | ||||||
|       injector.clipboardManager.setClipboardText(textContent, textContent, transferableData) as TextBlockTransferable |       injector.clipboardManager.setClipboardText( | ||||||
|  |       text.text, | ||||||
|  |       transferableData = text.transferableData, | ||||||
|  |     ) as TextBlockTransferable | ||||||
|     val allContentsAfter = CopyPasteManager.getInstance().allContents |     val allContentsAfter = CopyPasteManager.getInstance().allContents | ||||||
|     val sizeAfterInsert = allContentsAfter.size |     val sizeAfterInsert = allContentsAfter.size | ||||||
|     try { |     try { | ||||||
| @@ -191,7 +192,7 @@ internal class PutGroup : VimPutBase() { | |||||||
|     } finally { |     } finally { | ||||||
|       val textInClipboard = (firstItemBefore as? TextBlockTransferable) |       val textInClipboard = (firstItemBefore as? TextBlockTransferable) | ||||||
|         ?.getTransferData(DataFlavor.stringFlavor) as? String |         ?.getTransferData(DataFlavor.stringFlavor) as? String | ||||||
|       val textOnTop = textInClipboard != null && textInClipboard != text.copiedText.text |       val textOnTop = textInClipboard != null && textInClipboard != text.text | ||||||
|       if (sizeBeforeInsert != sizeAfterInsert || textOnTop) { |       if (sizeBeforeInsert != sizeAfterInsert || textOnTop) { | ||||||
|         // Sometimes an inserted text replaces an existing one. E.g. on insert with + or * register |         // Sometimes an inserted text replaces an existing one. E.g. on insert with + or * register | ||||||
|         (CopyPasteManager.getInstance() as? CopyPasteManagerEx)?.run { removeContent(origContent) } |         (CopyPasteManager.getInstance() as? CopyPasteManagerEx)?.run { removeContent(origContent) } | ||||||
|   | |||||||
| @@ -134,7 +134,7 @@ internal object IdeaSelectionControl { | |||||||
|       is Mode.VISUAL -> VimPlugin.getVisualMotion().enterVisualMode(editor.vim, mode.selectionType) |       is Mode.VISUAL -> VimPlugin.getVisualMotion().enterVisualMode(editor.vim, mode.selectionType) | ||||||
|       is Mode.SELECT -> VimPlugin.getVisualMotion().enterSelectMode(editor.vim, mode.selectionType) |       is Mode.SELECT -> VimPlugin.getVisualMotion().enterSelectMode(editor.vim, mode.selectionType) | ||||||
|       is Mode.INSERT -> VimPlugin.getChange() |       is Mode.INSERT -> VimPlugin.getChange() | ||||||
|         .insertBeforeCursor(editor.vim, injector.executionContextManager.getEditorExecutionContext(editor.vim)) |         .insertBeforeCaret(editor.vim, injector.executionContextManager.getEditorExecutionContext(editor.vim)) | ||||||
|  |  | ||||||
|       is Mode.NORMAL -> Unit |       is Mode.NORMAL -> Unit | ||||||
|       else -> error("Unexpected mode: $mode") |       else -> error("Unexpected mode: $mode") | ||||||
|   | |||||||
| @@ -344,7 +344,7 @@ public class EditorHelper { | |||||||
|  |  | ||||||
|     final int offset = y - ((screenHeight - lineHeight) / lineHeight / 2 * lineHeight); |     final int offset = y - ((screenHeight - lineHeight) / lineHeight / 2 * lineHeight); | ||||||
|     final @NotNull VimEditor editor1 = new IjVimEditor(editor); |     final @NotNull VimEditor editor1 = new IjVimEditor(editor); | ||||||
|     final int lastVisualLine = EngineEditorHelperKt.getVisualLineCount(editor1) - 1; |     final int lastVisualLine = EngineEditorHelperKt.getVisualLineCount(editor1) + editor.getSettings().getAdditionalLinesCount(); | ||||||
|     final int offsetForLastLineAtBottom = getOffsetToScrollVisualLineToBottomOfScreen(editor, lastVisualLine); |     final int offsetForLastLineAtBottom = getOffsetToScrollVisualLineToBottomOfScreen(editor, lastVisualLine); | ||||||
|  |  | ||||||
|     // For `zz`, we want to use virtual space and move any line, including the last one, to the middle of the screen. |     // For `zz`, we want to use virtual space and move any line, including the last one, to the middle of the screen. | ||||||
|   | |||||||
| @@ -12,7 +12,9 @@ package com.maddyhome.idea.vim.helper | |||||||
|  |  | ||||||
| import com.intellij.codeWithMe.ClientId | import com.intellij.codeWithMe.ClientId | ||||||
| import com.intellij.openapi.editor.Caret | import com.intellij.openapi.editor.Caret | ||||||
|  | import com.intellij.openapi.editor.CaretState | ||||||
| import com.intellij.openapi.editor.Editor | import com.intellij.openapi.editor.Editor | ||||||
|  | import com.intellij.openapi.editor.EditorKind | ||||||
| import com.intellij.openapi.editor.ex.util.EditorUtil | import com.intellij.openapi.editor.ex.util.EditorUtil | ||||||
| import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx | import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx | ||||||
| import com.intellij.util.ui.table.JBTableRowEditor | import com.intellij.util.ui.table.JBTableRowEditor | ||||||
| @@ -21,6 +23,8 @@ import com.maddyhome.idea.vim.api.injector | |||||||
| import com.maddyhome.idea.vim.group.IjOptionConstants | import com.maddyhome.idea.vim.group.IjOptionConstants | ||||||
| import com.maddyhome.idea.vim.key.IdeaVimDisablerExtensionPoint | import com.maddyhome.idea.vim.key.IdeaVimDisablerExtensionPoint | ||||||
| import com.maddyhome.idea.vim.newapi.globalIjOptions | import com.maddyhome.idea.vim.newapi.globalIjOptions | ||||||
|  | import com.maddyhome.idea.vim.newapi.vim | ||||||
|  | import com.maddyhome.idea.vim.state.mode.inBlockSelection | ||||||
| import java.awt.Component | import java.awt.Component | ||||||
| import javax.swing.JComponent | import javax.swing.JComponent | ||||||
| import javax.swing.JTable | import javax.swing.JTable | ||||||
| @@ -102,8 +106,7 @@ internal fun Editor.isPrimaryEditor(): Boolean { | |||||||
| internal fun Editor.isTerminalEditor(): Boolean { | internal fun Editor.isTerminalEditor(): Boolean { | ||||||
|   return !isViewer |   return !isViewer | ||||||
|     && document.isWritable |     && document.isWritable | ||||||
|     && !EditorHelper.isFileEditor(this) |     && this.editorKind == EditorKind.CONSOLE | ||||||
|     && !EditorHelper.isDiffEditor(this) |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // Optimized clone of com.intellij.ide.ui.laf.darcula.DarculaUIUtil.isTableCellEditor | // Optimized clone of com.intellij.ide.ui.laf.darcula.DarculaUIUtil.isTableCellEditor | ||||||
| @@ -136,3 +139,41 @@ internal val Caret.vimLine: Int | |||||||
|  */ |  */ | ||||||
| internal val Editor.vimLine: Int | internal val Editor.vimLine: Int | ||||||
|   get() = this.caretModel.currentCaret.vimLine |   get() = this.caretModel.currentCaret.vimLine | ||||||
|  |  | ||||||
|  | internal inline fun Editor.runWithEveryCaretAndRestore(action: () -> Unit) { | ||||||
|  |   val caretModel = this.caretModel | ||||||
|  |   val carets = if (this.vim.inBlockSelection) null else caretModel.allCarets | ||||||
|  |   if (carets == null || carets.size == 1) { | ||||||
|  |     action() | ||||||
|  |   } | ||||||
|  |   else { | ||||||
|  |     var initialDocumentSize = this.document.textLength | ||||||
|  |     var documentSizeDifference = 0 | ||||||
|  |  | ||||||
|  |     val caretOffsets = carets.map { it.selectionStart to it.selectionEnd } | ||||||
|  |     val restoredCarets = mutableListOf<CaretState>() | ||||||
|  |  | ||||||
|  |     caretModel.removeSecondaryCarets() | ||||||
|  |      | ||||||
|  |     for ((selectionStart, selectionEnd) in caretOffsets) { | ||||||
|  |       if (selectionStart == selectionEnd) { | ||||||
|  |         caretModel.primaryCaret.moveToOffset(selectionStart + documentSizeDifference) | ||||||
|  |       } | ||||||
|  |       else { | ||||||
|  |         caretModel.primaryCaret.setSelection( | ||||||
|  |           selectionStart + documentSizeDifference, | ||||||
|  |           selectionEnd + documentSizeDifference | ||||||
|  |         ) | ||||||
|  |       } | ||||||
|  |        | ||||||
|  |       action() | ||||||
|  |       restoredCarets.add(caretModel.caretsAndSelections.single()) | ||||||
|  |  | ||||||
|  |       val documentLength = this.document.textLength | ||||||
|  |       documentSizeDifference += documentLength - initialDocumentSize | ||||||
|  |       initialDocumentSize = documentLength | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     caretModel.caretsAndSelections = restoredCarets | ||||||
|  |   }  | ||||||
|  | } | ||||||
|   | |||||||
| @@ -59,7 +59,7 @@ internal object ScrollViewHelper { | |||||||
|     // that this needs to be replaced as a more or less dumb line for line rewrite. |     // that this needs to be replaced as a more or less dumb line for line rewrite. | ||||||
|     val topLine = getVisualLineAtTopOfScreen(editor) |     val topLine = getVisualLineAtTopOfScreen(editor) | ||||||
|     val bottomLine = getVisualLineAtBottomOfScreen(editor) |     val bottomLine = getVisualLineAtBottomOfScreen(editor) | ||||||
|     val lastLine = vimEditor.getVisualLineCount() - 1 |     val lastLine = vimEditor.getVisualLineCount() + editor.settings.additionalLinesCount | ||||||
|  |  | ||||||
|     // We need the non-normalised value here, so we can handle cases such as so=999 to keep the current line centred |     // We need the non-normalised value here, so we can handle cases such as so=999 to keep the current line centred | ||||||
|     val scrollOffset = injector.options(vimEditor).scrolloff |     val scrollOffset = injector.options(vimEditor).scrolloff | ||||||
|   | |||||||
| @@ -17,6 +17,7 @@ import com.intellij.openapi.editor.markup.HighlighterLayer | |||||||
| import com.intellij.openapi.editor.markup.HighlighterTargetArea | import com.intellij.openapi.editor.markup.HighlighterTargetArea | ||||||
| import com.intellij.openapi.editor.markup.RangeHighlighter | import com.intellij.openapi.editor.markup.RangeHighlighter | ||||||
| import com.intellij.openapi.editor.markup.TextAttributes | import com.intellij.openapi.editor.markup.TextAttributes | ||||||
|  | import com.intellij.util.application | ||||||
| import com.maddyhome.idea.vim.api.VimEditor | import com.maddyhome.idea.vim.api.VimEditor | ||||||
| import com.maddyhome.idea.vim.api.globalOptions | import com.maddyhome.idea.vim.api.globalOptions | ||||||
| import com.maddyhome.idea.vim.api.injector | import com.maddyhome.idea.vim.api.injector | ||||||
| @@ -30,6 +31,7 @@ import com.maddyhome.idea.vim.state.mode.inVisualMode | |||||||
| import org.jetbrains.annotations.Contract | import org.jetbrains.annotations.Contract | ||||||
| import java.awt.Font | import java.awt.Font | ||||||
| import java.util.* | import java.util.* | ||||||
|  | import javax.swing.Timer | ||||||
|  |  | ||||||
| internal fun updateSearchHighlights( | internal fun updateSearchHighlights( | ||||||
|   pattern: String?, |   pattern: String?, | ||||||
| @@ -84,6 +86,12 @@ internal fun addSubstitutionConfirmationHighlight(editor: Editor, start: Int, en | |||||||
|   ) |   ) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | val removeHighlightsEditors = mutableListOf<Editor>() | ||||||
|  | val removeHighlightsTimer = Timer(400) { | ||||||
|  |   removeHighlightsEditors.forEach(::removeSearchHighlights) | ||||||
|  |   removeHighlightsEditors.clear() | ||||||
|  | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Refreshes current search highlights for all visible editors |  * Refreshes current search highlights for all visible editors | ||||||
|  */ |  */ | ||||||
| @@ -125,27 +133,43 @@ private fun updateSearchHighlights( | |||||||
|       // hlsearch (+ incsearch/noincsearch) |       // hlsearch (+ incsearch/noincsearch) | ||||||
|       // Make sure the range fits this editor. Note that Vim will use the same range for all windows. E.g., given |       // Make sure the range fits this editor. Note that Vim will use the same range for all windows. E.g., given | ||||||
|       // `:1,5s/foo`, Vim will highlight all occurrences of `foo` in the first five lines of all visible windows |       // `:1,5s/foo`, Vim will highlight all occurrences of `foo` in the first five lines of all visible windows | ||||||
|       val vimEditor = editor.vim |       val isSearching = injector.commandLine.getActiveCommandLine() != null | ||||||
|       val editorLastLine = vimEditor.lineCount() - 1 |       application.invokeLater { | ||||||
|       val searchStartLine = searchRange?.startLine ?: 0 |         val vimEditor = editor.vim | ||||||
|       val searchEndLine = (searchRange?.endLine ?: -1).coerceAtMost(editorLastLine) |         val editorLastLine = vimEditor.lineCount() - 1 | ||||||
|       if (searchStartLine <= editorLastLine) { |         val searchStartLine = searchRange?.startLine ?: 0 | ||||||
|         val results = |         val searchEndLine = (searchRange?.endLine ?: -1).coerceAtMost(editorLastLine) | ||||||
|           injector.searchHelper.findAll( |         if (searchStartLine <= editorLastLine) { | ||||||
|             vimEditor, |           val visibleArea = editor.scrollingModel.visibleAreaOnScrollingFinished | ||||||
|             pattern, |           val visibleTopLeft = visibleArea.location | ||||||
|             searchStartLine, |           val visibleBottomRight = visibleArea.location.apply { translate(visibleArea.width, visibleArea.height) } | ||||||
|             searchEndLine, |           val visibleStartOffset = editor.logicalPositionToOffset(editor.xyToLogicalPosition(visibleTopLeft)) | ||||||
|             shouldIgnoreCase(pattern, shouldIgnoreSmartCase) |           val visibleEndOffset = editor.logicalPositionToOffset(editor.xyToLogicalPosition(visibleBottomRight)) | ||||||
|           ) |           val visibleStartLine = editor.document.getLineNumber(visibleStartOffset) | ||||||
|         if (results.isNotEmpty()) { |           val visibleEndLine = editor.document.getLineNumber(visibleEndOffset) | ||||||
|           if (editor === currentEditor?.ij) { |           removeSearchHighlights(editor) | ||||||
|             currentMatchOffset = findClosestMatch(results, initialOffset, count1, forwards) |  | ||||||
|  |           val results = | ||||||
|  |             injector.searchHelper.findAll( | ||||||
|  |               vimEditor, | ||||||
|  |               pattern, | ||||||
|  |               searchStartLine.coerceAtLeast(visibleStartLine), | ||||||
|  |               searchEndLine.coerceAtMost(visibleEndLine), | ||||||
|  |               shouldIgnoreCase(pattern, shouldIgnoreSmartCase) | ||||||
|  |             ) | ||||||
|  |           if (results.isNotEmpty()) { | ||||||
|  |             if (editor === currentEditor?.ij) { | ||||||
|  |               currentMatchOffset = findClosestMatch(results, initialOffset, count1, forwards) | ||||||
|  |             } | ||||||
|  |             highlightSearchResults(editor, pattern, results, currentMatchOffset) | ||||||
|  |             if (!isSearching) { | ||||||
|  |               removeHighlightsEditors.add(editor) | ||||||
|  |               removeHighlightsTimer.restart() | ||||||
|  |             } | ||||||
|           } |           } | ||||||
|           highlightSearchResults(editor, pattern, results, currentMatchOffset) |  | ||||||
|         } |         } | ||||||
|  |         editor.vimLastSearch = pattern | ||||||
|       } |       } | ||||||
|       editor.vimLastSearch = pattern |  | ||||||
|     } else if (shouldAddCurrentMatchSearchHighlight(pattern, showHighlights, initialOffset)) { |     } else if (shouldAddCurrentMatchSearchHighlight(pattern, showHighlights, initialOffset)) { | ||||||
|       // nohlsearch + incsearch. Even though search highlights are disabled, we still show a highlight (current editor |       // nohlsearch + incsearch. Even though search highlights are disabled, we still show a highlight (current editor | ||||||
|       // only), because 'incsearch' is active. But we don't show a search if Visual is active (behind Command-line of |       // only), because 'incsearch' is active. But we don't show a search if Visual is active (behind Command-line of | ||||||
| @@ -179,6 +203,7 @@ private fun updateSearchHighlights( | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   removeHighlightsTimer.restart() | ||||||
|   return currentEditorCurrentMatchOffset |   return currentEditorCurrentMatchOffset | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -204,7 +229,7 @@ private fun removeSearchHighlights(editor: Editor) { | |||||||
|  */ |  */ | ||||||
| @Contract("_, _, false -> false; _, null, true -> false") | @Contract("_, _, false -> false; _, null, true -> false") | ||||||
| private fun shouldAddAllSearchHighlights(editor: Editor, newPattern: String?, hlSearch: Boolean): Boolean { | private fun shouldAddAllSearchHighlights(editor: Editor, newPattern: String?, hlSearch: Boolean): Boolean { | ||||||
|   return hlSearch && newPattern != null && newPattern != editor.vimLastSearch && newPattern != "" |   return hlSearch && newPattern != null && newPattern != "" | ||||||
| } | } | ||||||
|  |  | ||||||
| private fun findClosestMatch( | private fun findClosestMatch( | ||||||
|   | |||||||
| @@ -20,6 +20,7 @@ import com.intellij.openapi.fileEditor.TextEditorWithPreview | |||||||
| import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider | import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider | ||||||
| import com.intellij.openapi.util.registry.Registry | import com.intellij.openapi.util.registry.Registry | ||||||
| import com.intellij.util.PlatformUtils | import com.intellij.util.PlatformUtils | ||||||
|  | import com.maddyhome.idea.vim.VimPlugin | ||||||
| import com.maddyhome.idea.vim.api.ExecutionContext | import com.maddyhome.idea.vim.api.ExecutionContext | ||||||
| import com.maddyhome.idea.vim.api.VimCaret | import com.maddyhome.idea.vim.api.VimCaret | ||||||
| import com.maddyhome.idea.vim.api.VimEditor | import com.maddyhome.idea.vim.api.VimEditor | ||||||
| @@ -29,6 +30,8 @@ import com.maddyhome.idea.vim.common.InsertSequence | |||||||
| import com.maddyhome.idea.vim.newapi.IjVimCaret | import com.maddyhome.idea.vim.newapi.IjVimCaret | ||||||
| import com.maddyhome.idea.vim.newapi.globalIjOptions | import com.maddyhome.idea.vim.newapi.globalIjOptions | ||||||
| import com.maddyhome.idea.vim.newapi.ij | import com.maddyhome.idea.vim.newapi.ij | ||||||
|  | import com.maddyhome.idea.vim.state.mode.SelectionType | ||||||
|  | import com.maddyhome.idea.vim.state.mode.inVisualMode | ||||||
| import com.maddyhome.idea.vim.undo.VimTimestampBasedUndoService | import com.maddyhome.idea.vim.undo.VimTimestampBasedUndoService | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -82,15 +85,7 @@ internal class UndoRedoHelper : VimTimestampBasedUndoService { | |||||||
|       // TODO refactor me after VIM-308 when restoring selection and caret movement will be ignored by undo |       // TODO refactor me after VIM-308 when restoring selection and caret movement will be ignored by undo | ||||||
|       editor.runWithChangeTracking { |       editor.runWithChangeTracking { | ||||||
|         undoManager.undo(fileEditor) |         undoManager.undo(fileEditor) | ||||||
|  |         restoreVisualMode(editor) | ||||||
|         // We execute undo one more time if the previous one just restored selection |  | ||||||
|         if (!hasChanges && hasSelection(editor) && undoManager.isUndoAvailable(fileEditor)) { |  | ||||||
|           undoManager.undo(fileEditor) |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       CommandProcessor.getInstance().runUndoTransparentAction { |  | ||||||
|         removeSelections(editor) |  | ||||||
|       } |       } | ||||||
|     } else { |     } else { | ||||||
|       runWithBooleanRegistryOption("ide.undo.transparent.caret.movement", true) { |       runWithBooleanRegistryOption("ide.undo.transparent.caret.movement", true) { | ||||||
| @@ -241,4 +236,21 @@ internal class UndoRedoHelper : VimTimestampBasedUndoService { | |||||||
|     val hasChanges: Boolean |     val hasChanges: Boolean | ||||||
|       get() = changeListener.hasChanged || initialPath != editor.getPath() |       get() = changeListener.hasChanged || initialPath != editor.getPath() | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   private fun restoreVisualMode(editor: VimEditor) { | ||||||
|  |     if (!editor.inVisualMode && editor.getSelectionModel().hasSelection()) { | ||||||
|  |       val detectedMode = VimPlugin.getVisualMotion().detectSelectionType(editor) | ||||||
|  |  | ||||||
|  |       // Visual block selection is restored into multiple carets, so multi-carets that form a block are always | ||||||
|  |       // identified as visual block mode, leading to false positives. | ||||||
|  |       // Since I use visual block mode much less often than multi-carets, this is a judgment call to never restore | ||||||
|  |       // visual block mode. | ||||||
|  |       val wantedMode = if (detectedMode == SelectionType.BLOCK_WISE) | ||||||
|  |         SelectionType.CHARACTER_WISE | ||||||
|  |       else | ||||||
|  |         detectedMode | ||||||
|  |  | ||||||
|  |       VimPlugin.getVisualMotion().enterVisualMode(editor, wantedMode) | ||||||
|  |     } | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -18,7 +18,6 @@ import com.intellij.openapi.editor.VisualPosition | |||||||
| import com.intellij.openapi.editor.markup.RangeHighlighter | import com.intellij.openapi.editor.markup.RangeHighlighter | ||||||
| import com.intellij.openapi.util.Key | import com.intellij.openapi.util.Key | ||||||
| import com.intellij.openapi.util.UserDataHolder | import com.intellij.openapi.util.UserDataHolder | ||||||
| import com.maddyhome.idea.vim.api.CaretRegisterStorageBase |  | ||||||
| import com.maddyhome.idea.vim.api.LocalMarkStorage | import com.maddyhome.idea.vim.api.LocalMarkStorage | ||||||
| import com.maddyhome.idea.vim.api.SelectionInfo | import com.maddyhome.idea.vim.api.SelectionInfo | ||||||
| import com.maddyhome.idea.vim.common.InsertSequence | import com.maddyhome.idea.vim.common.InsertSequence | ||||||
| @@ -98,7 +97,6 @@ internal var Caret.vimInsertStart: RangeMarker by userDataOr { | |||||||
| } | } | ||||||
|  |  | ||||||
| // TODO: Data could be lost during visual block motion | // TODO: Data could be lost during visual block motion | ||||||
| internal var Caret.registerStorage: CaretRegisterStorageBase? by userDataCaretToEditor() |  | ||||||
| internal var Caret.markStorage: LocalMarkStorage? by userDataCaretToEditor() | internal var Caret.markStorage: LocalMarkStorage? by userDataCaretToEditor() | ||||||
| internal var Caret.lastSelectionInfo: SelectionInfo? by userDataCaretToEditor() | internal var Caret.lastSelectionInfo: SelectionInfo? by userDataCaretToEditor() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,32 +0,0 @@ | |||||||
| /* |  | ||||||
|  * Copyright 2003-2023 The IdeaVim authors |  | ||||||
|  * |  | ||||||
|  * Use of this source code is governed by an MIT-style |  | ||||||
|  * license that can be found in the LICENSE.txt file or at |  | ||||||
|  * https://opensource.org/licenses/MIT. |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| package com.maddyhome.idea.vim.helper |  | ||||||
|  |  | ||||||
| import com.intellij.ide.plugins.StandalonePluginUpdateChecker |  | ||||||
| import com.intellij.openapi.components.Service |  | ||||||
| import com.intellij.openapi.components.service |  | ||||||
| import com.maddyhome.idea.vim.VimPlugin |  | ||||||
| import com.maddyhome.idea.vim.group.NotificationService |  | ||||||
| import com.maddyhome.idea.vim.icons.VimIcons |  | ||||||
|  |  | ||||||
| @Service(Service.Level.APP) |  | ||||||
| internal class VimStandalonePluginUpdateChecker : StandalonePluginUpdateChecker( |  | ||||||
|   VimPlugin.getPluginId(), |  | ||||||
|   updateTimestampProperty = PROPERTY_NAME, |  | ||||||
|   NotificationService.IDEAVIM_STICKY_GROUP, |  | ||||||
|   VimIcons.IDEAVIM, |  | ||||||
| ) { |  | ||||||
|  |  | ||||||
|   override fun skipUpdateCheck(): Boolean = VimPlugin.isNotEnabled() || "dev" in VimPlugin.getVersion() |  | ||||||
|  |  | ||||||
|   companion object { |  | ||||||
|     private const val PROPERTY_NAME = "ideavim.statistics.timestamp" |  | ||||||
|     fun getInstance(): VimStandalonePluginUpdateChecker = service() |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -61,11 +61,13 @@ class IJEditorFocusListener : EditorListener { | |||||||
|  |  | ||||||
|     val switchToInsertMode = Runnable { |     val switchToInsertMode = Runnable { | ||||||
|       val context: ExecutionContext = injector.executionContextManager.getEditorExecutionContext(editor) |       val context: ExecutionContext = injector.executionContextManager.getEditorExecutionContext(editor) | ||||||
|       VimPlugin.getChange().insertBeforeCursor(editor, context) |       VimPlugin.getChange().insertBeforeCaret(editor, context) | ||||||
|       KeyHandler.getInstance().lastUsedEditorInfo = LastUsedEditorInfo(currentEditorHashCode, true) |       KeyHandler.getInstance().lastUsedEditorInfo = LastUsedEditorInfo(currentEditorHashCode, true) | ||||||
|     } |     } | ||||||
|     if (isCurrentEditorTerminal && !ijEditor.inInsertMode) { |     if (isCurrentEditorTerminal) { | ||||||
|       switchToInsertMode.run() |       if (!ijEditor.inInsertMode) { | ||||||
|  |         switchToInsertMode.run() | ||||||
|  |       } | ||||||
|     } else if (ijEditor.isInsertMode && (oldEditorInfo.isInsertModeForced || !ijEditor.document.isWritable)) { |     } else if (ijEditor.isInsertMode && (oldEditorInfo.isInsertModeForced || !ijEditor.document.isWritable)) { | ||||||
|       val context: ExecutionContext = injector.executionContextManager.getEditorExecutionContext(editor) |       val context: ExecutionContext = injector.executionContextManager.getEditorExecutionContext(editor) | ||||||
|       val mode = injector.vimState.mode |       val mode = injector.vimState.mode | ||||||
|   | |||||||
| @@ -16,7 +16,9 @@ import com.intellij.codeInsight.lookup.impl.actions.ChooseItemAction | |||||||
| import com.intellij.codeInsight.template.Template | import com.intellij.codeInsight.template.Template | ||||||
| import com.intellij.codeInsight.template.TemplateEditingAdapter | import com.intellij.codeInsight.template.TemplateEditingAdapter | ||||||
| import com.intellij.codeInsight.template.TemplateManagerListener | import com.intellij.codeInsight.template.TemplateManagerListener | ||||||
|  | import com.intellij.codeInsight.template.impl.TemplateManagerImpl | ||||||
| import com.intellij.codeInsight.template.impl.TemplateState | import com.intellij.codeInsight.template.impl.TemplateState | ||||||
|  | import com.intellij.codeInsight.template.impl.actions.NextVariableAction | ||||||
| import com.intellij.find.FindModelListener | import com.intellij.find.FindModelListener | ||||||
| import com.intellij.ide.actions.ApplyIntentionAction | import com.intellij.ide.actions.ApplyIntentionAction | ||||||
| import com.intellij.openapi.actionSystem.ActionManager | import com.intellij.openapi.actionSystem.ActionManager | ||||||
| @@ -30,6 +32,7 @@ import com.intellij.openapi.actionSystem.ex.AnActionListener | |||||||
| import com.intellij.openapi.actionSystem.impl.ProxyShortcutSet | import com.intellij.openapi.actionSystem.impl.ProxyShortcutSet | ||||||
| import com.intellij.openapi.editor.Editor | import com.intellij.openapi.editor.Editor | ||||||
| import com.intellij.openapi.editor.actions.EnterAction | import com.intellij.openapi.editor.actions.EnterAction | ||||||
|  | import com.intellij.openapi.editor.impl.ScrollingModelImpl | ||||||
| import com.intellij.openapi.keymap.KeymapManager | import com.intellij.openapi.keymap.KeymapManager | ||||||
| import com.intellij.openapi.project.DumbAwareToggleAction | import com.intellij.openapi.project.DumbAwareToggleAction | ||||||
| import com.intellij.openapi.util.TextRange | import com.intellij.openapi.util.TextRange | ||||||
| @@ -61,6 +64,7 @@ internal object IdeaSpecifics { | |||||||
|     private val surrounderAction = |     private val surrounderAction = | ||||||
|       "com.intellij.codeInsight.generation.surroundWith.SurroundWithHandler\$InvokeSurrounderAction" |       "com.intellij.codeInsight.generation.surroundWith.SurroundWithHandler\$InvokeSurrounderAction" | ||||||
|     private var editor: Editor? = null |     private var editor: Editor? = null | ||||||
|  |     private var caretOffset = -1 | ||||||
|     private var completionPrevDocumentLength: Int? = null |     private var completionPrevDocumentLength: Int? = null | ||||||
|     private var completionPrevDocumentOffset: Int? = null |     private var completionPrevDocumentOffset: Int? = null | ||||||
|  |  | ||||||
| @@ -70,6 +74,7 @@ internal object IdeaSpecifics { | |||||||
|       val hostEditor = event.dataContext.getData(CommonDataKeys.HOST_EDITOR) |       val hostEditor = event.dataContext.getData(CommonDataKeys.HOST_EDITOR) | ||||||
|       if (hostEditor != null) { |       if (hostEditor != null) { | ||||||
|         editor = hostEditor |         editor = hostEditor | ||||||
|  |         caretOffset = hostEditor.caretModel.offset | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       val isVimAction = (action as? AnActionWrapper)?.delegate is VimShortcutKeyAction |       val isVimAction = (action as? AnActionWrapper)?.delegate is VimShortcutKeyAction | ||||||
| @@ -127,17 +132,18 @@ internal object IdeaSpecifics { | |||||||
|       if (VimPlugin.isNotEnabled()) return |       if (VimPlugin.isNotEnabled()) return | ||||||
|  |  | ||||||
|       val editor = editor |       val editor = editor | ||||||
|       if (editor != null && action is ChooseItemAction && injector.registerGroup.isRecording) { |       if (editor != null) { | ||||||
|         val prevDocumentLength = completionPrevDocumentLength |         if (action is ChooseItemAction && injector.registerGroup.isRecording) { | ||||||
|         val prevDocumentOffset = completionPrevDocumentOffset |           val prevDocumentLength = completionPrevDocumentLength | ||||||
|  |           val prevDocumentOffset = completionPrevDocumentOffset | ||||||
|  |  | ||||||
|         if (prevDocumentLength != null && prevDocumentOffset != null) { |           if (prevDocumentLength != null && prevDocumentOffset != null) { | ||||||
|           val register = VimPlugin.getRegister() |             val register = VimPlugin.getRegister() | ||||||
|           val addedTextLength = editor.document.textLength - prevDocumentLength |             val addedTextLength = editor.document.textLength - prevDocumentLength | ||||||
|           val caretShift = addedTextLength - (editor.caretModel.primaryCaret.offset - prevDocumentOffset) |             val caretShift = addedTextLength - (editor.caretModel.primaryCaret.offset - prevDocumentOffset) | ||||||
|           val leftArrow = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0) |             val leftArrow = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0) | ||||||
|  |  | ||||||
|           register.recordText( |             register.recordText( | ||||||
|             editor.document.getText( |             editor.document.getText( | ||||||
|               TextRange( |               TextRange( | ||||||
|                 prevDocumentOffset, |                 prevDocumentOffset, | ||||||
| @@ -145,31 +151,49 @@ internal object IdeaSpecifics { | |||||||
|               ) |               ) | ||||||
|             ) |             ) | ||||||
|           ) |           ) | ||||||
|           repeat(caretShift.coerceAtLeast(0)) { |             repeat(caretShift.coerceAtLeast(0)) { | ||||||
|             register.recordKeyStroke(leftArrow) |               register.recordKeyStroke(leftArrow) | ||||||
|  |             } | ||||||
|  |           } | ||||||
|  |  | ||||||
|  |           this.completionPrevDocumentLength = null | ||||||
|  |           this.completionPrevDocumentOffset = null | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         //region Enter insert mode after surround with if | ||||||
|  |         if (surrounderAction == action.javaClass.name && surrounderItems.any { | ||||||
|  |             action.templatePresentation.text.endsWith( | ||||||
|  |               it, | ||||||
|  |             ) | ||||||
|  |           } | ||||||
|  |         ) { | ||||||
|  |           editor?.let { | ||||||
|  |             it.vim.mode = Mode.NORMAL() | ||||||
|  |             VimPlugin.getChange().insertBeforeCaret(it.vim, event.dataContext.vim) | ||||||
|  |             KeyHandler.getInstance().reset(it.vim) | ||||||
|           } |           } | ||||||
|         } |         } | ||||||
|  |         else if (action is NextVariableAction && TemplateManagerImpl.getTemplateState(editor) == null) { | ||||||
|         this.completionPrevDocumentLength = null |           editor.vim.exitInsertMode(event.dataContext.vim) | ||||||
|         this.completionPrevDocumentOffset = null |           KeyHandler.getInstance().reset(editor.vim) | ||||||
|       } |  | ||||||
|  |  | ||||||
|       //region Enter insert mode after surround with if |  | ||||||
|       if (surrounderAction == action.javaClass.name && surrounderItems.any { |  | ||||||
|           action.templatePresentation.text.endsWith( |  | ||||||
|             it, |  | ||||||
|           ) |  | ||||||
|         } |         } | ||||||
|       ) { |         //endregion | ||||||
|         editor?.let { |  | ||||||
|           it.vim.mode = Mode.NORMAL() |         if (caretOffset != -1 && caretOffset != editor.caretModel.offset) { | ||||||
|           VimPlugin.getChange().insertBeforeCursor(it.vim, event.dataContext.vim) |           val scrollModel = editor.scrollingModel as ScrollingModelImpl | ||||||
|           KeyHandler.getInstance().reset(it.vim) |           if (scrollModel.isScrollingNow) { | ||||||
|  |             val v = scrollModel.verticalScrollOffset | ||||||
|  |             val h = scrollModel.horizontalScrollOffset | ||||||
|  |             scrollModel.finishAnimation() | ||||||
|  |             scrollModel.scroll(h, v) | ||||||
|  |             scrollModel.finishAnimation() | ||||||
|  |           } | ||||||
|  |           injector.scroll.scrollCaretIntoView(editor.vim) | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|       //endregion |  | ||||||
|  |  | ||||||
|       this.editor = null |       this.editor = null | ||||||
|  |       this.caretOffset = -1 | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -199,7 +223,7 @@ internal object IdeaSpecifics { | |||||||
|           // Enable insert mode if there is no selection in template |           // Enable insert mode if there is no selection in template | ||||||
|           // Template with selection is handled by [com.maddyhome.idea.vim.group.visual.VisualMotionGroup.controlNonVimSelectionChange] |           // Template with selection is handled by [com.maddyhome.idea.vim.group.visual.VisualMotionGroup.controlNonVimSelectionChange] | ||||||
|           if (editor.vim.inNormalMode) { |           if (editor.vim.inNormalMode) { | ||||||
|             VimPlugin.getChange().insertBeforeCursor( |             VimPlugin.getChange().insertBeforeCaret( | ||||||
|               editor.vim, |               editor.vim, | ||||||
|               injector.executionContextManager.getEditorExecutionContext(editor.vim), |               injector.executionContextManager.getEditorExecutionContext(editor.vim), | ||||||
|             ) |             ) | ||||||
|   | |||||||
| @@ -81,7 +81,6 @@ import com.maddyhome.idea.vim.handler.keyCheckRequests | |||||||
| import com.maddyhome.idea.vim.helper.CaretVisualAttributesListener | import com.maddyhome.idea.vim.helper.CaretVisualAttributesListener | ||||||
| import com.maddyhome.idea.vim.helper.GuicursorChangeListener | import com.maddyhome.idea.vim.helper.GuicursorChangeListener | ||||||
| import com.maddyhome.idea.vim.helper.StrictMode | import com.maddyhome.idea.vim.helper.StrictMode | ||||||
| import com.maddyhome.idea.vim.helper.VimStandalonePluginUpdateChecker |  | ||||||
| import com.maddyhome.idea.vim.helper.exitSelectMode | import com.maddyhome.idea.vim.helper.exitSelectMode | ||||||
| import com.maddyhome.idea.vim.helper.exitVisualMode | import com.maddyhome.idea.vim.helper.exitVisualMode | ||||||
| import com.maddyhome.idea.vim.helper.forceBarCursor | import com.maddyhome.idea.vim.helper.forceBarCursor | ||||||
| @@ -98,6 +97,7 @@ import com.maddyhome.idea.vim.newapi.IjVimSearchGroup | |||||||
| import com.maddyhome.idea.vim.newapi.InsertTimeRecorder | import com.maddyhome.idea.vim.newapi.InsertTimeRecorder | ||||||
| import com.maddyhome.idea.vim.newapi.ij | import com.maddyhome.idea.vim.newapi.ij | ||||||
| import com.maddyhome.idea.vim.newapi.vim | import com.maddyhome.idea.vim.newapi.vim | ||||||
|  | import com.maddyhome.idea.vim.state.mode.Mode | ||||||
| import com.maddyhome.idea.vim.state.mode.inSelectMode | import com.maddyhome.idea.vim.state.mode.inSelectMode | ||||||
| import com.maddyhome.idea.vim.state.mode.selectionType | import com.maddyhome.idea.vim.state.mode.selectionType | ||||||
| import com.maddyhome.idea.vim.ui.ShowCmdOptionChangeListener | import com.maddyhome.idea.vim.ui.ShowCmdOptionChangeListener | ||||||
| @@ -412,9 +412,20 @@ internal object VimListenerManager { | |||||||
|       // We can't rely on being passed a non-null editor, so check for Code With Me scenarios explicitly |       // We can't rely on being passed a non-null editor, so check for Code With Me scenarios explicitly | ||||||
|       if (VimPlugin.isNotEnabled() || !ClientId.isCurrentlyUnderLocalId) return |       if (VimPlugin.isNotEnabled() || !ClientId.isCurrentlyUnderLocalId) return | ||||||
|        |        | ||||||
|  |       val newEditor = event.newEditor | ||||||
|  |       if (newEditor is TextEditor) { | ||||||
|  |         val editor = newEditor.editor | ||||||
|  |         if (editor.isInsertMode) { | ||||||
|  |           editor.vim.mode = Mode.NORMAL() | ||||||
|  |           KeyHandler.getInstance().reset(editor.vim) | ||||||
|  |         } | ||||||
|  |         // Breaks relativenumber for some reason | ||||||
|  | //        injector.scroll.scrollCaretIntoView(editor.vim) | ||||||
|  |       } | ||||||
|  |        | ||||||
|       MotionGroup.fileEditorManagerSelectionChangedCallback(event) |       MotionGroup.fileEditorManagerSelectionChangedCallback(event) | ||||||
|       FileGroup.fileEditorManagerSelectionChangedCallback(event) |       FileGroup.fileEditorManagerSelectionChangedCallback(event) | ||||||
|       VimPlugin.getSearch().fileEditorManagerSelectionChangedCallback(event) | //      VimPlugin.getSearch().fileEditorManagerSelectionChangedCallback(event) | ||||||
|       IjVimRedrawService.fileEditorManagerSelectionChangedCallback(event) |       IjVimRedrawService.fileEditorManagerSelectionChangedCallback(event) | ||||||
|       VimLastSelectedEditorTracker.setLastSelectedEditor(event.newEditor) |       VimLastSelectedEditorTracker.setLastSelectedEditor(event.newEditor) | ||||||
|     } |     } | ||||||
| @@ -487,8 +498,6 @@ internal object VimListenerManager { | |||||||
|           OpeningEditor(openingEditor, owningEditorWindow, isPreview, canBeReused) |           OpeningEditor(openingEditor, owningEditorWindow, isPreview, canBeReused) | ||||||
|         ) |         ) | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       VimStandalonePluginUpdateChecker.getInstance().pluginUsed() |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun editorReleased(event: EditorFactoryEvent) { |     override fun editorReleased(event: EditorFactoryEvent) { | ||||||
|   | |||||||
| @@ -39,7 +39,7 @@ import java.io.IOException | |||||||
|  |  | ||||||
| @Service | @Service | ||||||
| internal class IjClipboardManager : VimClipboardManager { | internal class IjClipboardManager : VimClipboardManager { | ||||||
|   override fun getPrimaryContent(editor: VimEditor, context: ExecutionContext): IjVimCopiedText? { |   override fun getPrimaryContent(): IjVimCopiedText? { | ||||||
|     val clipboard = Toolkit.getDefaultToolkit()?.systemSelection ?: return null |     val clipboard = Toolkit.getDefaultToolkit()?.systemSelection ?: return null | ||||||
|     val contents = clipboard.getContents(null) ?: return null |     val contents = clipboard.getContents(null) ?: return null | ||||||
|     val (text, transferableData) = getTextAndTransferableData(contents) ?: return null |     val (text, transferableData) = getTextAndTransferableData(contents) ?: return null | ||||||
| @@ -242,6 +242,6 @@ internal class IjClipboardManager : VimClipboardManager { | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| data class IjVimCopiedText(override val text: String, val transferableData: List<Any>) : VimCopiedText { | data class IjVimCopiedText(override val text: String, override val transferableData: List<Any>) : VimCopiedText { | ||||||
|   override fun updateText(newText: String): VimCopiedText = IjVimCopiedText(newText, transferableData) |   override fun updateText(newText: String): VimCopiedText = IjVimCopiedText(newText, transferableData) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -12,8 +12,6 @@ import com.intellij.openapi.editor.Caret | |||||||
| import com.intellij.openapi.editor.LogicalPosition | import com.intellij.openapi.editor.LogicalPosition | ||||||
| import com.intellij.openapi.editor.VisualPosition | import com.intellij.openapi.editor.VisualPosition | ||||||
| import com.maddyhome.idea.vim.api.BufferPosition | import com.maddyhome.idea.vim.api.BufferPosition | ||||||
| import com.maddyhome.idea.vim.api.CaretRegisterStorage |  | ||||||
| import com.maddyhome.idea.vim.api.CaretRegisterStorageBase |  | ||||||
| import com.maddyhome.idea.vim.api.ImmutableVimCaret | import com.maddyhome.idea.vim.api.ImmutableVimCaret | ||||||
| import com.maddyhome.idea.vim.api.LocalMarkStorage | import com.maddyhome.idea.vim.api.LocalMarkStorage | ||||||
| import com.maddyhome.idea.vim.api.SelectionInfo | import com.maddyhome.idea.vim.api.SelectionInfo | ||||||
| @@ -21,6 +19,7 @@ import com.maddyhome.idea.vim.api.VimCaret | |||||||
| import com.maddyhome.idea.vim.api.VimCaretBase | import com.maddyhome.idea.vim.api.VimCaretBase | ||||||
| import com.maddyhome.idea.vim.api.VimEditor | import com.maddyhome.idea.vim.api.VimEditor | ||||||
| import com.maddyhome.idea.vim.api.VimVisualPosition | import com.maddyhome.idea.vim.api.VimVisualPosition | ||||||
|  | import com.maddyhome.idea.vim.api.injector | ||||||
| import com.maddyhome.idea.vim.common.InsertSequence | import com.maddyhome.idea.vim.common.InsertSequence | ||||||
| import com.maddyhome.idea.vim.common.LiveRange | import com.maddyhome.idea.vim.common.LiveRange | ||||||
| import com.maddyhome.idea.vim.group.visual.VisualChange | import com.maddyhome.idea.vim.group.visual.VisualChange | ||||||
| @@ -29,7 +28,6 @@ import com.maddyhome.idea.vim.helper.insertHistory | |||||||
| import com.maddyhome.idea.vim.helper.lastSelectionInfo | import com.maddyhome.idea.vim.helper.lastSelectionInfo | ||||||
| import com.maddyhome.idea.vim.helper.markStorage | import com.maddyhome.idea.vim.helper.markStorage | ||||||
| import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset | import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset | ||||||
| import com.maddyhome.idea.vim.helper.registerStorage |  | ||||||
| import com.maddyhome.idea.vim.helper.resetVimLastColumn | import com.maddyhome.idea.vim.helper.resetVimLastColumn | ||||||
| import com.maddyhome.idea.vim.helper.vimInsertStart | import com.maddyhome.idea.vim.helper.vimInsertStart | ||||||
| import com.maddyhome.idea.vim.helper.vimLastColumn | import com.maddyhome.idea.vim.helper.vimLastColumn | ||||||
| @@ -37,22 +35,14 @@ import com.maddyhome.idea.vim.helper.vimLastVisualOperatorRange | |||||||
| import com.maddyhome.idea.vim.helper.vimLine | import com.maddyhome.idea.vim.helper.vimLine | ||||||
| import com.maddyhome.idea.vim.helper.vimSelectionStart | import com.maddyhome.idea.vim.helper.vimSelectionStart | ||||||
| import com.maddyhome.idea.vim.helper.vimSelectionStartClear | import com.maddyhome.idea.vim.helper.vimSelectionStartClear | ||||||
|  | import com.maddyhome.idea.vim.register.VimRegisterGroup | ||||||
| import com.maddyhome.idea.vim.state.mode.SelectionType | import com.maddyhome.idea.vim.state.mode.SelectionType | ||||||
|  |  | ||||||
| internal class IjVimCaret(val caret: Caret) : VimCaretBase() { | internal class IjVimCaret(val caret: Caret) : VimCaretBase() { | ||||||
|  |  | ||||||
|   override val registerStorage: CaretRegisterStorage |   override val registerStorage: VimRegisterGroup | ||||||
|     get() { |     get() = injector.registerGroup | ||||||
|       var storage = this.caret.registerStorage |   | ||||||
|       if (storage == null) { |  | ||||||
|         initInjector() // To initialize injector used in CaretRegisterStorageBase |  | ||||||
|         storage = CaretRegisterStorageBase(this) |  | ||||||
|         this.caret.registerStorage = storage |  | ||||||
|       } else if (storage.caret != this) { |  | ||||||
|         storage.caret = this |  | ||||||
|       } |  | ||||||
|       return storage |  | ||||||
|     } |  | ||||||
|   override val markStorage: LocalMarkStorage |   override val markStorage: LocalMarkStorage | ||||||
|     get() { |     get() { | ||||||
|       var storage = this.caret.markStorage |       var storage = this.caret.markStorage | ||||||
|   | |||||||
| @@ -20,6 +20,7 @@ import com.intellij.openapi.editor.ex.ScrollingModelEx | |||||||
| import com.intellij.openapi.editor.ex.util.EditorUtil | import com.intellij.openapi.editor.ex.util.EditorUtil | ||||||
| import com.intellij.openapi.editor.impl.CaretModelImpl | import com.intellij.openapi.editor.impl.CaretModelImpl | ||||||
| import com.intellij.openapi.editor.impl.EditorImpl | import com.intellij.openapi.editor.impl.EditorImpl | ||||||
|  | import com.intellij.openapi.util.text.StringUtil | ||||||
| import com.intellij.openapi.vfs.VirtualFileManager | import com.intellij.openapi.vfs.VirtualFileManager | ||||||
| import com.maddyhome.idea.vim.api.BufferPosition | import com.maddyhome.idea.vim.api.BufferPosition | ||||||
| import com.maddyhome.idea.vim.api.ExecutionContext | import com.maddyhome.idea.vim.api.ExecutionContext | ||||||
| @@ -35,8 +36,8 @@ import com.maddyhome.idea.vim.api.VimFoldRegion | |||||||
| import com.maddyhome.idea.vim.api.VimIndentConfig | import com.maddyhome.idea.vim.api.VimIndentConfig | ||||||
| import com.maddyhome.idea.vim.api.VimScrollingModel | import com.maddyhome.idea.vim.api.VimScrollingModel | ||||||
| import com.maddyhome.idea.vim.api.VimSelectionModel | import com.maddyhome.idea.vim.api.VimSelectionModel | ||||||
| import com.maddyhome.idea.vim.api.VimVisualPosition |  | ||||||
| import com.maddyhome.idea.vim.api.VimVirtualFile | import com.maddyhome.idea.vim.api.VimVirtualFile | ||||||
|  | import com.maddyhome.idea.vim.api.VimVisualPosition | ||||||
| import com.maddyhome.idea.vim.api.injector | import com.maddyhome.idea.vim.api.injector | ||||||
| import com.maddyhome.idea.vim.common.IndentConfig | import com.maddyhome.idea.vim.common.IndentConfig | ||||||
| import com.maddyhome.idea.vim.common.LiveRange | import com.maddyhome.idea.vim.common.LiveRange | ||||||
| @@ -150,7 +151,7 @@ internal class IjVimEditor(editor: Editor) : MutableLinearEditor, VimEditorBase( | |||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|     editor.document.insertString(atPosition, text) |     editor.document.insertString(atPosition, StringUtil.convertLineSeparators(text, "\n")) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   override fun replaceString(start: Int, end: Int, newString: String) { |   override fun replaceString(start: Int, end: Int, newString: String) { | ||||||
| @@ -179,21 +180,38 @@ internal class IjVimEditor(editor: Editor) : MutableLinearEditor, VimEditorBase( | |||||||
|     return editor.caretModel.allCarets.map { IjVimCaret(it) } |     return editor.caretModel.allCarets.map { IjVimCaret(it) } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   override var isFirstCaret = true | ||||||
|  |   override var isReversingCarets = false | ||||||
|  |    | ||||||
|   @Suppress("ideavimRunForEachCaret") |   @Suppress("ideavimRunForEachCaret") | ||||||
|   override fun forEachCaret(action: (VimCaret) -> Unit) { |   override fun forEachCaret(action: (VimCaret) -> Unit) { | ||||||
|     if (editor.vim.inBlockSelection) { |     if (editor.vim.inBlockSelection) { | ||||||
|       action(IjVimCaret(editor.caretModel.primaryCaret)) |       action(IjVimCaret(editor.caretModel.primaryCaret)) | ||||||
|     } else { |     } else { | ||||||
|       editor.caretModel.runForEachCaret({ |       try { | ||||||
|         if (it.isValid) { |         editor.caretModel.runForEachCaret({ | ||||||
|           action(IjVimCaret(it)) |           if (it.isValid) { | ||||||
|         } |             action(IjVimCaret(it)) | ||||||
|       }, false) |             isFirstCaret = false | ||||||
|  |           } | ||||||
|  |         }, false) | ||||||
|  |       } finally { | ||||||
|  |         isFirstCaret = true | ||||||
|  |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   override fun forEachNativeCaret(action: (VimCaret) -> Unit, reverse: Boolean) { |   override fun forEachNativeCaret(action: (VimCaret) -> Unit, reverse: Boolean) { | ||||||
|     editor.caretModel.runForEachCaret({ action(IjVimCaret(it)) }, reverse) |     isReversingCarets = reverse | ||||||
|  |     try { | ||||||
|  |       editor.caretModel.runForEachCaret({ | ||||||
|  |         action(IjVimCaret(it)) | ||||||
|  |         isFirstCaret = false | ||||||
|  |       }, reverse) | ||||||
|  |     } finally { | ||||||
|  |       isFirstCaret = true | ||||||
|  |       isReversingCarets = false | ||||||
|  |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   override fun isInForEachCaretScope(): Boolean { |   override fun isInForEachCaretScope(): Boolean { | ||||||
| @@ -497,6 +515,10 @@ internal class IjVimEditor(editor: Editor) : MutableLinearEditor, VimEditorBase( | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   override fun getSoftWrapStartAtOffset(offset: Int): Int? { | ||||||
|  |     return editor.softWrapModel.getSoftWrap(offset)?.start | ||||||
|  |   } | ||||||
|  |  | ||||||
|   override fun <T : ImmutableVimCaret> findLastVersionOfCaret(caret: T): T { |   override fun <T : ImmutableVimCaret> findLastVersionOfCaret(caret: T): T { | ||||||
|     return caret |     return caret | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -353,7 +353,7 @@ public class ExEntryPanel extends JPanel implements VimCommandLine { | |||||||
|         int count1 = Math.max(1, KeyHandler.getInstance().getKeyHandlerState().getEditorCommandBuilder() |         int count1 = Math.max(1, KeyHandler.getInstance().getKeyHandlerState().getEditorCommandBuilder() | ||||||
|           .calculateCount0Snapshot()); |           .calculateCount0Snapshot()); | ||||||
|  |  | ||||||
|         if (labelText.equals("/") || labelText.equals("?") || searchCommand) { |         if ((labelText.equals("/") || labelText.equals("?") || searchCommand) && !injector.getMacro().isExecutingMacro()) { | ||||||
|           final boolean forwards = !labelText.equals("?");  // :s, :g, :v are treated as forwards |           final boolean forwards = !labelText.equals("?");  // :s, :g, :v are treated as forwards | ||||||
|           int patternEnd = injector.getSearchGroup().findEndOfPattern(searchText, separator, 0); |           int patternEnd = injector.getSearchGroup().findEndOfPattern(searchText, separator, 0); | ||||||
|           final String pattern = searchText.substring(0, patternEnd); |           final String pattern = searchText.substring(0, patternEnd); | ||||||
|   | |||||||
| @@ -1,12 +1,4 @@ | |||||||
| <!-- | <idea-plugin xmlns:xi="http://www.w3.org/2001/XInclude"> | ||||||
|   ~ Copyright 2003-2023 The IdeaVim authors |  | ||||||
|   ~ |  | ||||||
|   ~ Use of this source code is governed by an MIT-style |  | ||||||
|   ~ license that can be found in the LICENSE.txt file or at |  | ||||||
|   ~ https://opensource.org/licenses/MIT. |  | ||||||
|   --> |  | ||||||
|  |  | ||||||
| <idea-plugin url="https://plugins.jetbrains.com/plugin/164" xmlns:xi="http://www.w3.org/2001/XInclude"> |  | ||||||
|   <name>IdeaVim</name> |   <name>IdeaVim</name> | ||||||
|   <id>IdeaVIM</id> |   <id>IdeaVIM</id> | ||||||
|   <description><![CDATA[ |   <description><![CDATA[ | ||||||
| @@ -21,7 +13,7 @@ | |||||||
|         <li><a href="https://youtrack.jetbrains.com/issues/VIM">Issue tracker</a>: feature requests and bug reports</li> |         <li><a href="https://youtrack.jetbrains.com/issues/VIM">Issue tracker</a>: feature requests and bug reports</li> | ||||||
|       </ul> |       </ul> | ||||||
|     ]]></description> |     ]]></description> | ||||||
|   <version>SNAPSHOT</version> |   <version>chylex</version> | ||||||
|   <vendor>JetBrains</vendor> |   <vendor>JetBrains</vendor> | ||||||
|  |  | ||||||
|   <!-- Mark the plugin as compatible with RubyMine and other products based on the IntelliJ platform (including CWM) --> |   <!-- Mark the plugin as compatible with RubyMine and other products based on the IntelliJ platform (including CWM) --> | ||||||
| @@ -143,6 +135,8 @@ | |||||||
|  |  | ||||||
|     <editorNotificationProvider |     <editorNotificationProvider | ||||||
|         implementation="com.maddyhome.idea.vim.troubleshooting.AccidentalInstallDetectorEditorNotificationProvider"/> |         implementation="com.maddyhome.idea.vim.troubleshooting.AccidentalInstallDetectorEditorNotificationProvider"/> | ||||||
|  |  | ||||||
|  |     <dependencySupport coordinate="configuration" kind="vim" displayName="IdeaVim"/> | ||||||
|   </extensions> |   </extensions> | ||||||
|  |  | ||||||
|   <xi:include href="/META-INF/includes/ApplicationServices.xml" xpointer="xpointer(/idea-plugin/*)"/> |   <xi:include href="/META-INF/includes/ApplicationServices.xml" xpointer="xpointer(/idea-plugin/*)"/> | ||||||
| @@ -171,5 +165,6 @@ | |||||||
|     </group> |     </group> | ||||||
|  |  | ||||||
|     <action id="VimFindActionIdAction" class="com.maddyhome.idea.vim.listener.FindActionIdAction"/> |     <action id="VimFindActionIdAction" class="com.maddyhome.idea.vim.listener.FindActionIdAction"/> | ||||||
|  |     <action id="VimJumpToSource" class="com.intellij.diff.actions.impl.OpenInEditorAction" /> | ||||||
|   </actions> |   </actions> | ||||||
| </idea-plugin> | </idea-plugin> | ||||||
|   | |||||||
| @@ -78,5 +78,10 @@ | |||||||
|         "keys": "gJ", |         "keys": "gJ", | ||||||
|         "class": "com.maddyhome.idea.vim.action.change.delete.DeleteJoinVisualLinesAction", |         "class": "com.maddyhome.idea.vim.action.change.delete.DeleteJoinVisualLinesAction", | ||||||
|         "modes": "X" |         "modes": "X" | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |         "keys": "z@", | ||||||
|  |         "class": "com.maddyhome.idea.vim.action.macro.PlaybackRegisterInOpenFilesAction", | ||||||
|  |         "modes": "N" | ||||||
|     } |     } | ||||||
| ] | ] | ||||||
| @@ -1144,6 +1144,12 @@ $c  tw${c}o | |||||||
|       "O${c}NcE thIs ${c}TEXt wIlL n${c}Ot lOoK s${c}O rIdIcuLoUs\n", |       "O${c}NcE thIs ${c}TEXt wIlL n${c}Ot lOoK s${c}O rIdIcuLoUs\n", | ||||||
|     ) |     ) | ||||||
|     assertState("O${c}nce this text will n${c}ot look s${c}o ridiculous\n") |     assertState("O${c}nce this text will n${c}ot look s${c}o ridiculous\n") | ||||||
|  |  | ||||||
|  |     typeTextInFile( | ||||||
|  |       injector.parser.parseKeys("v2wgu"), | ||||||
|  |       "O${c}NcE thIs ${c}TEXt wIlL n${c}Ot lOoK s${c}O rIdIcuLoUs\n", | ||||||
|  |     ) | ||||||
|  |     assertState("O${c}nce this text will n${c}ot look s${c}o ridiculous\n") | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @Test |   @Test | ||||||
| @@ -1180,6 +1186,12 @@ $c  tw${c}o | |||||||
|       "O${c}NcE thIs ${c}TEXt wIlL N${c}Ot lOoK S${c}O rIdIcuLoUs\n", |       "O${c}NcE thIs ${c}TEXt wIlL N${c}Ot lOoK S${c}O rIdIcuLoUs\n", | ||||||
|     ) |     ) | ||||||
|     assertState("O${c}NCE THIS TEXT WILL N${c}OT LOOK S${c}O RIDICULOUS\n") |     assertState("O${c}NCE THIS TEXT WILL N${c}OT LOOK S${c}O RIDICULOUS\n") | ||||||
|  |  | ||||||
|  |     typeTextInFile( | ||||||
|  |       injector.parser.parseKeys("v2wgU"), | ||||||
|  |       "O${c}NcE thIs ${c}TEXt wIlL N${c}Ot lOoK S${c}O rIdIcuLoUs\n", | ||||||
|  |     ) | ||||||
|  |     assertState("O${c}NCE THIS TEXT WILL N${c}OT LOOK S${c}O RIDICULOUS\n") | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @Test |   @Test | ||||||
|   | |||||||
| @@ -320,4 +320,61 @@ class ChangeCaseToggleCharacterActionTest : VimTestCase() { | |||||||
|       enterCommand("set nooldundo") |       enterCommand("set nooldundo") | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   @Test | ||||||
|  |   fun `test toggle case line caret position`() { | ||||||
|  |     configureByText("  Hello ${c}World") | ||||||
|  |     typeText("g~~") | ||||||
|  |     assertState("  ${c}hELLO wORLD") | ||||||
|  |     typeText("u") | ||||||
|  |     assertState("  Hello ${c}World") | ||||||
|  |  | ||||||
|  |     typeText("^g~~") | ||||||
|  |     assertState("  ${c}hELLO wORLD") | ||||||
|  |     typeText("u") | ||||||
|  |     assertState("  ${c}Hello World") | ||||||
|  |  | ||||||
|  |     typeText("hg~~") | ||||||
|  |     assertState(" $c hELLO wORLD") | ||||||
|  |     typeText("u") | ||||||
|  |     assertState(" $c Hello World") | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   @Test | ||||||
|  |   fun `test uppercase line caret position`() { | ||||||
|  |     configureByText("  Hello ${c}World") | ||||||
|  |     typeText("gUU") | ||||||
|  |     assertState("  ${c}HELLO WORLD") | ||||||
|  |     typeText("u") | ||||||
|  |     assertState("  Hello ${c}World") | ||||||
|  |  | ||||||
|  |     typeText("^gUU") | ||||||
|  |     assertState("  ${c}HELLO WORLD") | ||||||
|  |     typeText("u") | ||||||
|  |     assertState("  ${c}Hello World") | ||||||
|  |  | ||||||
|  |     typeText("hgUU") | ||||||
|  |     assertState(" $c HELLO WORLD") | ||||||
|  |     typeText("u") | ||||||
|  |     assertState(" $c Hello World") | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   @Test | ||||||
|  |   fun `test lowercase line caret position`() { | ||||||
|  |     configureByText("  Hello ${c}World") | ||||||
|  |     typeText("guu") | ||||||
|  |     assertState("  ${c}hello world") | ||||||
|  |     typeText("u") | ||||||
|  |     assertState("  Hello ${c}World") | ||||||
|  |  | ||||||
|  |     typeText("^guu") | ||||||
|  |     assertState("  ${c}hello world") | ||||||
|  |     typeText("u") | ||||||
|  |     assertState("  ${c}Hello World") | ||||||
|  |  | ||||||
|  |     typeText("hguu") | ||||||
|  |     assertState(" $c hello world") | ||||||
|  |     typeText("u") | ||||||
|  |     assertState(" $c Hello World") | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ import org.jetbrains.plugins.ideavim.TestWithoutNeovim | |||||||
| import org.jetbrains.plugins.ideavim.VimTestCase | import org.jetbrains.plugins.ideavim.VimTestCase | ||||||
| import org.junit.jupiter.api.Test | import org.junit.jupiter.api.Test | ||||||
| 
 | 
 | ||||||
| class VisualBlockInsertActionTest : VimTestCase() { | class VisualInsertActionTest : VimTestCase() { | ||||||
|   // VIM-1379 |CTRL-V| |j| |v_b_I| |   // VIM-1379 |CTRL-V| |j| |v_b_I| | ||||||
|   @TestWithoutNeovim(SkipNeovimReason.VISUAL_BLOCK_MODE) |   @TestWithoutNeovim(SkipNeovimReason.VISUAL_BLOCK_MODE) | ||||||
|   @Test |   @Test | ||||||
| @@ -101,28 +101,70 @@ class VisualBlockInsertActionTest : VimTestCase() { | |||||||
|     ) |     ) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   @TestWithoutNeovim(SkipNeovimReason.VISUAL_BLOCK_MODE) |  | ||||||
|   @Test |   @Test | ||||||
|   fun `test insert in non block mode`() { |   fun `test insert in non-block visual within single line`() { | ||||||
|     doTest( |     val before = """ | ||||||
|       listOf("vwIHello<esc>"), |       |  A ${c}Discovery | ||||||
|       """ |  | ||||||
|                 ${c}A Discovery |  | ||||||
| 
 | 
 | ||||||
|                 ${c}I found it in a legendary land |       |  I ${c}found it in a legendary land | ||||||
|                 all rocks and ${c}lavender and tufted grass, |       |  all rocks and lavender and tufted grass, | ||||||
|                 where it was settled on some sodden sand |       |  where it was settled on some sodden sand | ||||||
|                 hard by the torrent of a mountain pass. |       |  hard by the torrent of a mountain pass. | ||||||
|       """.trimIndent(), |     """.trimMargin() | ||||||
|       """ |     val after = """ | ||||||
|                 Hell${c}oA Discovery |       |Hell${c}o  A Discovery | ||||||
| 
 | 
 | ||||||
|                 Hell${c}oI found it in a legendary land |       |Hell${c}o  I found it in a legendary land | ||||||
|                 Hell${c}oall rocks and lavender and tufted grass, |       |  all rocks and lavender and tufted grass, | ||||||
|                 where it was settled on some sodden sand |       |  where it was settled on some sodden sand | ||||||
|                 hard by the torrent of a mountain pass. |       |  hard by the torrent of a mountain pass. | ||||||
|       """.trimIndent(), |     """.trimMargin() | ||||||
|     ) |     doTest(listOf($$"v$IHello<esc>"), before, after) | ||||||
|  |     doTest(listOf("VIHello<esc>"), before, after) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   @Test | ||||||
|  |   fun `test insert in non-block visual spanning multiple lines down`() { | ||||||
|  |     val before = """ | ||||||
|  |       |  A ${c}Discovery | ||||||
|  | 
 | ||||||
|  |       |  I ${c}found 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. | ||||||
|  |     """.trimMargin() | ||||||
|  |     val after = """ | ||||||
|  |       |Hell${c}o  A Discovery | ||||||
|  | 
 | ||||||
|  |       |Hell${c}o  I found 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. | ||||||
|  |     """.trimMargin() | ||||||
|  |     doTest(listOf("vjIHello<esc>"), before, after) | ||||||
|  |     doTest(listOf("VjIHello<esc>"), before, after) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   @Test | ||||||
|  |   fun `test insert in non-block visual spanning multiple lines up`() { | ||||||
|  |     val before = """ | ||||||
|  |       |  A Discovery | ||||||
|  | 
 | ||||||
|  |       |  I found it in a legendary land | ||||||
|  |       |  all rocks and lavender and tufted grass${c}, | ||||||
|  |       |  where it was settled on some sodden sand | ||||||
|  |       |  hard ${c}by the torrent of a mountain pass. | ||||||
|  |     """.trimMargin() | ||||||
|  |     val after = """ | ||||||
|  |       |  A Discovery | ||||||
|  | 
 | ||||||
|  |       |  I found it in a legendary landHell${c}o | ||||||
|  |       |  all rocks and lavender and tufted grass, | ||||||
|  |       |  whereHell${c}o it was settled on some sodden sand | ||||||
|  |       |  hard by the torrent of a mountain pass. | ||||||
|  |     """.trimMargin() | ||||||
|  |     doTest(listOf("vkIHello<esc>"), before, after) | ||||||
|  |     doTest(listOf("VkIHello<esc>"), before, after) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   @TestWithoutNeovim(SkipNeovimReason.VISUAL_BLOCK_MODE) |   @TestWithoutNeovim(SkipNeovimReason.VISUAL_BLOCK_MODE) | ||||||
| @@ -241,12 +241,7 @@ class RegistersCommandTest : VimTestCase() { | |||||||
|  |  | ||||||
|     val vimEditor = fixture.editor.vim |     val vimEditor = fixture.editor.vim | ||||||
|     val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) |     val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) | ||||||
|     injector.registerGroup.saveRegister( |     injector.registerGroup.saveRegister(vimEditor, context, '+', Register('+', SelectionType.LINE_WISE, "Lorem ipsum dolor", mutableListOf())) | ||||||
|       vimEditor, |  | ||||||
|       context, |  | ||||||
|       '+', |  | ||||||
|       Register('+', injector.clipboardManager.dumbCopiedText("Lorem ipsum dolor"), SelectionType.LINE_WISE) |  | ||||||
|     ) |  | ||||||
|     val clipboardContent = injector.clipboardManager.dumbCopiedText("clipboard content") |     val clipboardContent = injector.clipboardManager.dumbCopiedText("clipboard content") | ||||||
|     injector.clipboardManager.setClipboardContent(vimEditor, context, clipboardContent) |     injector.clipboardManager.setClipboardContent(vimEditor, context, clipboardContent) | ||||||
|     typeText("V<Esc>") |     typeText("V<Esc>") | ||||||
| @@ -453,12 +448,7 @@ class RegistersCommandTest : VimTestCase() { | |||||||
|     val vimEditor = fixture.editor.vim |     val vimEditor = fixture.editor.vim | ||||||
|     val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) |     val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) | ||||||
|     val clipboardContent = injector.clipboardManager.dumbCopiedText("clipboard content") |     val clipboardContent = injector.clipboardManager.dumbCopiedText("clipboard content") | ||||||
|     injector.registerGroup.saveRegister( |     injector.registerGroup.saveRegister(vimEditor, context, '+', Register('+', SelectionType.LINE_WISE, "Lorem ipsum dolor", mutableListOf())) | ||||||
|       vimEditor, |  | ||||||
|       context, |  | ||||||
|       '+', |  | ||||||
|       Register('+', injector.clipboardManager.dumbCopiedText("Lorem ipsum dolor"), SelectionType.LINE_WISE) |  | ||||||
|     ) |  | ||||||
|     injector.clipboardManager.setClipboardContent(vimEditor, context, clipboardContent) |     injector.clipboardManager.setClipboardContent(vimEditor, context, clipboardContent) | ||||||
|     typeText("V<Esc>") |     typeText("V<Esc>") | ||||||
|  |  | ||||||
|   | |||||||
| @@ -32,7 +32,7 @@ dependencies { | |||||||
|   compileOnly("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") |   compileOnly("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") | ||||||
|   testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion") |   testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion") | ||||||
|   testImplementation(testFixtures(project(":"))) // The root project |   testImplementation(testFixtures(project(":"))) // The root project | ||||||
|   testImplementation("org.junit.vintage:junit-vintage-engine:5.13.0") |   testImplementation("org.junit.vintage:junit-vintage-engine:5.13.2") | ||||||
|  |  | ||||||
|   intellijPlatform { |   intellijPlatform { | ||||||
|     // Snapshots don't use installers |     // Snapshots don't use installers | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ import org.jetbrains.plugins.ideavim.TestWithoutNeovim | |||||||
| import org.jetbrains.plugins.ideavim.VimJavaTestCase | import org.jetbrains.plugins.ideavim.VimJavaTestCase | ||||||
| import org.junit.jupiter.api.Test | import org.junit.jupiter.api.Test | ||||||
| 
 | 
 | ||||||
| class VisualBlockInsertActionJavaTest : VimJavaTestCase() { | class VisualInsertActionJavaTest : VimJavaTestCase() { | ||||||
|   // VIM-1110 |CTRL-V| |v_b_i| |zc| |   // VIM-1110 |CTRL-V| |v_b_i| |zc| | ||||||
|   @TestWithoutNeovim(SkipNeovimReason.FOLDING) |   @TestWithoutNeovim(SkipNeovimReason.FOLDING) | ||||||
|   @Test |   @Test | ||||||
| @@ -25,7 +25,7 @@ dependencies { | |||||||
|   compileOnly("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") |   compileOnly("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") | ||||||
|   testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion") |   testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion") | ||||||
|   testImplementation(testFixtures(project(":"))) // The root project |   testImplementation(testFixtures(project(":"))) // The root project | ||||||
|   testImplementation("org.junit.vintage:junit-vintage-engine:5.13.0") |   testImplementation("org.junit.vintage:junit-vintage-engine:5.13.2") | ||||||
|  |  | ||||||
|   intellijPlatform { |   intellijPlatform { | ||||||
|     // Snapshots don't use installers |     // Snapshots don't use installers | ||||||
| @@ -47,17 +47,8 @@ tasks { | |||||||
|   // I didn't find a better way to exclude except disabling and defining a new task with a different name |   // I didn't find a better way to exclude except disabling and defining a new task with a different name | ||||||
|   // Note that useJUnitTestPlatform() is required to prevent red code |   // Note that useJUnitTestPlatform() is required to prevent red code | ||||||
|   test { |   test { | ||||||
|     enabled = false |  | ||||||
|     useJUnitPlatform() |     useJUnitPlatform() | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // The `test` task is automatically set up with IntelliJ goodness. A custom test task needs to be configured for it |  | ||||||
|   val testLongRunning by intellijPlatformTesting.testIde.registering { |  | ||||||
|     task { |  | ||||||
|       group = "verification" |  | ||||||
|       useJUnitPlatform() |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| } | } | ||||||
|  |  | ||||||
| java { | java { | ||||||
|   | |||||||
| @@ -25,7 +25,7 @@ dependencies { | |||||||
|   compileOnly("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") |   compileOnly("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") | ||||||
|   testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion") |   testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion") | ||||||
|   testImplementation(testFixtures(project(":"))) // The root project |   testImplementation(testFixtures(project(":"))) // The root project | ||||||
|   testImplementation("org.junit.vintage:junit-vintage-engine:5.13.0") |   testImplementation("org.junit.vintage:junit-vintage-engine:5.13.2") | ||||||
|  |  | ||||||
|   intellijPlatform { |   intellijPlatform { | ||||||
|     // Snapshots don't use installers |     // Snapshots don't use installers | ||||||
| @@ -48,15 +48,6 @@ tasks { | |||||||
|   // I didn't find a better way to exclude except disabling and defining a new task with a different name |   // I didn't find a better way to exclude except disabling and defining a new task with a different name | ||||||
|   test { |   test { | ||||||
|     useJUnitPlatform() |     useJUnitPlatform() | ||||||
|     enabled = false |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   // The `test` task is automatically set up with IntelliJ goodness. A custom test task needs to be configured for it |  | ||||||
|   val testPropertyBased by intellijPlatformTesting.testIde.registering { |  | ||||||
|     task { |  | ||||||
|       group = "verification" |  | ||||||
|       useJUnitPlatform() |  | ||||||
|     } |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ val javaVersion: String by project | |||||||
| val remoteRobotVersion: String by project | val remoteRobotVersion: String by project | ||||||
|  |  | ||||||
| dependencies { | dependencies { | ||||||
|   testFixturesImplementation("org.junit.jupiter:junit-jupiter:5.13.0") |   testFixturesImplementation("org.junit.jupiter:junit-jupiter:5.13.3") | ||||||
|   compileOnly("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") |   compileOnly("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") | ||||||
|   testFixturesImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion") |   testFixturesImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion") | ||||||
|   testFixturesImplementation(testFixtures(project(":"))) // The root project |   testFixturesImplementation(testFixtures(project(":"))) // The root project | ||||||
|   | |||||||
| @@ -11,6 +11,7 @@ import com.intellij.remoterobot.data.RemoteComponent | |||||||
| import com.intellij.remoterobot.fixtures.CommonContainerFixture | import com.intellij.remoterobot.fixtures.CommonContainerFixture | ||||||
| import com.intellij.remoterobot.fixtures.DefaultXpath | import com.intellij.remoterobot.fixtures.DefaultXpath | ||||||
| import com.intellij.remoterobot.fixtures.FixtureName | import com.intellij.remoterobot.fixtures.FixtureName | ||||||
|  | import com.intellij.remoterobot.fixtures.JButtonFixture | ||||||
| import com.intellij.remoterobot.search.locators.byXpath | import com.intellij.remoterobot.search.locators.byXpath | ||||||
| import java.time.Duration | import java.time.Duration | ||||||
|  |  | ||||||
| @@ -28,6 +29,6 @@ class ManageLicensesFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteCompo | |||||||
|     /// Note: The license code is obfuscated, so we use the class `W`. But a better solution is required. |     /// Note: The license code is obfuscated, so we use the class `W`. But a better solution is required. | ||||||
|     textFields(byXpath("//div[@class='W']")).first().text = System.getenv("RIDER_LICENSE") |     textFields(byXpath("//div[@class='W']")).first().text = System.getenv("RIDER_LICENSE") | ||||||
|     button("Activate").click() |     button("Activate").click() | ||||||
|     button("Close").click() |     button(JButtonFixture.byText("Close"), timeout = Duration.ofSeconds(20)).click() | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -10,8 +10,8 @@ plugins { | |||||||
|     java |     java | ||||||
|     kotlin("jvm") |     kotlin("jvm") | ||||||
| //    id("org.jlleitschuh.gradle.ktlint") | //    id("org.jlleitschuh.gradle.ktlint") | ||||||
|     id("com.google.devtools.ksp") version "2.0.21-1.0.25" |     id("com.google.devtools.ksp") version "2.2.0-2.0.2" | ||||||
|     kotlin("plugin.serialization") version "2.0.21" |     kotlin("plugin.serialization") version "2.2.0" | ||||||
|     `maven-publish` |     `maven-publish` | ||||||
|     antlr |     antlr | ||||||
| } | } | ||||||
| @@ -45,13 +45,13 @@ afterEvaluate { | |||||||
| } | } | ||||||
|  |  | ||||||
| dependencies { | dependencies { | ||||||
|     testImplementation("org.junit.jupiter:junit-jupiter-api:5.13.0") |     testImplementation("org.junit.jupiter:junit-jupiter-api:5.13.3") | ||||||
|     testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.13.0") |     testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.13.3") | ||||||
|  |  | ||||||
|     // Temp workaround suggested in https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-faq.html#junit5-test-framework-refers-to-junit4 |     // Temp workaround suggested in https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-faq.html#junit5-test-framework-refers-to-junit4 | ||||||
|     // Can be removed when IJPL-159134 is fixed |     // Can be removed when IJPL-159134 is fixed | ||||||
| //    testRuntimeOnly("junit:junit:4.13.2") | //    testRuntimeOnly("junit:junit:4.13.2") | ||||||
|     testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.13.0") |     testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.13.2") | ||||||
|  |  | ||||||
|     // https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-test |     // https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-test | ||||||
|     testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion") |     testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion") | ||||||
| @@ -68,7 +68,7 @@ dependencies { | |||||||
|  |  | ||||||
|     compileOnly(kotlin("reflect")) |     compileOnly(kotlin("reflect")) | ||||||
|  |  | ||||||
|     testImplementation("org.mockito.kotlin:mockito-kotlin:5.4.0") |     testImplementation("org.mockito.kotlin:mockito-kotlin:6.0.0") | ||||||
| } | } | ||||||
|  |  | ||||||
| tasks { | tasks { | ||||||
| @@ -88,13 +88,13 @@ tasks { | |||||||
|     named("compileTestKotlin") { |     named("compileTestKotlin") { | ||||||
|       dependsOn("generateTestGrammarSource") |       dependsOn("generateTestGrammarSource") | ||||||
|     } |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|     compileKotlin { | kotlin { | ||||||
|         kotlinOptions { |   compilerOptions { | ||||||
|             apiVersion = "2.0" |     apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0) | ||||||
|             freeCompilerArgs = listOf("-Xjvm-default=all-compatibility") |     freeCompilerArgs = listOf("-Xjvm-default=all-compatibility") | ||||||
|         } |   } | ||||||
|     } |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // --- Linting | // --- Linting | ||||||
|   | |||||||
| @@ -16,7 +16,7 @@ import com.maddyhome.idea.vim.command.Command | |||||||
| import com.maddyhome.idea.vim.command.OperatorArguments | import com.maddyhome.idea.vim.command.OperatorArguments | ||||||
| import com.maddyhome.idea.vim.handler.VimActionHandler | import com.maddyhome.idea.vim.handler.VimActionHandler | ||||||
|  |  | ||||||
| @CommandOrMotion(keys = ["<C-R>"], modes = [Mode.NORMAL]) | @CommandOrMotion(keys = ["U", "<C-R>"], modes = [Mode.NORMAL, Mode.VISUAL]) | ||||||
| class RedoAction : VimActionHandler.SingleExecution() { | class RedoAction : VimActionHandler.SingleExecution() { | ||||||
|   override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED |   override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED | ||||||
|  |  | ||||||
|   | |||||||
| @@ -16,7 +16,7 @@ import com.maddyhome.idea.vim.command.Command | |||||||
| import com.maddyhome.idea.vim.command.OperatorArguments | import com.maddyhome.idea.vim.command.OperatorArguments | ||||||
| import com.maddyhome.idea.vim.handler.VimActionHandler | import com.maddyhome.idea.vim.handler.VimActionHandler | ||||||
|  |  | ||||||
| @CommandOrMotion(keys = ["u", "<Undo>"], modes = [Mode.NORMAL]) | @CommandOrMotion(keys = ["u", "<Undo>"], modes = [Mode.NORMAL, Mode.VISUAL]) | ||||||
| class UndoAction : VimActionHandler.SingleExecution() { | class UndoAction : VimActionHandler.SingleExecution() { | ||||||
|   override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED |   override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED | ||||||
|  |  | ||||||
|   | |||||||
| @@ -18,10 +18,13 @@ import com.maddyhome.idea.vim.command.Argument | |||||||
| import com.maddyhome.idea.vim.command.Command | import com.maddyhome.idea.vim.command.Command | ||||||
| import com.maddyhome.idea.vim.command.DuplicableOperatorAction | import com.maddyhome.idea.vim.command.DuplicableOperatorAction | ||||||
| import com.maddyhome.idea.vim.command.OperatorArguments | import com.maddyhome.idea.vim.command.OperatorArguments | ||||||
|  | import com.maddyhome.idea.vim.diagnostic.vimLogger | ||||||
| import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler | import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler | ||||||
|  |  | ||||||
| @CommandOrMotion(keys = ["gu"], modes = [Mode.NORMAL]) | @CommandOrMotion(keys = ["gu"], modes = [Mode.NORMAL]) | ||||||
| class ChangeCaseLowerMotionAction : ChangeEditorActionHandler.ForEachCaret(), DuplicableOperatorAction { | class ChangeCaseLowerMotionAction : ChangeEditorActionHandler.ForEachCaret(), DuplicableOperatorAction { | ||||||
|  |   private val logger = vimLogger<ChangeCaseLowerMotionAction>() | ||||||
|  |  | ||||||
|   override val type: Command.Type = Command.Type.CHANGE |   override val type: Command.Type = Command.Type.CHANGE | ||||||
|  |  | ||||||
|   override val argumentType: Argument.Type = Argument.Type.MOTION |   override val argumentType: Argument.Type = Argument.Type.MOTION | ||||||
| @@ -35,15 +38,18 @@ class ChangeCaseLowerMotionAction : ChangeEditorActionHandler.ForEachCaret(), Du | |||||||
|     argument: Argument?, |     argument: Argument?, | ||||||
|     operatorArguments: OperatorArguments, |     operatorArguments: OperatorArguments, | ||||||
|   ): Boolean { |   ): Boolean { | ||||||
|     return argument != null && |     if (argument == null || argument !is Argument.Motion) { | ||||||
|       injector.changeGroup |       logger.error("Argument is null or not Argument.Motion. argument=$argument") | ||||||
|         .changeCaseMotion( |       return false | ||||||
|           editor, |     } | ||||||
|           caret, |  | ||||||
|           context, |     return injector.changeGroup.changeCaseMotion( | ||||||
|           VimChangeGroup.ChangeCaseType.LOWER, |         editor, | ||||||
|           argument, |         caret, | ||||||
|           operatorArguments, |         context, | ||||||
|         ) |         VimChangeGroup.ChangeCaseType.LOWER, | ||||||
|  |         argument, | ||||||
|  |         operatorArguments, | ||||||
|  |       ) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -8,7 +8,6 @@ | |||||||
| package com.maddyhome.idea.vim.action.change.change | package com.maddyhome.idea.vim.action.change.change | ||||||
|  |  | ||||||
| import com.intellij.vim.annotations.CommandOrMotion | import com.intellij.vim.annotations.CommandOrMotion | ||||||
| import com.intellij.vim.annotations.Mode |  | ||||||
| import com.maddyhome.idea.vim.api.ExecutionContext | import com.maddyhome.idea.vim.api.ExecutionContext | ||||||
| import com.maddyhome.idea.vim.api.VimCaret | import com.maddyhome.idea.vim.api.VimCaret | ||||||
| import com.maddyhome.idea.vim.api.VimChangeGroup | import com.maddyhome.idea.vim.api.VimChangeGroup | ||||||
| @@ -22,7 +21,7 @@ import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler | |||||||
| /** | /** | ||||||
|  * @author vlan |  * @author vlan | ||||||
|  */ |  */ | ||||||
| @CommandOrMotion(keys = ["u"], modes = [Mode.VISUAL]) | @CommandOrMotion(keys = [], modes = []) | ||||||
| class ChangeCaseLowerVisualAction : VisualOperatorActionHandler.ForEachCaret() { | class ChangeCaseLowerVisualAction : VisualOperatorActionHandler.ForEachCaret() { | ||||||
|   override val type: Command.Type = Command.Type.CHANGE |   override val type: Command.Type = Command.Type.CHANGE | ||||||
|  |  | ||||||
|   | |||||||
| @@ -18,10 +18,13 @@ import com.maddyhome.idea.vim.command.Argument | |||||||
| import com.maddyhome.idea.vim.command.Command | import com.maddyhome.idea.vim.command.Command | ||||||
| import com.maddyhome.idea.vim.command.DuplicableOperatorAction | import com.maddyhome.idea.vim.command.DuplicableOperatorAction | ||||||
| import com.maddyhome.idea.vim.command.OperatorArguments | import com.maddyhome.idea.vim.command.OperatorArguments | ||||||
|  | import com.maddyhome.idea.vim.diagnostic.vimLogger | ||||||
| import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler | import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler | ||||||
|  |  | ||||||
| @CommandOrMotion(keys = ["g~"], modes = [Mode.NORMAL]) | @CommandOrMotion(keys = ["g~"], modes = [Mode.NORMAL]) | ||||||
| class ChangeCaseToggleMotionAction : ChangeEditorActionHandler.ForEachCaret(), DuplicableOperatorAction { | class ChangeCaseToggleMotionAction : ChangeEditorActionHandler.ForEachCaret(), DuplicableOperatorAction { | ||||||
|  |   private val logger = vimLogger<ChangeCaseToggleMotionAction>() | ||||||
|  |  | ||||||
|   override val type: Command.Type = Command.Type.CHANGE |   override val type: Command.Type = Command.Type.CHANGE | ||||||
|  |  | ||||||
|   override val argumentType: Argument.Type = Argument.Type.MOTION |   override val argumentType: Argument.Type = Argument.Type.MOTION | ||||||
| @@ -35,15 +38,18 @@ class ChangeCaseToggleMotionAction : ChangeEditorActionHandler.ForEachCaret(), D | |||||||
|     argument: Argument?, |     argument: Argument?, | ||||||
|     operatorArguments: OperatorArguments, |     operatorArguments: OperatorArguments, | ||||||
|   ): Boolean { |   ): Boolean { | ||||||
|     return argument != null && |     if (argument == null || argument !is Argument.Motion) { | ||||||
|       injector.changeGroup |       logger.error("Argument is null or not Argument.Motion. argument=$argument") | ||||||
|         .changeCaseMotion( |       return false | ||||||
|           editor, |     } | ||||||
|           caret, |  | ||||||
|           context, |     return injector.changeGroup.changeCaseMotion( | ||||||
|           VimChangeGroup.ChangeCaseType.TOGGLE, |         editor, | ||||||
|           argument, |         caret, | ||||||
|           operatorArguments, |         context, | ||||||
|         ) |         VimChangeGroup.ChangeCaseType.TOGGLE, | ||||||
|  |         argument, | ||||||
|  |         operatorArguments, | ||||||
|  |       ) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -18,10 +18,13 @@ import com.maddyhome.idea.vim.command.Argument | |||||||
| import com.maddyhome.idea.vim.command.Command | import com.maddyhome.idea.vim.command.Command | ||||||
| import com.maddyhome.idea.vim.command.DuplicableOperatorAction | import com.maddyhome.idea.vim.command.DuplicableOperatorAction | ||||||
| import com.maddyhome.idea.vim.command.OperatorArguments | import com.maddyhome.idea.vim.command.OperatorArguments | ||||||
|  | import com.maddyhome.idea.vim.diagnostic.vimLogger | ||||||
| import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler | import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler | ||||||
|  |  | ||||||
| @CommandOrMotion(keys = ["gU"], modes = [Mode.NORMAL]) | @CommandOrMotion(keys = ["gU"], modes = [Mode.NORMAL]) | ||||||
| class ChangeCaseUpperMotionAction : ChangeEditorActionHandler.ForEachCaret(), DuplicableOperatorAction { | class ChangeCaseUpperMotionAction : ChangeEditorActionHandler.ForEachCaret(), DuplicableOperatorAction { | ||||||
|  |   private val logger = vimLogger<ChangeCaseUpperMotionAction>() | ||||||
|  |  | ||||||
|   override val type: Command.Type = Command.Type.CHANGE |   override val type: Command.Type = Command.Type.CHANGE | ||||||
|  |  | ||||||
|   override val argumentType: Argument.Type = Argument.Type.MOTION |   override val argumentType: Argument.Type = Argument.Type.MOTION | ||||||
| @@ -35,15 +38,18 @@ class ChangeCaseUpperMotionAction : ChangeEditorActionHandler.ForEachCaret(), Du | |||||||
|     argument: Argument?, |     argument: Argument?, | ||||||
|     operatorArguments: OperatorArguments, |     operatorArguments: OperatorArguments, | ||||||
|   ): Boolean { |   ): Boolean { | ||||||
|     return argument != null && |     if (argument == null || argument !is Argument.Motion) { | ||||||
|       injector.changeGroup |       logger.error("Argument is null or not Argument.Motion. argument=$argument") | ||||||
|         .changeCaseMotion( |       return false | ||||||
|           editor, |     } | ||||||
|           caret, |  | ||||||
|           context, |     return injector.changeGroup.changeCaseMotion( | ||||||
|           VimChangeGroup.ChangeCaseType.UPPER, |         editor, | ||||||
|           argument, |         caret, | ||||||
|           operatorArguments, |         context, | ||||||
|         ) |         VimChangeGroup.ChangeCaseType.UPPER, | ||||||
|  |         argument, | ||||||
|  |         operatorArguments, | ||||||
|  |       ) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -8,7 +8,6 @@ | |||||||
| package com.maddyhome.idea.vim.action.change.change | package com.maddyhome.idea.vim.action.change.change | ||||||
|  |  | ||||||
| import com.intellij.vim.annotations.CommandOrMotion | import com.intellij.vim.annotations.CommandOrMotion | ||||||
| import com.intellij.vim.annotations.Mode |  | ||||||
| import com.maddyhome.idea.vim.api.ExecutionContext | import com.maddyhome.idea.vim.api.ExecutionContext | ||||||
| import com.maddyhome.idea.vim.api.VimCaret | import com.maddyhome.idea.vim.api.VimCaret | ||||||
| import com.maddyhome.idea.vim.api.VimChangeGroup | import com.maddyhome.idea.vim.api.VimChangeGroup | ||||||
| @@ -22,7 +21,7 @@ import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler | |||||||
| /** | /** | ||||||
|  * @author vlan |  * @author vlan | ||||||
|  */ |  */ | ||||||
| @CommandOrMotion(keys = ["U"], modes = [Mode.VISUAL]) | @CommandOrMotion(keys = [], modes = []) | ||||||
| class ChangeCaseUpperVisualAction : VisualOperatorActionHandler.ForEachCaret() { | class ChangeCaseUpperVisualAction : VisualOperatorActionHandler.ForEachCaret() { | ||||||
|   override val type: Command.Type = Command.Type.CHANGE |   override val type: Command.Type = Command.Type.CHANGE | ||||||
|  |  | ||||||
|   | |||||||
| @@ -27,7 +27,7 @@ class InsertAfterCursorAction : ChangeEditorActionHandler.SingleExecution() { | |||||||
|     argument: Argument?, |     argument: Argument?, | ||||||
|     operatorArguments: OperatorArguments, |     operatorArguments: OperatorArguments, | ||||||
|   ): Boolean { |   ): Boolean { | ||||||
|     injector.changeGroup.insertAfterCursor(editor, context) |     injector.changeGroup.insertAfterCaret(editor, context) | ||||||
|     return true |     return true | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -47,5 +47,5 @@ private fun insertAtPreviousInsert(editor: VimEditor, context: ExecutionContext) | |||||||
|   if (motion is Motion.AbsoluteOffset) { |   if (motion is Motion.AbsoluteOffset) { | ||||||
|     caret.moveToOffset(motion.offset) |     caret.moveToOffset(motion.offset) | ||||||
|   } |   } | ||||||
|   injector.changeGroup.insertBeforeCursor(editor, context) |   injector.changeGroup.insertBeforeCaret(editor, context) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -29,7 +29,7 @@ class InsertBeforeCursorAction : ChangeEditorActionHandler.SingleExecution() { | |||||||
|     argument: Argument?, |     argument: Argument?, | ||||||
|     operatorArguments: OperatorArguments, |     operatorArguments: OperatorArguments, | ||||||
|   ): Boolean { |   ): Boolean { | ||||||
|     injector.changeGroup.insertBeforeCursor(editor, context) |     injector.changeGroup.insertBeforeCaret(editor, context) | ||||||
|     return true |     return true | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -69,15 +69,10 @@ class InsertRegisterAction : VimActionHandler.SingleExecution() { | |||||||
|  */ |  */ | ||||||
| @RWLockLabel.SelfSynchronized | @RWLockLabel.SelfSynchronized | ||||||
| private fun insertRegister(editor: VimEditor, context: ExecutionContext, key: Char): Boolean { | private fun insertRegister(editor: VimEditor, context: ExecutionContext, key: Char): Boolean { | ||||||
|   val register: Register? = injector.registerGroup.getRegister(editor, context, key) |   val register: Register? = injector.registerGroup.getRegister(key) | ||||||
|   if (register != null) { |   if (register != null) { | ||||||
|     val textData = PutData.TextData( |     val textData = PutData.TextData(register.text, SelectionType.CHARACTER_WISE, emptyList(), register.name) | ||||||
|       register.name, |     val putData = PutData(textData, null, 1, insertTextBeforeCaret = true, rawIndent = true, caretAfterInsertedText = true) | ||||||
|       injector.clipboardManager.dumbCopiedText(register.text), |  | ||||||
|       SelectionType.CHARACTER_WISE |  | ||||||
|     ) |  | ||||||
|     val putData = |  | ||||||
|       PutData(textData, null, 1, insertTextBeforeCaret = true, rawIndent = true, caretAfterInsertedText = true) |  | ||||||
|     injector.put.putText(editor, context, putData) |     injector.put.putText(editor, context, putData) | ||||||
|     return true |     return true | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -13,6 +13,7 @@ import com.maddyhome.idea.vim.api.ExecutionContext | |||||||
| import com.maddyhome.idea.vim.api.VimCaret | import com.maddyhome.idea.vim.api.VimCaret | ||||||
| import com.maddyhome.idea.vim.api.VimEditor | import com.maddyhome.idea.vim.api.VimEditor | ||||||
| import com.maddyhome.idea.vim.api.injector | import com.maddyhome.idea.vim.api.injector | ||||||
|  | import com.maddyhome.idea.vim.api.normalizeLine | ||||||
| import com.maddyhome.idea.vim.command.Command | import com.maddyhome.idea.vim.command.Command | ||||||
| import com.maddyhome.idea.vim.command.OperatorArguments | import com.maddyhome.idea.vim.command.OperatorArguments | ||||||
| import com.maddyhome.idea.vim.group.visual.VimSelection | import com.maddyhome.idea.vim.group.visual.VimSelection | ||||||
| @@ -20,10 +21,17 @@ import com.maddyhome.idea.vim.handler.VisualOperatorActionHandler | |||||||
| import com.maddyhome.idea.vim.state.mode.SelectionType | import com.maddyhome.idea.vim.state.mode.SelectionType | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * @author vlan |  * Handles the 'I' command in Visual mode. | ||||||
|  |  * | ||||||
|  |  * For (linewise) Visual mode, the caret positioning follows these rules (based on observation in Vim): | ||||||
|  |  * - If text on multiple lines is selected AND the caret is on the first line (e.g., when selecting from bottom to top), | ||||||
|  |  *   the caret position remains unchanged | ||||||
|  |  * - In all other cases, the caret is moved to the start of the first selected line | ||||||
|  |  * | ||||||
|  |  * For blockwise Visual mode, it initiates insert at the start of block on each line in the selection | ||||||
|  */ |  */ | ||||||
| @CommandOrMotion(keys = ["I"], modes = [Mode.VISUAL]) | @CommandOrMotion(keys = ["I"], modes = [Mode.VISUAL]) | ||||||
| class VisualBlockInsertAction : VisualOperatorActionHandler.SingleExecution() { | class VisualInsertAction : VisualOperatorActionHandler.SingleExecution() { | ||||||
|   override val type: Command.Type = Command.Type.INSERT |   override val type: Command.Type = Command.Type.INSERT | ||||||
| 
 | 
 | ||||||
|   override fun executeForAllCarets( |   override fun executeForAllCarets( | ||||||
| @@ -38,7 +46,17 @@ class VisualBlockInsertAction : VisualOperatorActionHandler.SingleExecution() { | |||||||
|     return if (vimSelection.type == SelectionType.BLOCK_WISE) { |     return if (vimSelection.type == SelectionType.BLOCK_WISE) { | ||||||
|       injector.changeGroup.initBlockInsert(editor, context, vimSelection.toVimTextRange(false), false) |       injector.changeGroup.initBlockInsert(editor, context, vimSelection.toVimTextRange(false), false) | ||||||
|     } else { |     } else { | ||||||
|       injector.changeGroup.insertBeforeFirstNonBlank(editor, context) |       // For visual selections spanning multiple lines, keep caret position if it's on the first line | ||||||
|  |       // Otherwise move the caret to the start of the first selected line | ||||||
|  |       for ((caret, selection) in caretsAndSelections) { | ||||||
|  |         val range = selection.toVimTextRange() | ||||||
|  |         val posStart = editor.offsetToBufferPosition(range.startOffset) | ||||||
|  |         val nextLineStart = editor.getLineStartOffset(editor.normalizeLine(posStart.line + 1)) | ||||||
|  |         if (caret.offset >= nextLineStart || nextLineStart >= range.endOffset) { | ||||||
|  |           caret.moveToOffset(injector.motion.moveCaretToLineStart(editor, posStart.line)) | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |       injector.changeGroup.insertBeforeCaret(editor, context) | ||||||
|       true |       true | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| @@ -10,7 +10,6 @@ package com.maddyhome.idea.vim.action.copy | |||||||
| import com.intellij.vim.annotations.CommandOrMotion | import com.intellij.vim.annotations.CommandOrMotion | ||||||
| import com.intellij.vim.annotations.Mode | import com.intellij.vim.annotations.Mode | ||||||
| import com.maddyhome.idea.vim.api.ExecutionContext | import com.maddyhome.idea.vim.api.ExecutionContext | ||||||
| import com.maddyhome.idea.vim.api.ImmutableVimCaret |  | ||||||
| import com.maddyhome.idea.vim.api.VimEditor | import com.maddyhome.idea.vim.api.VimEditor | ||||||
| import com.maddyhome.idea.vim.api.injector | import com.maddyhome.idea.vim.api.injector | ||||||
| import com.maddyhome.idea.vim.command.Argument | import com.maddyhome.idea.vim.command.Argument | ||||||
| @@ -36,33 +35,40 @@ sealed class PutTextBaseAction( | |||||||
|     val count = operatorArguments.count1 |     val count = operatorArguments.count1 | ||||||
|     val sortedCarets = editor.sortedCarets() |     val sortedCarets = editor.sortedCarets() | ||||||
|     return if (sortedCarets.size > 1) { |     return if (sortedCarets.size > 1) { | ||||||
|       val caretToPutData = sortedCarets.associateWith { getPutDataForCaret(editor, context, it, count) } |       val putData = getPutData(count) | ||||||
|  |  | ||||||
|  |       val splitText = putData.textData?.rawText?.split('\n')?.dropLastWhile(String::isEmpty) | ||||||
|  |       val caretToPutData = if (splitText != null && splitText.size == sortedCarets.size) { | ||||||
|  |         sortedCarets.mapIndexed { index, caret -> caret to putData.copy(textData = putData.textData.copy(rawText = splitText[splitText.lastIndex - index])) }.toMap() | ||||||
|  |       } else { | ||||||
|  |         sortedCarets.associateWith { putData } | ||||||
|  |       } | ||||||
|  |        | ||||||
|       var result = true |       var result = true | ||||||
|       caretToPutData.forEach { |       caretToPutData.forEach { | ||||||
|         result = injector.put.putTextForCaret(editor, it.key, context, it.value) && result |         result = injector.put.putTextForCaret(editor, it.key, context, it.value) && result | ||||||
|       } |       } | ||||||
|       result |       result | ||||||
|     } else { |     } else { | ||||||
|       val putData = getPutDataForCaret(editor, context, sortedCarets.single(), count) |       injector.put.putText(editor, context, getPutData(count)) | ||||||
|       injector.put.putText(editor, context, putData) |  | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   private fun getPutDataForCaret( |   private fun getPutData(count: Int, | ||||||
|     editor: VimEditor, |  | ||||||
|     context: ExecutionContext, |  | ||||||
|     caret: ImmutableVimCaret, |  | ||||||
|     count: Int, |  | ||||||
|   ): PutData { |   ): PutData { | ||||||
|     val registerService = injector.registerGroup |     return PutData(getRegisterTextData(), null, count, insertTextBeforeCaret, indent, caretAfterInsertedText, -1) | ||||||
|     val registerChar = if (caret.editor.carets().size == 1) { |   } | ||||||
|       registerService.currentRegister | } | ||||||
|     } else { |  | ||||||
|       registerService.getCurrentRegisterForMulticaret() | fun getRegisterTextData(): TextData? { | ||||||
|     } |   val register = injector.registerGroup.getRegister(injector.registerGroup.currentRegister) | ||||||
|     val register = caret.registerStorage.getRegister(editor, context, registerChar) |   return register?.let { | ||||||
|     val textData = register?.let { TextData(register) } |     TextData( | ||||||
|     return PutData(textData, null, count, insertTextBeforeCaret, indent, caretAfterInsertedText, -1) |       register.text ?: injector.parser.toPrintableString(register.keys), | ||||||
|  |       register.type, | ||||||
|  |       register.transferableData, | ||||||
|  |       register.name, | ||||||
|  |     ) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -41,8 +41,22 @@ sealed class PutVisualTextBaseAction( | |||||||
|   ): Boolean { |   ): Boolean { | ||||||
|     if (caretsAndSelections.isEmpty()) return false |     if (caretsAndSelections.isEmpty()) return false | ||||||
|     val count = cmd.count |     val count = cmd.count | ||||||
|     val caretToPutData = |     val sortedCarets = | ||||||
|       editor.sortedCarets().associateWith { getPutDataForCaret(editor, context, it, caretsAndSelections[it], count) } |       editor.sortedCarets() | ||||||
|  |  | ||||||
|  |     val textData = getRegisterTextData() | ||||||
|  |     val splitText = textData?.rawText?.split('\n')?.dropLastWhile(String::isEmpty) | ||||||
|  |  | ||||||
|  |     val caretToTextData = if (splitText != null && splitText.size == sortedCarets.size) { | ||||||
|  |       sortedCarets.mapIndexed { index, caret -> caret to textData.copy(rawText = splitText[splitText.lastIndex - index]) }.toMap() | ||||||
|  |     } else { | ||||||
|  |       sortedCarets.associateWith { textData } | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     val caretToPutData = caretToTextData.mapValues { (caret, textData) -> | ||||||
|  |       getPutDataForCaret(textData, caret, caretsAndSelections[caret], count) | ||||||
|  |     } | ||||||
|  |      | ||||||
|     injector.registerGroup.resetRegister() |     injector.registerGroup.resetRegister() | ||||||
|     var result = true |     var result = true | ||||||
|     caretToPutData.forEach { |     caretToPutData.forEach { | ||||||
| @@ -51,16 +65,10 @@ sealed class PutVisualTextBaseAction( | |||||||
|     return result |     return result | ||||||
|   } |   } | ||||||
|    |    | ||||||
|   private fun getPutDataForCaret( |   private fun getPutDataForCaret(textData: PutData.TextData?, | ||||||
|     editor: VimEditor, |  | ||||||
|     context: ExecutionContext, |  | ||||||
|     caret: VimCaret, |     caret: VimCaret, | ||||||
|     selection: VimSelection?, |     selection: VimSelection?, | ||||||
|     count: Int, |     count: Int,): PutData { | ||||||
|   ): PutData { |  | ||||||
|     val lastRegisterChar = injector.registerGroup.lastRegisterChar |  | ||||||
|     val register = caret.registerStorage.getRegister(editor, context, lastRegisterChar) |  | ||||||
|     val textData = register?.let { PutData.TextData(register) } |  | ||||||
|     val visualSelection = selection?.let { PutData.VisualSelection(mapOf(caret to it), it.type) } |     val visualSelection = selection?.let { PutData.VisualSelection(mapOf(caret to it), it.type) } | ||||||
|     return PutData(textData, visualSelection, count, insertTextBeforeCaret, indent, caretAfterInsertedText) |     return PutData(textData, visualSelection, count, insertTextBeforeCaret, indent, caretAfterInsertedText) | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -88,8 +88,7 @@ class ProcessSearchEntryAction(private val parentAction: ProcessExEntryAction) : | |||||||
|  |  | ||||||
|       else -> throw ExException("Unexpected search label ${argument.label}") |       else -> throw ExException("Unexpected search label ${argument.label}") | ||||||
|     } |     } | ||||||
|     // Vim doesn't treat not finding something as an error, although it might report either an error or warning message |     if (offsetAndMotion == null) return Motion.Error | ||||||
|     if (offsetAndMotion == null) return Motion.NoMotion |  | ||||||
|     parentAction.motionType = offsetAndMotion.second |     parentAction.motionType = offsetAndMotion.second | ||||||
|     return offsetAndMotion.first.toMotionOrError() |     return offsetAndMotion.first.toMotionOrError() | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -0,0 +1,32 @@ | |||||||
|  | /* | ||||||
|  |  * Copyright 2003-2025 The IdeaVim authors | ||||||
|  |  * | ||||||
|  |  * Use of this source code is governed by an MIT-style | ||||||
|  |  * license that can be found in the LICENSE.txt file or at | ||||||
|  |  * https://opensource.org/licenses/MIT. | ||||||
|  |  */ | ||||||
|  | package com.maddyhome.idea.vim.action.file | ||||||
|  |  | ||||||
|  | import com.intellij.vim.annotations.CommandOrMotion | ||||||
|  | import com.intellij.vim.annotations.Mode | ||||||
|  | import com.maddyhome.idea.vim.api.ExecutionContext | ||||||
|  | import com.maddyhome.idea.vim.api.VimEditor | ||||||
|  | import com.maddyhome.idea.vim.api.injector | ||||||
|  | import com.maddyhome.idea.vim.command.Command | ||||||
|  | import com.maddyhome.idea.vim.command.OperatorArguments | ||||||
|  | import com.maddyhome.idea.vim.handler.VimActionHandler | ||||||
|  |  | ||||||
|  | @CommandOrMotion(keys = ["ZQ"], modes = [Mode.NORMAL]) | ||||||
|  | class FileCloseAction : VimActionHandler.SingleExecution() { | ||||||
|  |   override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED | ||||||
|  |  | ||||||
|  |   override fun execute( | ||||||
|  |     editor: VimEditor, | ||||||
|  |     context: ExecutionContext, | ||||||
|  |     cmd: Command, | ||||||
|  |     operatorArguments: OperatorArguments, | ||||||
|  |   ): Boolean { | ||||||
|  |     injector.file.closeFile(editor, context) | ||||||
|  |     return true | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
|  * Copyright 2003-2023 The IdeaVim authors |  * Copyright 2003-2025 The IdeaVim authors | ||||||
|  * |  * | ||||||
|  * Use of this source code is governed by an MIT-style |  * Use of this source code is governed by an MIT-style | ||||||
|  * license that can be found in the LICENSE.txt file or at |  * license that can be found in the LICENSE.txt file or at | ||||||
| @@ -16,9 +16,9 @@ import com.maddyhome.idea.vim.command.Command | |||||||
| import com.maddyhome.idea.vim.command.OperatorArguments | import com.maddyhome.idea.vim.command.OperatorArguments | ||||||
| import com.maddyhome.idea.vim.handler.VimActionHandler | import com.maddyhome.idea.vim.handler.VimActionHandler | ||||||
|  |  | ||||||
| @CommandOrMotion(keys = ["ZQ", "ZZ"], modes = [Mode.NORMAL]) | @CommandOrMotion(keys = ["ZZ"], modes = [Mode.NORMAL]) | ||||||
| class FileSaveCloseAction : VimActionHandler.SingleExecution() { | class FileSaveCloseAction : VimActionHandler.SingleExecution() { | ||||||
|   override val type: Command.Type = Command.Type.OTHER_WRITABLE |   override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED | ||||||
|  |  | ||||||
|   override fun execute( |   override fun execute( | ||||||
|     editor: VimEditor, |     editor: VimEditor, | ||||||
|   | |||||||
| @@ -76,6 +76,13 @@ sealed class TillCharacterMotion( | |||||||
|       ) |       ) | ||||||
|     } |     } | ||||||
|     injector.motion.setLastFTCmd(tillCharacterMotionType, argument.character) |     injector.motion.setLastFTCmd(tillCharacterMotionType, argument.character) | ||||||
|  |      | ||||||
|  |     val offset = if (!finishBeforeCharacter) "" | ||||||
|  |     else if (direction == Direction.FORWARDS) "s-1" | ||||||
|  |     else "s+1" | ||||||
|  |      | ||||||
|  |     injector.searchGroup.setLastSearchState(argument.character.let { if (it in "`^$.*[~/\\") "\\$it" else it.toString() }, offset, direction) | ||||||
|  |      | ||||||
|     return res.toMotionOrError() |     return res.toMotionOrError() | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -48,7 +48,7 @@ class SelectMotionArrowLeftAction : MotionActionHandler.ForEachCaret() { | |||||||
|       editor.exitSelectModeNative(false) |       editor.exitSelectModeNative(false) | ||||||
|       if (editor.isTemplateActive()) { |       if (editor.isTemplateActive()) { | ||||||
|         logger.debug("Template is active. Activate insert mode") |         logger.debug("Template is active. Activate insert mode") | ||||||
|         injector.changeGroup.insertBeforeCursor(editor, context) |         injector.changeGroup.insertBeforeCaret(editor, context) | ||||||
|         if (caret.offset in startSelection..endSelection) { |         if (caret.offset in startSelection..endSelection) { | ||||||
|           return startSelection.toMotion() |           return startSelection.toMotion() | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -48,7 +48,7 @@ class SelectMotionArrowRightAction : MotionActionHandler.ForEachCaret() { | |||||||
|       editor.exitSelectModeNative(false) |       editor.exitSelectModeNative(false) | ||||||
|       if (editor.isTemplateActive()) { |       if (editor.isTemplateActive()) { | ||||||
|         logger.debug("Template is active. Activate insert mode") |         logger.debug("Template is active. Activate insert mode") | ||||||
|         injector.changeGroup.insertBeforeCursor(editor, context) |         injector.changeGroup.insertBeforeCaret(editor, context) | ||||||
|         if (caret.offset in startSelection..endSelection) { |         if (caret.offset in startSelection..endSelection) { | ||||||
|           return endSelection.toMotion() |           return endSelection.toMotion() | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -31,6 +31,12 @@ class MotionCamelLeftAction : MotionActionHandler.ForEachCaret() { | |||||||
|     argument: Argument?, |     argument: Argument?, | ||||||
|     operatorArguments: OperatorArguments, |     operatorArguments: OperatorArguments, | ||||||
|   ): Motion { |   ): Motion { | ||||||
|  |     if (caret.hasSelection() && caret.offset > caret.vimSelectionStart) { | ||||||
|  |       val target = injector.searchHelper.findPreviousCamelEnd(editor.text(), caret.offset, operatorArguments.count1) | ||||||
|  |       if (target != null && target > caret.vimSelectionStart) { | ||||||
|  |         return target.toMotionOrError() | ||||||
|  |       } | ||||||
|  |     } | ||||||
|     return injector.searchHelper.findPreviousCamelStart(editor.text(), caret.offset, operatorArguments.count1) |     return injector.searchHelper.findPreviousCamelStart(editor.text(), caret.offset, operatorArguments.count1) | ||||||
|       ?.toMotionOrError() ?: Motion.Error |       ?.toMotionOrError() ?: Motion.Error | ||||||
|   } |   } | ||||||
| @@ -47,6 +53,10 @@ class MotionCamelRightAction : MotionActionHandler.ForEachCaret() { | |||||||
|     argument: Argument?, |     argument: Argument?, | ||||||
|     operatorArguments: OperatorArguments, |     operatorArguments: OperatorArguments, | ||||||
|   ): Motion { |   ): Motion { | ||||||
|  |     if (caret.hasSelection() && caret.offset >= caret.vimSelectionStart) { | ||||||
|  |       return injector.searchHelper.findNextCamelEnd(editor.text(), caret.offset + 1, operatorArguments.count1) | ||||||
|  |         ?.toMotionOrError() ?: Motion.Error | ||||||
|  |     } | ||||||
|     return injector.searchHelper.findNextCamelStart(editor.text(), caret.offset + 1, operatorArguments.count1) |     return injector.searchHelper.findNextCamelStart(editor.text(), caret.offset + 1, operatorArguments.count1) | ||||||
|       ?.toMotionOrError() ?: Motion.Error |       ?.toMotionOrError() ?: Motion.Error | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -70,6 +70,6 @@ class MotionDownNotLineWiseAction : MotionActionHandler.ForEachCaret() { | |||||||
|     argument: Argument?, |     argument: Argument?, | ||||||
|     operatorArguments: OperatorArguments, |     operatorArguments: OperatorArguments, | ||||||
|   ): Motion { |   ): Motion { | ||||||
|     return injector.motion.getVerticalMotionOffset(editor, caret, operatorArguments.count1) |     return injector.motion.getVerticalMotionOffset(editor, caret, operatorArguments.count1, bufferLines = true) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -70,6 +70,6 @@ class MotionUpNotLineWiseAction : MotionActionHandler.ForEachCaret() { | |||||||
|     argument: Argument?, |     argument: Argument?, | ||||||
|     operatorArguments: OperatorArguments, |     operatorArguments: OperatorArguments, | ||||||
|   ): Motion { |   ): Motion { | ||||||
|     return injector.motion.getVerticalMotionOffset(editor, caret, -operatorArguments.count1) |     return injector.motion.getVerticalMotionOffset(editor, caret, -operatorArguments.count1, bufferLines = true) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -9,7 +9,6 @@ | |||||||
| package com.maddyhome.idea.vim.api | package com.maddyhome.idea.vim.api | ||||||
|  |  | ||||||
| import com.maddyhome.idea.vim.common.LiveRange | import com.maddyhome.idea.vim.common.LiveRange | ||||||
| import com.maddyhome.idea.vim.common.TextRange |  | ||||||
| import com.maddyhome.idea.vim.group.visual.VisualChange | import com.maddyhome.idea.vim.group.visual.VisualChange | ||||||
| import com.maddyhome.idea.vim.group.visual.vimMoveBlockSelectionToOffset | import com.maddyhome.idea.vim.group.visual.vimMoveBlockSelectionToOffset | ||||||
| import com.maddyhome.idea.vim.group.visual.vimMoveSelectionToCaret | import com.maddyhome.idea.vim.group.visual.vimMoveSelectionToCaret | ||||||
| @@ -17,13 +16,11 @@ import com.maddyhome.idea.vim.handler.Motion | |||||||
| import com.maddyhome.idea.vim.helper.RWLockLabel | import com.maddyhome.idea.vim.helper.RWLockLabel | ||||||
| import com.maddyhome.idea.vim.helper.StrictMode | import com.maddyhome.idea.vim.helper.StrictMode | ||||||
| import com.maddyhome.idea.vim.helper.exitVisualMode | import com.maddyhome.idea.vim.helper.exitVisualMode | ||||||
| import com.maddyhome.idea.vim.register.Register | import com.maddyhome.idea.vim.register.VimRegisterGroup | ||||||
| import com.maddyhome.idea.vim.state.mode.SelectionType |  | ||||||
| import com.maddyhome.idea.vim.state.mode.inBlockSelection | import com.maddyhome.idea.vim.state.mode.inBlockSelection | ||||||
| import com.maddyhome.idea.vim.state.mode.inCommandLineModeWithVisual | import com.maddyhome.idea.vim.state.mode.inCommandLineModeWithVisual | ||||||
| import com.maddyhome.idea.vim.state.mode.inSelectMode | import com.maddyhome.idea.vim.state.mode.inSelectMode | ||||||
| import com.maddyhome.idea.vim.state.mode.inVisualMode | import com.maddyhome.idea.vim.state.mode.inVisualMode | ||||||
| import javax.swing.KeyStroke |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Immutable interface of the caret. Immutable caret is an important concept of Fleet. |  * Immutable interface of the caret. Immutable caret is an important concept of Fleet. | ||||||
| @@ -65,7 +62,7 @@ interface ImmutableVimCaret { | |||||||
|   fun hasSelection(): Boolean |   fun hasSelection(): Boolean | ||||||
|  |  | ||||||
|   var lastSelectionInfo: SelectionInfo |   var lastSelectionInfo: SelectionInfo | ||||||
|   val registerStorage: CaretRegisterStorage |   val registerStorage: VimRegisterGroup | ||||||
|   val markStorage: LocalMarkStorage |   val markStorage: LocalMarkStorage | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -151,19 +148,3 @@ fun VimCaret.moveToMotion(motion: Motion): VimCaret { | |||||||
|     this |     this | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| interface CaretRegisterStorage { |  | ||||||
|   val caret: ImmutableVimCaret |  | ||||||
|  |  | ||||||
|   fun storeText( |  | ||||||
|     editor: VimEditor, |  | ||||||
|     context: ExecutionContext, |  | ||||||
|     range: TextRange, |  | ||||||
|     type: SelectionType, |  | ||||||
|     isDelete: Boolean, |  | ||||||
|   ): Boolean |  | ||||||
|  |  | ||||||
|   fun getRegister(editor: VimEditor, context: ExecutionContext, r: Char): Register? |  | ||||||
|   fun setKeys(editor: VimEditor, context: ExecutionContext, register: Char, keys: List<KeyStroke>) |  | ||||||
|   fun saveRegister(editor: VimEditor, context: ExecutionContext, r: Char, register: Register) |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -8,94 +8,4 @@ | |||||||
|  |  | ||||||
| package com.maddyhome.idea.vim.api | package com.maddyhome.idea.vim.api | ||||||
|  |  | ||||||
| import com.maddyhome.idea.vim.common.TextRange |  | ||||||
| import com.maddyhome.idea.vim.register.Register |  | ||||||
| import com.maddyhome.idea.vim.register.RegisterConstants |  | ||||||
| import com.maddyhome.idea.vim.register.VimRegisterGroupBase |  | ||||||
| import com.maddyhome.idea.vim.state.mode.SelectionType |  | ||||||
| import javax.swing.KeyStroke |  | ||||||
|  |  | ||||||
| abstract class VimCaretBase : VimCaret | abstract class VimCaretBase : VimCaret | ||||||
|  |  | ||||||
| open class CaretRegisterStorageBase(override var caret: ImmutableVimCaret) : CaretRegisterStorage, |  | ||||||
|   VimRegisterGroupBase() { |  | ||||||
|   companion object { |  | ||||||
|     private const val ALLOWED_TO_STORE_REGISTERS = RegisterConstants.RECORDABLE_REGISTERS + |  | ||||||
|       RegisterConstants.SMALL_DELETION_REGISTER + |  | ||||||
|       RegisterConstants.BLACK_HOLE_REGISTER + |  | ||||||
|       RegisterConstants.LAST_INSERTED_TEXT_REGISTER + |  | ||||||
|       RegisterConstants.LAST_SEARCH_REGISTER |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   override var lastRegisterChar: Char |  | ||||||
|     get() { |  | ||||||
|       return injector.registerGroup.lastRegisterChar |  | ||||||
|     } |  | ||||||
|     set(_) {} |  | ||||||
|  |  | ||||||
|   override var isRegisterSpecifiedExplicitly: Boolean |  | ||||||
|     get() { |  | ||||||
|       return injector.registerGroup.isRegisterSpecifiedExplicitly |  | ||||||
|     } |  | ||||||
|     set(_) {} |  | ||||||
|  |  | ||||||
|   override fun storeText( |  | ||||||
|     editor: VimEditor, |  | ||||||
|     context: ExecutionContext, |  | ||||||
|     range: TextRange, |  | ||||||
|     type: SelectionType, |  | ||||||
|     isDelete: Boolean, |  | ||||||
|   ): Boolean { |  | ||||||
|     val registerChar = if (caret.editor.carets().size == 1) currentRegister else getCurrentRegisterForMulticaret() |  | ||||||
|     if (caret.isPrimary) { |  | ||||||
|       val registerService = injector.registerGroup |  | ||||||
|       registerService.lastRegisterChar = registerChar |  | ||||||
|       return registerService.storeText(editor, context, caret, range, type, isDelete) |  | ||||||
|     } else { |  | ||||||
|       if (!ALLOWED_TO_STORE_REGISTERS.contains(registerChar)) { |  | ||||||
|         return false |  | ||||||
|       } |  | ||||||
|       val text = preprocessTextBeforeStoring(editor.getText(range), type) |  | ||||||
|       return storeTextInternal(editor, context, range, text, type, registerChar, isDelete) |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   override fun getRegister(r: Char): Register? { |  | ||||||
|     val editorStub = injector.fallbackWindow |  | ||||||
|     val contextStub = injector.executionContextManager.getEditorExecutionContext(editorStub) |  | ||||||
|     return getRegister(editorStub, contextStub, r) |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   override fun getRegister(editor: VimEditor, context: ExecutionContext, r: Char): Register? { |  | ||||||
|     if (caret.isPrimary || !RegisterConstants.RECORDABLE_REGISTERS.contains(r)) { |  | ||||||
|       return injector.registerGroup.getRegister(editor, context, r) |  | ||||||
|     } |  | ||||||
|     return super.getRegister(editor, context, r) ?: injector.registerGroup.getRegister(editor, context, r) |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   override fun setKeys(register: Char, keys: List<KeyStroke>) { |  | ||||||
|     val editorStub = injector.fallbackWindow |  | ||||||
|     val contextStub = injector.executionContextManager.getEditorExecutionContext(editorStub) |  | ||||||
|     setKeys(editorStub, contextStub, register, keys) |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   override fun setKeys(editor: VimEditor, context: ExecutionContext, register: Char, keys: List<KeyStroke>) { |  | ||||||
|     if (caret.isPrimary) { |  | ||||||
|       injector.registerGroup.setKeys(register, keys) |  | ||||||
|     } |  | ||||||
|     if (!RegisterConstants.RECORDABLE_REGISTERS.contains(register)) { |  | ||||||
|       return |  | ||||||
|     } |  | ||||||
|     return super.setKeys(register, keys) |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   override fun saveRegister(editor: VimEditor, context: ExecutionContext, r: Char, register: Register) { |  | ||||||
|     if (caret.isPrimary) { |  | ||||||
|       injector.registerGroup.saveRegister(editor, context, r, register) |  | ||||||
|     } |  | ||||||
|     if (!RegisterConstants.RECORDABLE_REGISTERS.contains(r)) { |  | ||||||
|       return |  | ||||||
|     } |  | ||||||
|     return super.saveRegister(editor, context, r, register) |  | ||||||
|   } |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -23,13 +23,13 @@ import javax.swing.KeyStroke | |||||||
| interface VimChangeGroup { | interface VimChangeGroup { | ||||||
|   fun setInsertRepeat(lines: Int, column: Int, append: Boolean) |   fun setInsertRepeat(lines: Int, column: Int, append: Boolean) | ||||||
|  |  | ||||||
|   fun insertBeforeCursor(editor: VimEditor, context: ExecutionContext) |   fun insertBeforeCaret(editor: VimEditor, context: ExecutionContext) | ||||||
|  |  | ||||||
|   fun insertBeforeFirstNonBlank(editor: VimEditor, context: ExecutionContext) |   fun insertBeforeFirstNonBlank(editor: VimEditor, context: ExecutionContext) | ||||||
|  |  | ||||||
|   fun insertLineStart(editor: VimEditor, context: ExecutionContext) |   fun insertLineStart(editor: VimEditor, context: ExecutionContext) | ||||||
|  |  | ||||||
|   fun insertAfterCursor(editor: VimEditor, context: ExecutionContext) |   fun insertAfterCaret(editor: VimEditor, context: ExecutionContext) | ||||||
|  |  | ||||||
|   fun insertAfterLineEnd(editor: VimEditor, context: ExecutionContext) |   fun insertAfterLineEnd(editor: VimEditor, context: ExecutionContext) | ||||||
|  |  | ||||||
| @@ -198,7 +198,7 @@ interface VimChangeGroup { | |||||||
|     caret: VimCaret, |     caret: VimCaret, | ||||||
|     context: ExecutionContext?, |     context: ExecutionContext?, | ||||||
|     type: ChangeCaseType, |     type: ChangeCaseType, | ||||||
|     argument: Argument, |     argument: Argument.Motion, | ||||||
|     operatorArguments: OperatorArguments, |     operatorArguments: OperatorArguments, | ||||||
|   ): Boolean |   ): Boolean | ||||||
|  |  | ||||||
| @@ -231,7 +231,7 @@ interface VimChangeGroup { | |||||||
|     operatorArguments: OperatorArguments, |     operatorArguments: OperatorArguments, | ||||||
|   ) |   ) | ||||||
|  |  | ||||||
|   fun insertText(editor: VimEditor, caret: VimCaret, offset: Int, str: String): VimCaret |   fun insertText(editor: VimEditor, caret: VimCaret, offset: Int, str: CharSequence): VimCaret | ||||||
|  |  | ||||||
|   fun insertText(editor: VimEditor, caret: VimCaret, str: String): VimCaret |   fun insertText(editor: VimEditor, caret: VimCaret, str: String): VimCaret | ||||||
|  |  | ||||||
|   | |||||||
| @@ -182,31 +182,41 @@ abstract class VimChangeGroupBase : VimChangeGroup { | |||||||
|         return false |         return false | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |     val mode = editor.mode | ||||||
|     val isInsertMode = editor.mode == Mode.INSERT || editor.mode == Mode.REPLACE |     if (type == null || | ||||||
|     val shouldYank = type != null && !isInsertMode && saveToRegister |       (mode == Mode.INSERT || mode == Mode.REPLACE) || | ||||||
|     if (shouldYank && !caret.registerStorage.storeText(editor, context, updatedRange, type, isDelete = true)) { |       !saveToRegister || | ||||||
|       return false |       injector.registerGroup.storeText( | ||||||
|     } |  | ||||||
|  |  | ||||||
|     val startOffsets = updatedRange.startOffsets |  | ||||||
|     val endOffsets = updatedRange.endOffsets |  | ||||||
|     for (i in updatedRange.size() - 1 downTo 0) { |  | ||||||
|       val (newRange, _) = editor.search( |  | ||||||
|         startOffsets[i] to endOffsets[i], |  | ||||||
|         editor, |         editor, | ||||||
|         LineDeleteShift.NL_ON_END |         context, | ||||||
|       ) ?: continue |         caret, | ||||||
|       injector.application.runWriteAction { |         updatedRange, | ||||||
|  |         type, | ||||||
|  |         true, | ||||||
|  |         !editor.isFirstCaret, | ||||||
|  |         editor.isReversingCarets | ||||||
|  |       ) | ||||||
|  |     ) { | ||||||
|  |       val startOffsets = updatedRange.startOffsets | ||||||
|  |       val endOffsets = updatedRange.endOffsets | ||||||
|  |       for (i in updatedRange.size() - 1 downTo 0) { | ||||||
|  |         val (newRange, _) = editor.search( | ||||||
|  |           startOffsets[i] to endOffsets[i], | ||||||
|  |           editor, | ||||||
|  |           LineDeleteShift.NL_ON_END | ||||||
|  |         ) ?: continue | ||||||
|  |         injector.application.runWriteAction { | ||||||
|         editor.deleteString(TextRange(newRange.first, newRange.second)) |         editor.deleteString(TextRange(newRange.first, newRange.second)) | ||||||
|       } |       } | ||||||
|  |       } | ||||||
|  |       if (type != null) { | ||||||
|  |         val start = updatedRange.startOffset | ||||||
|  |         injector.markService.setMark(caret, MARK_CHANGE_POS, start) | ||||||
|  |         injector.markService.setChangeMarks(caret, TextRange(start, start + 1)) | ||||||
|  |       } | ||||||
|  |       return true | ||||||
|     } |     } | ||||||
|     if (type != null) { |     return false | ||||||
|       val start = updatedRange.startOffset |  | ||||||
|       injector.markService.setMark(caret, MARK_CHANGE_POS, start) |  | ||||||
|       injector.markService.setChangeMarks(caret, TextRange(start, start + 1)) |  | ||||||
|     } |  | ||||||
|     return true |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
| @@ -216,7 +226,7 @@ abstract class VimChangeGroupBase : VimChangeGroup { | |||||||
|    * @param caret  The caret to start insertion in |    * @param caret  The caret to start insertion in | ||||||
|    * @param str    The text to insert |    * @param str    The text to insert | ||||||
|    */ |    */ | ||||||
|   override fun insertText(editor: VimEditor, caret: VimCaret, offset: Int, str: String): VimCaret { |   override fun insertText(editor: VimEditor, caret: VimCaret, offset: Int, str: CharSequence): VimCaret { | ||||||
|     injector.application.runWriteAction { |     injector.application.runWriteAction { | ||||||
|       (editor as MutableVimEditor).insertText(caret, offset, str) |       (editor as MutableVimEditor).insertText(caret, offset, str) | ||||||
|     } |     } | ||||||
| @@ -391,7 +401,7 @@ abstract class VimChangeGroupBase : VimChangeGroup { | |||||||
|    * @param editor  The editor to insert into |    * @param editor  The editor to insert into | ||||||
|    * @param context The data context |    * @param context The data context | ||||||
|    */ |    */ | ||||||
|   override fun insertBeforeCursor(editor: VimEditor, context: ExecutionContext) { |   override fun insertBeforeCaret(editor: VimEditor, context: ExecutionContext) { | ||||||
|     initInsert(editor, context, Mode.INSERT) |     initInsert(editor, context, Mode.INSERT) | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -407,7 +417,7 @@ abstract class VimChangeGroupBase : VimChangeGroup { | |||||||
|    * @param editor  The editor to insert into |    * @param editor  The editor to insert into | ||||||
|    * @param context The data context |    * @param context The data context | ||||||
|    */ |    */ | ||||||
|   override fun insertAfterCursor(editor: VimEditor, context: ExecutionContext) { |   override fun insertAfterCaret(editor: VimEditor, context: ExecutionContext) { | ||||||
|     for (caret in editor.nativeCarets()) { |     for (caret in editor.nativeCarets()) { | ||||||
|       caret.moveToMotion(injector.motion.getHorizontalMotion(editor, caret, 1, true)) |       caret.moveToMotion(injector.motion.getHorizontalMotion(editor, caret, 1, true)) | ||||||
|     } |     } | ||||||
| @@ -771,7 +781,7 @@ abstract class VimChangeGroupBase : VimChangeGroup { | |||||||
|         lambdaEditor.exitSelectModeNative(false) |         lambdaEditor.exitSelectModeNative(false) | ||||||
|         KeyHandler.getInstance().reset(lambdaEditor) |         KeyHandler.getInstance().reset(lambdaEditor) | ||||||
|         if (isPrintableChar(key.keyChar) || activeTemplateWithLeftRightMotion(lambdaEditor, key)) { |         if (isPrintableChar(key.keyChar) || activeTemplateWithLeftRightMotion(lambdaEditor, key)) { | ||||||
|           injector.changeGroup.insertBeforeCursor(lambdaEditor, lambdaContext) |           injector.changeGroup.insertBeforeCaret(lambdaEditor, lambdaContext) | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
| @@ -1292,7 +1302,7 @@ abstract class VimChangeGroupBase : VimChangeGroup { | |||||||
|       if (type === SelectionType.LINE_WISE) { |       if (type === SelectionType.LINE_WISE) { | ||||||
|         // Please don't use `getDocument().getText().isEmpty()` because it converts CharSequence into String |         // Please don't use `getDocument().getText().isEmpty()` because it converts CharSequence into String | ||||||
|         if (editor.fileSize() == 0L) { |         if (editor.fileSize() == 0L) { | ||||||
|           insertBeforeCursor(editor, context) |           insertBeforeCaret(editor, context) | ||||||
|         } else if (after && !editor.endsWithNewLine()) { |         } else if (after && !editor.endsWithNewLine()) { | ||||||
|           insertNewLineBelow(editor, updatedCaret, lp.column) |           insertNewLineBelow(editor, updatedCaret, lp.column) | ||||||
|         } else { |         } else { | ||||||
| @@ -1305,7 +1315,7 @@ abstract class VimChangeGroupBase : VimChangeGroup { | |||||||
|         editor.vimChangeActionSwitchMode = Mode.INSERT |         editor.vimChangeActionSwitchMode = Mode.INSERT | ||||||
|       } |       } | ||||||
|     } else { |     } else { | ||||||
|       insertBeforeCursor(editor, context) |       insertBeforeCaret(editor, context) | ||||||
|     } |     } | ||||||
|     return true |     return true | ||||||
|   } |   } | ||||||
| @@ -1857,14 +1867,22 @@ abstract class VimChangeGroupBase : VimChangeGroup { | |||||||
|     caret: VimCaret, |     caret: VimCaret, | ||||||
|     context: ExecutionContext?, |     context: ExecutionContext?, | ||||||
|     type: VimChangeGroup.ChangeCaseType, |     type: VimChangeGroup.ChangeCaseType, | ||||||
|     argument: Argument, |     argument: Argument.Motion, | ||||||
|     operatorArguments: OperatorArguments, |     operatorArguments: OperatorArguments, | ||||||
|   ): Boolean { |   ): Boolean { | ||||||
|     val range = injector.motion.getMotionRange( |     var range = injector.motion.getMotionRange( | ||||||
|       editor, caret, context!!, argument, |       editor, caret, context!!, argument, operatorArguments | ||||||
|       operatorArguments |  | ||||||
|     ) |     ) | ||||||
|     return range != null && changeCaseRange(editor, caret, range, type) |     if (range == null) return false | ||||||
|  |  | ||||||
|  |     // If the motion is linewise, we need to adjust range.startOffset to match the observed Vim behavior | ||||||
|  |     if (argument.isLinewiseMotion()) { | ||||||
|  |       val pos = editor.offsetToBufferPosition(range.startOffset) | ||||||
|  |       // The leftmost non-whitespace character OR the current caret position, whichever is closer to the left | ||||||
|  |       val start = editor.getLeadingCharacterOffset(pos.line).coerceAtMost(caret.offset) | ||||||
|  |       range = TextRange(start, range.endOffset) | ||||||
|  |     } | ||||||
|  |     return changeCaseRange(editor, caret, range, type) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
| @@ -2030,7 +2048,7 @@ abstract class VimChangeGroupBase : VimChangeGroup { | |||||||
|       caret.moveToInlayAwareOffset(editor.bufferPositionToOffset(BufferPosition(line, column))) |       caret.moveToInlayAwareOffset(editor.bufferPositionToOffset(BufferPosition(line, column))) | ||||||
|       setInsertRepeat(lines, column, append) |       setInsertRepeat(lines, column, append) | ||||||
|     } |     } | ||||||
|     insertBeforeCursor(editor, context) |     insertBeforeCaret(editor, context) | ||||||
|     return true |     return true | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -20,7 +20,7 @@ import java.awt.datatransfer.Transferable | |||||||
|  * - **Clipboard**: This is supported by all operating systems. It functions as a storage for the common 'copy and paste' operations typically done with Ctrl-C and Ctrl-V. |  * - **Clipboard**: This is supported by all operating systems. It functions as a storage for the common 'copy and paste' operations typically done with Ctrl-C and Ctrl-V. | ||||||
|  */ |  */ | ||||||
| interface VimClipboardManager { | interface VimClipboardManager { | ||||||
|   fun getPrimaryContent(editor: VimEditor, context: ExecutionContext): VimCopiedText? |   fun getPrimaryContent(): VimCopiedText? | ||||||
|  |  | ||||||
|   fun getClipboardContent(editor: VimEditor, context: ExecutionContext): VimCopiedText? |   fun getClipboardContent(editor: VimEditor, context: ExecutionContext): VimCopiedText? | ||||||
|  |  | ||||||
|   | |||||||
| @@ -111,7 +111,8 @@ interface VimEditor { | |||||||
|    * This method should perform caret merging after the operations. This is similar to IJ runForEachCaret |    * This method should perform caret merging after the operations. This is similar to IJ runForEachCaret | ||||||
|    * TODO review |    * TODO review | ||||||
|    */ |    */ | ||||||
|  |   val isFirstCaret: Boolean | ||||||
|  |   val isReversingCarets: Boolean | ||||||
|   fun forEachCaret(action: (VimCaret) -> Unit) |   fun forEachCaret(action: (VimCaret) -> Unit) | ||||||
|   fun forEachNativeCaret(action: (VimCaret) -> Unit, reverse: Boolean = false) |   fun forEachNativeCaret(action: (VimCaret) -> Unit, reverse: Boolean = false) | ||||||
|   fun isInForEachCaretScope(): Boolean |   fun isInForEachCaretScope(): Boolean | ||||||
| @@ -210,6 +211,7 @@ interface VimEditor { | |||||||
|  |  | ||||||
|   fun createIndentBySize(size: Int): String |   fun createIndentBySize(size: Int): String | ||||||
|   fun getFoldRegionAtOffset(offset: Int): VimFoldRegion? |   fun getFoldRegionAtOffset(offset: Int): VimFoldRegion? | ||||||
|  |   fun getSoftWrapStartAtOffset(offset: Int): Int? | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * Mostly related to Fleet. After the editor is modified, the carets are modified. You can't use the old caret |    * Mostly related to Fleet. After the editor is modified, the carets are modified. You can't use the old caret | ||||||
|   | |||||||
| @@ -17,8 +17,6 @@ import com.maddyhome.idea.vim.common.VimListenersNotifier | |||||||
| import com.maddyhome.idea.vim.diagnostic.VimLogger | import com.maddyhome.idea.vim.diagnostic.VimLogger | ||||||
| import com.maddyhome.idea.vim.diagnostic.vimLogger | import com.maddyhome.idea.vim.diagnostic.vimLogger | ||||||
| import com.maddyhome.idea.vim.impl.state.VimStateMachineImpl | import com.maddyhome.idea.vim.impl.state.VimStateMachineImpl | ||||||
| import com.maddyhome.idea.vim.register.VimRegisterGroup |  | ||||||
| import com.maddyhome.idea.vim.register.VimRegisterGroupBase |  | ||||||
| import com.maddyhome.idea.vim.state.VimStateMachine | import com.maddyhome.idea.vim.state.VimStateMachine | ||||||
| import com.maddyhome.idea.vim.vimscript.services.VariableService | import com.maddyhome.idea.vim.vimscript.services.VariableService | ||||||
| import com.maddyhome.idea.vim.vimscript.services.VimVariableServiceBase | import com.maddyhome.idea.vim.vimscript.services.VimVariableServiceBase | ||||||
| @@ -28,7 +26,6 @@ import com.maddyhome.idea.vim.yank.YankGroupBase | |||||||
| abstract class VimInjectorBase : VimInjector { | abstract class VimInjectorBase : VimInjector { | ||||||
|   companion object { |   companion object { | ||||||
|     val logger: VimLogger by lazy { vimLogger<VimInjectorBase>() } |     val logger: VimLogger by lazy { vimLogger<VimInjectorBase>() } | ||||||
|     val registerGroupStub: VimRegisterGroupBase by lazy { object : VimRegisterGroupBase() {} } |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   override val vimState: VimStateMachine = VimStateMachineImpl() |   override val vimState: VimStateMachine = VimStateMachineImpl() | ||||||
| @@ -38,8 +35,6 @@ abstract class VimInjectorBase : VimInjector { | |||||||
|  |  | ||||||
|   override val variableService: VariableService by lazy { object : VimVariableServiceBase() {} } |   override val variableService: VariableService by lazy { object : VimVariableServiceBase() {} } | ||||||
|  |  | ||||||
|   override val registerGroup: VimRegisterGroup by lazy { registerGroupStub } |  | ||||||
|   override val registerGroupIfCreated: VimRegisterGroup? by lazy { registerGroupStub } |  | ||||||
|   override val messages: VimMessages by lazy { VimMessagesStub() } |   override val messages: VimMessages by lazy { VimMessagesStub() } | ||||||
|   override val processGroup: VimProcessGroup by lazy { VimProcessGroupStub() } |   override val processGroup: VimProcessGroup by lazy { VimProcessGroupStub() } | ||||||
|   override val application: VimApplication by lazy { VimApplicationStub() } |   override val application: VimApplication by lazy { VimApplicationStub() } | ||||||
|   | |||||||
| @@ -25,7 +25,7 @@ interface VimMotionGroup { | |||||||
|     allowWrap: Boolean = false, |     allowWrap: Boolean = false, | ||||||
|   ): Motion |   ): Motion | ||||||
|  |  | ||||||
|   fun getVerticalMotionOffset(editor: VimEditor, caret: ImmutableVimCaret, count: Int): Motion |   fun getVerticalMotionOffset(editor: VimEditor, caret: ImmutableVimCaret, count: Int, bufferLines: Boolean = false): Motion | ||||||
|  |  | ||||||
| // TODO: Consider naming. These don't move the caret, but calculate offsets. Also consider returning Motion | // TODO: Consider naming. These don't move the caret, but calculate offsets. Also consider returning Motion | ||||||
|  |  | ||||||
|   | |||||||
| @@ -33,14 +33,18 @@ abstract class VimMotionGroupBase : VimMotionGroup { | |||||||
|   override var lastFTCmd: TillCharacterMotionType = TillCharacterMotionType.LAST_SMALL_T |   override var lastFTCmd: TillCharacterMotionType = TillCharacterMotionType.LAST_SMALL_T | ||||||
|   override var lastFTChar: Char = ' ' |   override var lastFTChar: Char = ' ' | ||||||
|  |  | ||||||
|   override fun getVerticalMotionOffset(editor: VimEditor, caret: ImmutableVimCaret, count: Int): Motion { |   override fun getVerticalMotionOffset(editor: VimEditor, caret: ImmutableVimCaret, count: Int, bufferLines: Boolean): Motion { | ||||||
|     val pos = caret.getVisualPosition() |     val pos = caret.getVisualPosition() | ||||||
|     if ((pos.line == 0 && count < 0) || (pos.line >= editor.getVisualLineCount() - 1 && count > 0)) { |     if ((pos.line == 0 && count < 0) || (pos.line >= editor.getVisualLineCount() - 1 && count > 0)) { | ||||||
|       return Motion.Error |       return Motion.Error | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     val intendedColumn = caret.vimLastColumn |     val intendedColumn = caret.vimLastColumn | ||||||
|     val line = editor.normalizeVisualLine(pos.line + count) |     val line = if (bufferLines) | ||||||
|  |       // TODO Does not work with folds, but I don't use those. | ||||||
|  |       editor.normalizeVisualLine(editor.bufferLineToVisualLine(editor.visualLineToBufferLine(pos.line) + count)) | ||||||
|  |     else | ||||||
|  |       editor.normalizeVisualLine(pos.line + count) | ||||||
|  |  | ||||||
|     if (intendedColumn == LAST_COLUMN) { |     if (intendedColumn == LAST_COLUMN) { | ||||||
|       val normalisedColumn = editor.normalizeVisualColumn( |       val normalisedColumn = editor.normalizeVisualColumn( | ||||||
| @@ -396,12 +400,11 @@ abstract class VimMotionGroupBase : VimMotionGroup { | |||||||
|     // If we are a linewise motion we need to normalize the start and stop then move the start to the beginning |     // If we are a linewise motion we need to normalize the start and stop then move the start to the beginning | ||||||
|     // of the line and move the end to the end of the line. |     // of the line and move the end to the end of the line. | ||||||
|     if (argument.isLinewiseMotion()) { |     if (argument.isLinewiseMotion()) { | ||||||
|       if (caret.getBufferPosition().line != editor.lineCount() - 1) { |       start = editor.getLineStartForOffset(start) | ||||||
|         start = editor.getLineStartForOffset(start) |       end = if (caret.getBufferPosition().line != editor.lineCount() - 1) { | ||||||
|         end = min((editor.getLineEndForOffset(end) + 1).toLong(), editor.fileSize()).toInt() |         min((editor.getLineEndForOffset(end) + 1).toLong(), editor.fileSize()).toInt() | ||||||
|       } else { |       } else { | ||||||
|         start = editor.getLineStartForOffset(start) |         editor.getLineEndForOffset(end) | ||||||
|         end = editor.getLineEndForOffset(end) |  | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -206,4 +206,17 @@ interface VimSearchGroup { | |||||||
|    * Returns true if any text is selected in the visible editors, false otherwise. |    * Returns true if any text is selected in the visible editors, false otherwise. | ||||||
|    */ |    */ | ||||||
|   fun isSomeTextHighlighted(): Boolean |   fun isSomeTextHighlighted(): Boolean | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * Sets the last search state purely for tests | ||||||
|  |    * | ||||||
|  |    * @param pattern         The pattern to save. This is the last search pattern, not the last substitute pattern | ||||||
|  |    * @param patternOffset   The pattern offset, e.g. `/{pattern}/{offset}` | ||||||
|  |    * @param direction       The direction to search | ||||||
|  |    */ | ||||||
|  |   fun setLastSearchState( | ||||||
|  |     pattern: String, | ||||||
|  |     patternOffset: String, | ||||||
|  |     direction: Direction, | ||||||
|  |   ) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1425,8 +1425,7 @@ abstract class VimSearchGroupBase : VimSearchGroup { | |||||||
|    * @param patternOffset   The pattern offset, e.g. `/{pattern}/{offset}` |    * @param patternOffset   The pattern offset, e.g. `/{pattern}/{offset}` | ||||||
|    * @param direction       The direction to search |    * @param direction       The direction to search | ||||||
|    */ |    */ | ||||||
|   @TestOnly |   override fun setLastSearchState( | ||||||
|   fun setLastSearchState( |  | ||||||
|     pattern: String, |     pattern: String, | ||||||
|     patternOffset: String, |     patternOffset: String, | ||||||
|     direction: Direction, |     direction: Direction, | ||||||
|   | |||||||
| @@ -53,15 +53,11 @@ sealed class Argument { | |||||||
|  |  | ||||||
|     fun getMotionType() = if (isLinewiseMotion()) SelectionType.LINE_WISE else SelectionType.CHARACTER_WISE |     fun getMotionType() = if (isLinewiseMotion()) SelectionType.LINE_WISE else SelectionType.CHARACTER_WISE | ||||||
|  |  | ||||||
|     fun isLinewiseMotion(): Boolean { |     fun isLinewiseMotion(): Boolean = when (motion) { | ||||||
|       return motion.let { |       is TextObjectActionHandler -> motion.visualType == TextObjectVisualType.LINE_WISE | ||||||
|         when (it) { |       is MotionActionHandler -> motion.motionType == MotionType.LINE_WISE | ||||||
|           is TextObjectActionHandler -> it.visualType == TextObjectVisualType.LINE_WISE |       is ExternalActionHandler -> motion.isLinewiseMotion | ||||||
|           is MotionActionHandler -> it.motionType == MotionType.LINE_WISE |       else -> error("Command is not a motion: $motion") | ||||||
|           is ExternalActionHandler -> it.isLinewiseMotion |  | ||||||
|           else -> error("Command is not a motion: $motion") |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     fun withArgument(argument: Argument) = Motion(motion, argument) |     fun withArgument(argument: Argument) = Motion(motion, argument) | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ package com.maddyhome.idea.vim.common | |||||||
|  |  | ||||||
| interface VimCopiedText { | interface VimCopiedText { | ||||||
|   val text: String |   val text: String | ||||||
|  |   val transferableData: List<Any> | ||||||
|  |  | ||||||
|   // TODO Looks like sticky tape, I'm not sure that we need to modify already stored text |   // TODO Looks like sticky tape, I'm not sure that we need to modify already stored text | ||||||
|   fun updateText(newText: String): VimCopiedText |   fun updateText(newText: String): VimCopiedText | ||||||
|   | |||||||
| @@ -8,7 +8,6 @@ | |||||||
|  |  | ||||||
| package com.maddyhome.idea.vim.common | package com.maddyhome.idea.vim.common | ||||||
|  |  | ||||||
| import com.maddyhome.idea.vim.api.ImmutableVimCaret |  | ||||||
| import com.maddyhome.idea.vim.api.VimEditor | import com.maddyhome.idea.vim.api.VimEditor | ||||||
| import com.maddyhome.idea.vim.api.injector | import com.maddyhome.idea.vim.api.injector | ||||||
| import com.maddyhome.idea.vim.state.mode.Mode | import com.maddyhome.idea.vim.state.mode.Mode | ||||||
| @@ -72,9 +71,9 @@ class VimListenersNotifier { | |||||||
|     isReplaceCharListeners.forEach { it.isReplaceCharChanged(editor) } |     isReplaceCharListeners.forEach { it.isReplaceCharChanged(editor) } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   fun notifyYankPerformed(caretToRange: Map<ImmutableVimCaret, TextRange>) { |   fun notifyYankPerformed(editor: VimEditor, range: TextRange) { | ||||||
|     if (!injector.enabler.isEnabled()) return // we remove all the listeners when turning the plugin off, but let's do it just in case |     if (!injector.enabler.isEnabled()) return // we remove all the listeners when turning the plugin off, but let's do it just in case | ||||||
|     yankListeners.forEach { it.yankPerformed(caretToRange) } |     yankListeners.forEach { it.yankPerformed(editor, range) } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   fun reset() { |   fun reset() { | ||||||
|   | |||||||
| @@ -8,8 +8,8 @@ | |||||||
|  |  | ||||||
| package com.maddyhome.idea.vim.common | package com.maddyhome.idea.vim.common | ||||||
|  |  | ||||||
| import com.maddyhome.idea.vim.api.ImmutableVimCaret | import com.maddyhome.idea.vim.api.VimEditor | ||||||
|  |  | ||||||
| interface VimYankListener { | interface VimYankListener { | ||||||
|   fun yankPerformed(caretToRange: Map<ImmutableVimCaret, TextRange>) |   fun yankPerformed(editor: VimEditor, range: TextRange) | ||||||
| } | } | ||||||
| @@ -13,6 +13,7 @@ import com.maddyhome.idea.vim.api.ImmutableVimCaret | |||||||
| import com.maddyhome.idea.vim.api.VimCaret | import com.maddyhome.idea.vim.api.VimCaret | ||||||
| import com.maddyhome.idea.vim.api.VimCaretListener | import com.maddyhome.idea.vim.api.VimCaretListener | ||||||
| import com.maddyhome.idea.vim.api.VimEditor | 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.api.injector | ||||||
| import com.maddyhome.idea.vim.api.normalizeOffset | import com.maddyhome.idea.vim.api.normalizeOffset | ||||||
| import com.maddyhome.idea.vim.command.Argument | import com.maddyhome.idea.vim.command.Argument | ||||||
| @@ -226,7 +227,15 @@ sealed class MotionActionHandler : EditorActionHandlerBase(false) { | |||||||
|       StrictMode.assert(caret.isPrimary, "Block selection mode must only operate on primary caret") |       StrictMode.assert(caret.isPrimary, "Block selection mode must only operate on primary caret") | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     val normalisedOffset = prepareMoveToAbsoluteOffset(editor, cmd, offset) |     val normalisedOffset = prepareMoveToAbsoluteOffset(editor, cmd, offset).let { | ||||||
|  |       if (offset.intendedColumn == VimMotionGroupBase.LAST_COLUMN) { | ||||||
|  |         val softWrapStart = editor.getSoftWrapStartAtOffset(it) | ||||||
|  |         if (softWrapStart != null) softWrapStart - 1 else it | ||||||
|  |       } | ||||||
|  |       else { | ||||||
|  |         it | ||||||
|  |       } | ||||||
|  |     } | ||||||
|     StrictMode.assert(normalisedOffset == offset.offset, "Adjusted offset should be normalised by action") |     StrictMode.assert(normalisedOffset == offset.offset, "Adjusted offset should be normalised by action") | ||||||
|  |  | ||||||
|     // Set before moving, so it can be applied during move, especially important for LAST_COLUMN and visual block mode |     // Set before moving, so it can be applied during move, especially important for LAST_COLUMN and visual block mode | ||||||
|   | |||||||
| @@ -272,7 +272,11 @@ class ToActionMappingInfo( | |||||||
|  |  | ||||||
|   override fun execute(editor: VimEditor, context: ExecutionContext, keyState: KeyHandlerState) { |   override fun execute(editor: VimEditor, context: ExecutionContext, keyState: KeyHandlerState) { | ||||||
|     LOG.debug("Executing 'ToAction' mapping...") |     LOG.debug("Executing 'ToAction' mapping...") | ||||||
|     injector.actionExecutor.executeAction(editor, name = action, context = context) |     val commandBuilder = KeyHandler.getInstance().keyHandlerState.commandBuilder | ||||||
|  |     for (i in 0 until commandBuilder.calculateCount0Snapshot().coerceAtLeast(1)) { | ||||||
|  |       injector.actionExecutor.executeAction(editor, name = action, context = context) | ||||||
|  |     } | ||||||
|  |     commandBuilder.resetCount() | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   companion object { |   companion object { | ||||||
|   | |||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user