[performance-plugin] AT-86 make GoToAnyPsiElement go forward in file

GitOrigin-RevId: f232e6a379a9b37b342fd5e51f8c0966dc6076ae
This commit is contained in:
roman.ivanitskii
2022-11-08 13:34:34 +02:00
committed by intellij-monorepo-bot
parent ff74483fba
commit 21e8b188d9
2 changed files with 13 additions and 10 deletions

View File

@@ -67,7 +67,7 @@ public final class BaseCommandProvider implements CommandProvider {
Map.entry(OpenRandomFileCommand.PREFIX, OpenRandomFileCommand::new),
Map.entry(PressEnterKeyCommand.PREFIX, PressEnterKeyCommand::new),
Map.entry(WaitForDumbCommand.PREFIX, WaitForDumbCommand::new),
Map.entry(GoToAnyPsiElement.PREFIX, GoToAnyPsiElement::new)
Map.entry(GoToNextPsiElement.PREFIX, GoToNextPsiElement::new)
);
}
}

View File

@@ -20,9 +20,9 @@ import org.jetbrains.concurrency.toPromise
import kotlin.math.max
import kotlin.math.min
class GoToAnyPsiElement(text: String, line: Int) : AbstractCommand(text, line) {
class GoToNextPsiElement(text: String, line: Int) : AbstractCommand(text, line) {
companion object {
const val PREFIX: @NonNls String = CMD_PREFIX + "goToAnyPsiElement"
const val PREFIX: @NonNls String = CMD_PREFIX + "goToNextPsiElement"
const val SUPPRESS_ERROR_IF_NOT_FOUND: @NonNls String = "SUPPRESS_ERROR_IF_NOT_FOUND"
val REGEX = " ".toRegex()
}
@@ -45,14 +45,17 @@ class GoToAnyPsiElement(text: String, line: Int) : AbstractCommand(text, line) {
psiFile?.accept(object : PsiRecursiveElementWalkingVisitor(true) {
override fun visitElement(element: PsiElement) {
if (params.contains(element.elementType?.debugName)) {
val spaceIndex = max(1, element.text.indexOf(" "))
val offset = min(element.endOffset, element.startOffset + spaceIndex)
if (editor.caretModel.offset == offset) {
actionCallback.setDone()
} else {
editor.caretModel.moveToOffset(offset)
if (editor.caretModel.currentCaret.offset < element.startOffset) {
val spaceIndex = max(1, element.text.indexOf(" "))
val offset = min(element.endOffset, element.startOffset + spaceIndex)
if (editor.caretModel.offset == offset) {
actionCallback.setDone()
}
else {
editor.caretModel.moveToOffset(offset)
}
stopWalking()
}
stopWalking()
}
super.visitElement(element)
}