mirror of
				https://github.com/chylex/IntelliJ-IdeaVim.git
				synced 2025-10-31 11:17:13 +01:00 
			
		
		
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			edb9b194bb
			...
			VIM-2227
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| f2b532a8dc | 
| @@ -122,21 +122,26 @@ class VimSurroundExtension : VimExtension { | |||||||
|       fun change(editor: Editor, charFrom: Char, newSurround: Pair<String, String>?) { |       fun change(editor: Editor, charFrom: Char, newSurround: Pair<String, String>?) { | ||||||
|         // We take over the " register, so preserve it |         // We take over the " register, so preserve it | ||||||
|         val oldValue: List<KeyStroke>? = getRegister(REGISTER) |         val oldValue: List<KeyStroke>? = getRegister(REGISTER) | ||||||
|  |         // Empty the " register | ||||||
|  |         setRegister(REGISTER, null) | ||||||
|         // Extract the inner value |         // Extract the inner value | ||||||
|         perform("di" + pick(charFrom), editor) |         perform("di" + pick(charFrom), editor) | ||||||
|         val innerValue: MutableList<KeyStroke> = getRegister(REGISTER)?.toMutableList() ?: mutableListOf() |         val innerValue: MutableList<KeyStroke> = getRegister(REGISTER)?.toMutableList() ?: mutableListOf() | ||||||
|         // Delete the surrounding |         // If the surrounding characters were not found, the register will be empty | ||||||
|         perform("da" + pick(charFrom), editor) |         if (innerValue.isNotEmpty()) { | ||||||
|         // Insert the surrounding characters and paste |           // Delete the surrounding | ||||||
|         if (newSurround != null) { |           perform("da" + pick(charFrom), editor) | ||||||
|           innerValue.addAll(0, injector.parser.parseKeys(newSurround.first)) |           // Insert the surrounding characters and paste | ||||||
|           innerValue.addAll(injector.parser.parseKeys(newSurround.second)) |           if (newSurround != null) { | ||||||
|  |             innerValue.addAll(0, injector.parser.parseKeys(newSurround.first)) | ||||||
|  |             innerValue.addAll(injector.parser.parseKeys(newSurround.second)) | ||||||
|  |           } | ||||||
|  |           pasteSurround(innerValue, editor) | ||||||
|  |           // Jump back to start | ||||||
|  |           executeNormalWithoutMapping(injector.parser.parseKeys("`["), editor) | ||||||
|         } |         } | ||||||
|         pasteSurround(innerValue, editor) |  | ||||||
|         // Restore the old value |         // Restore the old value | ||||||
|         setRegister(REGISTER, oldValue) |         setRegister(REGISTER, oldValue) | ||||||
|         // Jump back to start |  | ||||||
|         executeNormalWithoutMapping(injector.parser.parseKeys("`["), editor) |  | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       private fun perform(sequence: String, editor: Editor) { |       private fun perform(sequence: String, editor: Editor) { | ||||||
|   | |||||||
| @@ -313,6 +313,17 @@ class VimSurroundExtensionTest : VimTestCase() { | |||||||
|     doTest(listOf("dsb"), before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE) |     doTest(listOf("dsb"), before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   // VIM-2227 | ||||||
|  |   @TestWithoutNeovim(SkipNeovimReason.PLUGIN) | ||||||
|  |   fun testDeleteInvalidSurroundingCharacter() { | ||||||
|  |     val text = "if (${c}condition) {" | ||||||
|  |      | ||||||
|  |     doTest("yibds]", text, text, CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||||||
|  |     doTest("yibds[", text, text, CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||||||
|  |     doTest("yibds}", text, text, CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||||||
|  |     doTest("yibds{", text, text, CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||||||
|  |   } | ||||||
|  |  | ||||||
|   @TestWithoutNeovim(SkipNeovimReason.PLUGIN) |   @TestWithoutNeovim(SkipNeovimReason.PLUGIN) | ||||||
|   fun testRepeatDeleteSurroundParens() { |   fun testRepeatDeleteSurroundParens() { | ||||||
|     val before = "if ((${c}condition)) {\n}\n" |     val before = "if ((${c}condition)) {\n}\n" | ||||||
| @@ -371,6 +382,17 @@ class VimSurroundExtensionTest : VimTestCase() { | |||||||
|     doTest(listOf("csbrE."), before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE) |     doTest(listOf("csbrE."), before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   // VIM-2227 | ||||||
|  |   @TestWithoutNeovim(SkipNeovimReason.PLUGIN) | ||||||
|  |   fun testChangeInvalidSurroundingCharacter() { | ||||||
|  |     val text = "if (${c}condition) {" | ||||||
|  |  | ||||||
|  |     doTest("yibcs]}", text, text, CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||||||
|  |     doTest("yibcs[}", text, text, CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||||||
|  |     doTest("yibcs}]", text, text, CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||||||
|  |     doTest("yibcs{]", text, text, CommandState.Mode.COMMAND, CommandState.SubMode.NONE) | ||||||
|  |   } | ||||||
|  |  | ||||||
|   @VimBehaviorDiffers( |   @VimBehaviorDiffers( | ||||||
|     """ |     """ | ||||||
|       <h1>Title</h1> |       <h1>Title</h1> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user