mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-02-24 08:46:00 +01:00
Restore current match highlighting for :s command
Regression while migrating to the new regex engine removed the highlights shown when confirming each change
This commit is contained in:
parent
ffce61906a
commit
bfe0f51cb1
src/main/java/com/maddyhome/idea/vim/newapi
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api
@ -9,6 +9,8 @@
|
||||
package com.maddyhome.idea.vim.newapi
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.markup.RangeHighlighter
|
||||
import com.intellij.openapi.util.Ref
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
@ -135,13 +137,19 @@ public open class IjVimSearchGroup : VimSearchGroupBase() {
|
||||
return result.get()
|
||||
}
|
||||
|
||||
override fun addSubstitutionConfirmationHighlight(editor: VimEditor, startOffset: Int, endOffset: Int) {
|
||||
val hl = addSubstitutionConfirmationHighlight(
|
||||
(editor as IjVimEditor).editor,
|
||||
override fun addSubstitutionConfirmationHighlight(
|
||||
editor: VimEditor,
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
): SearchHighlight {
|
||||
|
||||
val ijEditor = (editor as IjVimEditor).editor
|
||||
val highlighter = addSubstitutionConfirmationHighlight(
|
||||
ijEditor,
|
||||
startOffset,
|
||||
endOffset
|
||||
)
|
||||
editor.editor.markupModel.removeHighlighter(hl)
|
||||
return IjSearchHighlight(ijEditor, highlighter)
|
||||
}
|
||||
|
||||
override fun setLatestMatch(match: String) {
|
||||
@ -173,4 +181,12 @@ public open class IjVimSearchGroup : VimSearchGroupBase() {
|
||||
showSearchHighlight = false
|
||||
updateSearchHighlights(false)
|
||||
}
|
||||
}
|
||||
|
||||
private class IjSearchHighlight(private val editor: Editor, private val highlighter: RangeHighlighter) :
|
||||
SearchHighlight() {
|
||||
|
||||
override fun remove() {
|
||||
editor.markupModel.removeHighlighter(highlighter)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,9 +99,7 @@ public abstract class VimSearchGroupBase : VimSearchGroup {
|
||||
*
|
||||
* @param force Whether to force this update.
|
||||
*/
|
||||
protected abstract fun updateSearchHighlights(
|
||||
force: Boolean,
|
||||
)
|
||||
protected abstract fun updateSearchHighlights(force: Boolean)
|
||||
|
||||
/**
|
||||
* Reset the search highlights to the last used pattern after highlighting incsearch results.
|
||||
@ -137,7 +135,7 @@ public abstract class VimSearchGroupBase : VimSearchGroup {
|
||||
editor: VimEditor,
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
)
|
||||
) : SearchHighlight
|
||||
|
||||
/**
|
||||
* Saves the latest matched string, for Vimscript purposes.
|
||||
@ -613,8 +611,7 @@ public abstract class VimSearchGroupBase : VimSearchGroup {
|
||||
if (doAll || line != editor.lineCount()) {
|
||||
var doReplace = true
|
||||
if (doAsk) {
|
||||
addSubstitutionConfirmationHighlight(editor, matchRange.startOffset, matchRange.endOffset)
|
||||
|
||||
val highlight = addSubstitutionConfirmationHighlight(editor, matchRange.startOffset, matchRange.endOffset)
|
||||
val choice: ReplaceConfirmationChoice = confirmChoice(editor, context, match, caret, matchRange.startOffset)
|
||||
when (choice) {
|
||||
ReplaceConfirmationChoice.SUBSTITUTE_THIS -> {}
|
||||
@ -630,6 +627,7 @@ public abstract class VimSearchGroupBase : VimSearchGroup {
|
||||
line2 = line
|
||||
}
|
||||
}
|
||||
highlight.remove()
|
||||
}
|
||||
if (doReplace) {
|
||||
setLatestMatch(editor.getText(TextRange(matchRange.startOffset, matchRange.endOffset)))
|
||||
@ -1043,7 +1041,7 @@ public abstract class VimSearchGroupBase : VimSearchGroup {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last search state, purely for tests
|
||||
* Sets the last search state purely for tests
|
||||
*
|
||||
* @param pattern The pattern to save. This is the last search pattern, not the last substitute pattern
|
||||
* @param patternOffset The pattern offset, e.g. `/{pattern}/{offset}`
|
||||
@ -1075,6 +1073,10 @@ public abstract class VimSearchGroupBase : VimSearchGroup {
|
||||
}
|
||||
|
||||
|
||||
protected abstract class SearchHighlight {
|
||||
public abstract fun remove()
|
||||
}
|
||||
|
||||
protected enum class PatternType {
|
||||
SEARCH,
|
||||
SUBSTITUTE,
|
||||
@ -1093,4 +1095,4 @@ private data class SubstituteCommandArguments(
|
||||
val pattern: String,
|
||||
val substituteString: String,
|
||||
val range: LineRange,
|
||||
)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user