Skip to content

Commit

Permalink
Fix(VIM-3517): Add support for global find & replace Vim-ism — :g/pat…
Browse files Browse the repository at this point in the history
…tern/s//replacement/g
  • Loading branch information
lippfi committed Jul 3, 2024
1 parent afceeca commit 10228f9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,40 @@ end
)
}

@Test
@TestFor(issues = ["VIM-3517"])
fun `test global used as a creative substitute alternative`() {
val textBefore = """
aaa bbb ccc aaa aaa
bbbbbb
bbbbbb
aaa bbb ccc aaa aaa aaa aaa aaa
bbbbbb
bbbbbb
bbbbbb
bbbbbb
bbbbbb
end
""".trimIndent()
val textAfter = """
replacement bbb ccc replacement replacement
bbbbbb
bbbbbb
replacement bbb ccc replacement replacement replacement replacement replacement
bbbbbb
bbbbbb
bbbbbb
bbbbbb
bbbbbb
end
""".trimIndent()
configureByText(textBefore)
typeText(commandToKeys(":g/aaa"))
assertState(textBefore)
typeText(commandToKeys(":g//s//replacement/g"))
assertState(textAfter)
}

private fun doTest(command: String, before: String, after: String) {
doTest(listOf(exCommand(command)), before, after)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ interface VimSearchGroup {

fun findDecimalNumber(line: String): Int?

fun updateSearchHighlightsAfterGlobalCommand()

/**
* Clears all search highlights.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ abstract class VimSearchGroupBase : VimSearchGroup {
*/
abstract fun resetIncsearchHighlights()

override fun updateSearchHighlightsAfterGlobalCommand() {
setShouldShowSearchHighlights()
updateSearchHighlights(false)
}

/**
* Asks the user how to deal with a substitution confirmation choice.
* Used when the 'c' flag is present in a substitute command.
Expand Down Expand Up @@ -258,7 +263,7 @@ abstract class VimSearchGroupBase : VimSearchGroup {
}
setLastUsedPattern(pattern, patSave, isNewPattern)

return VimRegex(pat.toString())
return VimRegex(pattern)
}

// TODO I think that this method (and the method above) should be part of the global command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ data class GlobalCommand(val range: Range, val argument: String, val invert: Boo
globalExe(editor, context, marks, globalCommandArguments.command)
}
}
injector.searchGroup.updateSearchHighlightsAfterGlobalCommand()
return true
}

Expand Down

0 comments on commit 10228f9

Please sign in to comment.