Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared tests #981

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Move more logic to vim-engine
  • Loading branch information
lippfi committed Aug 30, 2024
commit c91ea73c5fd1ad3eefe8f25a3a71019c708279fc
23 changes: 0 additions & 23 deletions src/main/java/com/maddyhome/idea/vim/newapi/IjVimSearchGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,25 @@ import com.intellij.openapi.editor.event.DocumentEvent
import com.intellij.openapi.editor.event.DocumentListener
import com.intellij.openapi.editor.markup.RangeHighlighter
import com.intellij.openapi.fileEditor.FileEditorManagerEvent
import com.intellij.openapi.util.Ref
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.Options
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
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.common.Direction
import com.maddyhome.idea.vim.common.Direction.Companion.fromInt
import com.maddyhome.idea.vim.diagnostic.vimLogger
import com.maddyhome.idea.vim.helper.MessageHelper
import com.maddyhome.idea.vim.helper.TestInputModel.Companion.getInstance
import com.maddyhome.idea.vim.helper.addSubstitutionConfirmationHighlight
import com.maddyhome.idea.vim.helper.highlightSearchResults
import com.maddyhome.idea.vim.helper.isCloseKeyStroke
import com.maddyhome.idea.vim.helper.shouldIgnoreCase
import com.maddyhome.idea.vim.helper.updateSearchHighlights
import com.maddyhome.idea.vim.helper.vimLastHighlighters
import com.maddyhome.idea.vim.options.GlobalOptionChangeListener
import com.maddyhome.idea.vim.ui.ModalEntry
import com.maddyhome.idea.vim.vimscript.model.functions.handlers.SubmatchFunctionHandler
import org.jdom.Element
import org.jetbrains.annotations.Contract
import org.jetbrains.annotations.TestOnly
import javax.swing.KeyStroke

@State(
name = "VimSearchSettings",
Expand Down Expand Up @@ -112,21 +104,6 @@ open class IjVimSearchGroup : VimSearchGroupBase(), PersistentStateComponent<Ele
return IjSearchHighlight(ijEditor, highlighter)
}

override fun setLatestMatch(match: String) {
SubmatchFunctionHandler.getInstance().latestMatch = match
}

override fun replaceString(
editor: VimEditor,
startOffset: Int,
endOffset: Int,
newString: String,
) {
ApplicationManager.getApplication().runWriteAction {
(editor as IjVimEditor).editor.document.replaceString(startOffset, endOffset, newString)
}
}

@TestOnly
override fun resetState() {
super.resetState()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"col": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.ColFunctionHandler",
"has": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.HasFunctionHandler",
"line": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.LineFunctionHandler",
"submatch": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.SubmatchFunctionHandler"
"line": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.LineFunctionHandler"
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.maddyhome.idea.vim.regexp.match.VimMatchResult
import com.maddyhome.idea.vim.register.RegisterConstants
import com.maddyhome.idea.vim.state.mode.inVisualMode
import com.maddyhome.idea.vim.vimscript.model.VimLContext
import com.maddyhome.idea.vim.vimscript.model.functions.handlers.SubmatchFunctionHandler
import org.jetbrains.annotations.TestOnly
import java.text.NumberFormat
import java.text.ParsePosition
Expand Down Expand Up @@ -137,24 +138,9 @@ abstract class VimSearchGroupBase : VimSearchGroup {
*
* @param match The match to save.
*/
protected abstract fun setLatestMatch(
match: String,
)

/**
* Replaces a string in the editor.
*
* @param editor The editor where the replacement is to take place.
* @param startOffset The offset where the string that is to be replaced starts (inclusive).
* @param endOffset The offset where the string that is to be replaced ends (exclusive).
* @param newString The new string that will replace the old one.
*/
protected abstract fun replaceString(
editor: VimEditor,
startOffset: Int,
endOffset: Int,
newString: String,
)
protected open fun setLatestMatch(match: String) {
SubmatchFunctionHandler.getInstance().latestMatch = match
}

/**
* Resets the variable that determines whether search highlights should be shown.
Expand Down Expand Up @@ -814,7 +800,9 @@ abstract class VimSearchGroupBase : VimSearchGroup {
if (doReplace) {
val endPositionWithoutReplace = editor.offsetToBufferPosition(matchRange.endOffset)

replaceString(editor, matchRange.startOffset, matchRange.endOffset, finalMatch)
injector.application.runWriteAction {
(editor as MutableVimEditor).replaceString(matchRange.startOffset, matchRange.endOffset, finalMatch)
}
didReplace = true

val endPositionWithReplace = editor.offsetToBufferPosition(matchRange.startOffset + finalMatch.length)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2023 The IdeaVim authors
* Copyright 2003-2024 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
Expand All @@ -20,7 +20,7 @@ import com.maddyhome.idea.vim.vimscript.model.expressions.Expression
import com.maddyhome.idea.vim.vimscript.model.functions.FunctionHandler

@VimscriptFunction(name = "submatch")
internal class SubmatchFunctionHandler : FunctionHandler() {
class SubmatchFunctionHandler : FunctionHandler() {
override val minimumNumberOfArguments = 1
override val maximumNumberOfArguments = 2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"len": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.LenFunctionHandler",
"sin": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.SinFunctionHandler",
"split": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.SplitFunctionHandler",
"submatch": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.SubmatchFunctionHandler",
"tolower": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.TolowerFunctionHandler",
"toupper": "com.maddyhome.idea.vim.vimscript.model.functions.handlers.ToupperFunctionHandler"
}