1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-06-02 22:34:08 +02:00

Fix regression ignoring case in global command

Regression in new regex engine
This commit is contained in:
Matt Ellis 2024-06-06 00:44:07 +01:00 committed by Alex Pláte
parent 79653b6048
commit f1b94d7026
2 changed files with 40 additions and 3 deletions
src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/vimscript/model/commands

View File

@ -11,7 +11,6 @@ package org.jetbrains.plugins.ideavim.ex.implementation.commands
import com.intellij.idea.TestFor import com.intellij.idea.TestFor
import com.maddyhome.idea.vim.VimPlugin import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.history.HistoryConstants import com.maddyhome.idea.vim.history.HistoryConstants
import com.maddyhome.idea.vim.state.mode.Mode
import org.jetbrains.plugins.ideavim.SkipNeovimReason import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase import org.jetbrains.plugins.ideavim.VimTestCase
@ -204,6 +203,36 @@ class GlobalCommandTest : VimTestCase() {
) )
} }
@Test
fun `test match ignores case`() {
doTest(
exCommand("g/test/p"),
"""
|one test
|two
|three Test
|four
|five TEST
""".trimMargin(),
"""
|one test
|two
|three Test
|four
|five TEST
""".trimMargin()
) {
enterCommand("set ignorecase")
}
assertExOutput(
"""
|one test
|three Test
|five TEST
""".trimMargin()
)
}
@Test @Test
fun `test check history`() { fun `test check history`() {
VimPlugin.getHistory().clear() VimPlugin.getHistory().clear()
@ -335,6 +364,6 @@ end
} }
private fun doTest(command: String, before: String, after: String) { private fun doTest(command: String, before: String, after: String) {
doTest(listOf(exCommand(command)), before, after, Mode.NORMAL()) doTest(listOf(exCommand(command)), before, after)
} }
} }

View File

@ -13,11 +13,14 @@ import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.VimRangeMarker import com.maddyhome.idea.vim.api.VimRangeMarker
import com.maddyhome.idea.vim.api.VimSearchGroupBase import com.maddyhome.idea.vim.api.VimSearchGroupBase
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.command.OperatorArguments import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.ex.ranges.LineRange import com.maddyhome.idea.vim.ex.ranges.LineRange
import com.maddyhome.idea.vim.ex.ranges.Range import com.maddyhome.idea.vim.ex.ranges.Range
import com.maddyhome.idea.vim.helper.enumSetOf
import com.maddyhome.idea.vim.regexp.VimRegexException import com.maddyhome.idea.vim.regexp.VimRegexException
import com.maddyhome.idea.vim.regexp.VimRegexOptions
import com.maddyhome.idea.vim.regexp.match.VimMatchResult import com.maddyhome.idea.vim.regexp.match.VimMatchResult
import com.maddyhome.idea.vim.vimscript.model.ExecutionResult import com.maddyhome.idea.vim.vimscript.model.ExecutionResult
@ -70,8 +73,12 @@ public data class GlobalCommand(val range: Range, val argument: String, val inve
return false return false
} }
val options = enumSetOf<VimRegexOptions>()
if (injector.globalOptions().smartcase) options.add(VimRegexOptions.SMART_CASE)
if (injector.globalOptions().ignorecase) options.add(VimRegexOptions.IGNORE_CASE)
if (globalBusy) { if (globalBusy) {
val match = regex.findInLine(editor, editor.currentCaret().getLine()) val match = regex.findInLine(editor, editor.currentCaret().getLine(), 0, options)
if (match is VimMatchResult.Success == !invert) { if (match is VimMatchResult.Success == !invert) {
globalExecuteOne(editor, context, editor.getLineStartOffset(editor.currentCaret().getLine()), globalCommandArguments.command) globalExecuteOne(editor, context, editor.getLineStartOffset(editor.currentCaret().getLine()), globalCommandArguments.command)
} }
@ -85,6 +92,7 @@ public data class GlobalCommand(val range: Range, val argument: String, val inve
editor, editor,
editor.getLineStartOffset(line1), editor.getLineStartOffset(line1),
editor.getLineEndOffset(line2), editor.getLineEndOffset(line2),
options,
) )
val matchesLines = matches.map { it.getLine(editor) }.toSet() val matchesLines = matches.map { it.getLine(editor) }.toSet()
val linesForGlobalCommand = if (invert) { val linesForGlobalCommand = if (invert) {