Skip to content

Commit b28ac49

Browse files
committed
Add new setting maxhlduringincsearch for limiting highlights with incsearch
This can otherwise lead to great slowdown particularly during initial typed letters. Because with incsearch highlighting is triggered and block, this means starting your search will highlight up to thousands of the same character only refined later. With this new setting this skips highlighting (during incsearch only) when above threshold, or keeps old behavior if set to -1.
1 parent 13d858e commit b28ac49

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

src/main/java/com/maddyhome/idea/vim/helper/SearchHighlightsHelper.kt

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ private fun updateSearchHighlights(
107107
&& (currentEditor == null || it.projectId == currentEditor.projectId)
108108
}
109109

110+
val shouldIgnoreCase = pattern == null || shouldIgnoreCase(pattern, shouldIgnoreSmartCase)
111+
112+
var maxhlduringincsearch = injector.globalOptions().maxhlduringincsearch
113+
if (maxhlduringincsearch < 0)
114+
maxhlduringincsearch = Int.MAX_VALUE
115+
110116
editors.forEach {
111117
val editor = it.ij
112118
var currentMatchOffset = -1
@@ -136,13 +142,24 @@ private fun updateSearchHighlights(
136142
pattern,
137143
searchStartLine,
138144
searchEndLine,
139-
shouldIgnoreCase(pattern, shouldIgnoreSmartCase)
145+
shouldIgnoreCase
140146
)
141147
if (results.isNotEmpty()) {
142-
if (editor === currentEditor?.ij) {
143-
currentMatchOffset = findClosestMatch(results, initialOffset, count1, forwards)
148+
// Only in incsearch is current editor not null, then check result size
149+
val showHighlightsInEditor = currentEditor == null || results.size < maxhlduringincsearch
150+
if (editor == currentEditor?.ij) {
151+
val currentMatchIndex = findClosestMatch(results, initialOffset, count1, forwards)
152+
currentMatchOffset = if (currentMatchIndex == -1) -1 else results[currentMatchIndex].startOffset
153+
154+
if (!showHighlightsInEditor) {
155+
// Always highlight at least the "current" match in the active editor
156+
highlightSearchResults(editor, pattern, listOf(results[currentMatchIndex]), currentMatchOffset)
157+
}
158+
}
159+
160+
if (showHighlightsInEditor) {
161+
highlightSearchResults(editor, pattern, results, currentMatchOffset)
144162
}
145-
highlightSearchResults(editor, pattern, results, currentMatchOffset)
146163
}
147164
}
148165
editor.vimLastSearch = pattern
@@ -237,7 +254,7 @@ private fun findClosestMatch(
237254
return -1
238255
}
239256

240-
return sortedResults[nextIndex % results.size].startOffset
257+
return nextIndex % results.size
241258
}
242259

243260
internal fun highlightSearchResults(

src/main/resources/dictionaries/ideavim.dic

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ keymodel
2323
lookupKeys
2424
mapleader
2525
matchpairs
26+
maxhlduringincsearch
2627
maxmapdepth
2728
nrformats
2829
operatorfunc

vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/OptionProperties.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ open class GlobalOptions(scope: OptionAccessScope) : OptionsPropertiesBase(scope
5050
var wrapscan: Boolean by optionProperty(Options.wrapscan)
5151

5252
// IdeaVim specific options. Put any editor or IDE specific options in IjOptionProperties
53+
var maxhlduringincsearch: Int by optionProperty(Options.maxhlduringincsearch)
5354

5455
// Temporary flags for work-in-progress behaviour. Hidden from the output of `:set all`
5556
var ideastrictmode: Boolean by optionProperty(Options.ideastrictmode)

vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/Options.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ object Options {
136136
)
137137
)
138138
)
139+
val maxhlduringincsearch: NumberOption = addOption(NumberOption(name="maxhlduringincsearch", GLOBAL, "maxhld", 100, -1))
139140
val maxmapdepth: NumberOption = addOption(NumberOption("maxmapdepth", GLOBAL, "mmd", 20))
140141
val more: ToggleOption = addOption(ToggleOption("more", GLOBAL, "more", true))
141142
val nrformats: StringListOption = addOption(

0 commit comments

Comments
 (0)