mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-05-02 19:34:04 +02:00
Disable incsearch highlight in Visual mode
This commit is contained in:
parent
ed6789cb8b
commit
1f68b756d5
src
main/java/com/maddyhome/idea/vim/helper
test/java/org/jetbrains/plugins/ideavim/group/search
testFixtures/kotlin/org/jetbrains/plugins/ideavim
@ -25,6 +25,8 @@ import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.ex.ranges.LineRange
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.state.mode.inCommandLineModeWithVisual
|
||||
import com.maddyhome.idea.vim.state.mode.inVisualMode
|
||||
import org.jetbrains.annotations.Contract
|
||||
import java.awt.Font
|
||||
import java.util.*
|
||||
@ -145,7 +147,10 @@ private fun updateSearchHighlights(
|
||||
}
|
||||
editor.vimLastSearch = pattern
|
||||
} else if (shouldAddCurrentMatchSearchHighlight(pattern, showHighlights, initialOffset)) {
|
||||
// nohlsearch + incsearch. Only highlight the 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
|
||||
// course), because the Visual selection is enough. We still need to find the current offset to update the
|
||||
// selection
|
||||
if (editor === currentEditor?.ij) {
|
||||
val searchOptions = EnumSet.of(SearchOptions.WHOLE_FILE)
|
||||
if (injector.globalOptions().wrapscan) searchOptions.add(SearchOptions.WRAP)
|
||||
@ -153,8 +158,10 @@ private fun updateSearchHighlights(
|
||||
if (!forwards) searchOptions.add(SearchOptions.BACKWARDS)
|
||||
val result = injector.searchHelper.findPattern(it, pattern, initialOffset, count1, searchOptions)
|
||||
if (result != null) {
|
||||
val results = listOf(result)
|
||||
highlightSearchResults(editor, pattern, results, result.startOffset)
|
||||
if (!it.inVisualMode && !it.inCommandLineModeWithVisual) {
|
||||
val results = listOf(result)
|
||||
highlightSearchResults(editor, pattern, results, result.startOffset)
|
||||
}
|
||||
currentMatchOffset = result.startOffset
|
||||
}
|
||||
}
|
||||
|
@ -622,6 +622,55 @@ class IncsearchTests : VimTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test incsearch updates Visual selection but not highlights with nohlsearch`() {
|
||||
// We don't show a highlight when nohlsearch is active and we're in Visual - the selection is enough
|
||||
doTest(
|
||||
listOf("ve", "/dolor"),
|
||||
"""
|
||||
|Lorem ipsum dolor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin(),
|
||||
"""
|
||||
|${s}Lorem ipsum ${c}d${se}olor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin(),
|
||||
Mode.CMD_LINE(Mode.VISUAL(SelectionType.CHARACTER_WISE))
|
||||
) {
|
||||
enterCommand("set nohlsearch")
|
||||
enterCommand("set incsearch")
|
||||
}
|
||||
assertNoSearchHighlights()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test incsearch updates empty Visual selection but not highlights with nohlsearch`() {
|
||||
doTest(
|
||||
"v/ipsum",
|
||||
"""
|
||||
|Lorem ipsum dolor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin(),
|
||||
"""
|
||||
|${s}Lorem ${c}i${se}psum dolor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin(),
|
||||
Mode.CMD_LINE(Mode.VISUAL(SelectionType.CHARACTER_WISE))
|
||||
) {
|
||||
enterCommand("set nohlsearch")
|
||||
enterCommand("set incsearch")
|
||||
}
|
||||
assertNoSearchHighlights()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test incsearch updates exclusive Visual selection`() {
|
||||
doTest(
|
||||
@ -684,6 +733,56 @@ class IncsearchTests : VimTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test incsearch updates exclusive Visual selection but not highlights with nohlsearch`() {
|
||||
doTest(
|
||||
listOf("ve", "/dolor"),
|
||||
"""
|
||||
|Lorem ipsum dolor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin(),
|
||||
"""
|
||||
|${s}Lorem ipsum ${c}${se}dolor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin(),
|
||||
Mode.CMD_LINE(Mode.VISUAL(SelectionType.CHARACTER_WISE))
|
||||
) {
|
||||
enterCommand("set selection=exclusive")
|
||||
enterCommand("set nohlsearch")
|
||||
enterCommand("set incsearch")
|
||||
}
|
||||
assertNoSearchHighlights()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test incsearch updates empty exclusive Visual selection but not highlights with nohlsearch`() {
|
||||
doTest(
|
||||
"v/ipsum",
|
||||
"""
|
||||
|Lorem ipsum dolor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin(),
|
||||
"""
|
||||
|${s}Lorem ${c}${se}ipsum dolor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin(),
|
||||
Mode.CMD_LINE(Mode.VISUAL(SelectionType.CHARACTER_WISE))
|
||||
) {
|
||||
enterCommand("set selection=exclusive")
|
||||
enterCommand("set nohlseach")
|
||||
enterCommand("set incsearch")
|
||||
}
|
||||
assertNoSearchHighlights()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test incsearch updates selection when editing search pattern`() {
|
||||
// This will initially move selection to the "it" in "sit" on the first line, then back to the start of "ipsum".
|
||||
@ -748,6 +847,32 @@ class IncsearchTests : VimTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test incsearch updates empty selection when editing search pattern with nohlsearch`() {
|
||||
// This will initially move selection to the "it" in "sit" on the first line, then back to the start of "ipsum".
|
||||
// Tests that the selection is correctly updated as the current target changes
|
||||
doTest(
|
||||
listOf("v", "/it", "<BS>", "p"),
|
||||
"""
|
||||
|Lorem ipsum dolor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin(),
|
||||
"""
|
||||
|${s}Lorem ${c}i${se}psum dolor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin(),
|
||||
Mode.CMD_LINE(Mode.VISUAL(SelectionType.CHARACTER_WISE))
|
||||
) {
|
||||
enterCommand("set nohlsearch")
|
||||
enterCommand("set incsearch")
|
||||
}
|
||||
assertNoSearchHighlights()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test incsearch updates exclusive selection when editing search pattern`() {
|
||||
// This will initially move selection to the "it" in "sit" on the first line, then back to the start of "ipsum".
|
||||
@ -814,6 +939,33 @@ class IncsearchTests : VimTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test incsearch updates empty exclusive selection when editing search pattern with nohlsearch`() {
|
||||
// This will initially move selection to the "it" in "sit" on the first line, then back to the start of "ipsum".
|
||||
// Tests that the selection is correctly updated as the current target changes
|
||||
doTest(
|
||||
listOf("v", "/it", "<BS>", "p"),
|
||||
"""
|
||||
|Lorem ipsum dolor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin(),
|
||||
"""
|
||||
|${s}Lorem ${c}${se}ipsum dolor sit amet,
|
||||
|consectetur adipiscing elit
|
||||
|Sed in orci mauris.
|
||||
|Cras id tellus in ex imperdiet egestas.
|
||||
""".trimMargin(),
|
||||
Mode.CMD_LINE(Mode.VISUAL(SelectionType.CHARACTER_WISE))
|
||||
) {
|
||||
enterCommand("set selection=exclusive")
|
||||
enterCommand("set nohlsearch")
|
||||
enterCommand("set incsearch")
|
||||
}
|
||||
assertNoSearchHighlights()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test incsearch updates block selection when started in Visual mode`() {
|
||||
doTest(
|
||||
|
@ -10,7 +10,6 @@ package org.jetbrains.plugins.ideavim.group.search
|
||||
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class SearchHighlightsTest : VimTestCase() {
|
||||
@Test
|
||||
@ -520,8 +519,4 @@ class SearchHighlightsTest : VimTestCase() {
|
||||
enterSearch(pattern)
|
||||
assertSearchHighlights(pattern, "\t«foo»")
|
||||
}
|
||||
|
||||
private fun assertNoSearchHighlights() {
|
||||
assertEquals(0, fixture.editor.markupModel.allHighlighters.size)
|
||||
}
|
||||
}
|
||||
|
@ -842,6 +842,10 @@ abstract class VimNoWriteActionTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
protected fun assertNoSearchHighlights() {
|
||||
assertEquals(0, fixture.editor.markupModel.allHighlighters.size)
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun doTest(
|
||||
keys: List<String>,
|
||||
|
Loading…
Reference in New Issue
Block a user