Created
July 30, 2025 09:50
-
-
Save maio/d54594b41626b2f2624a4c84fb62bda6 to your computer and use it in GitHub Desktop.
intellij-find-in-current-file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.intellij.openapi.project.DumbAware | |
| import com.intellij.find.FindManager | |
| import com.intellij.find.FindModel | |
| import com.intellij.openapi.actionSystem.AnAction | |
| import com.intellij.openapi.actionSystem.AnActionEvent | |
| import com.intellij.openapi.actionSystem.CommonDataKeys | |
| import com.intellij.psi.search.GlobalSearchScope | |
| import liveplugin.* | |
| class FindInCurrentFileAction: AnAction("Find in Current File..."), DumbAware { | |
| override fun actionPerformed(event: AnActionEvent) { | |
| show("Project path: ${event.project?.basePath}") | |
| val project = event.project ?: return | |
| val editor = event.getData(CommonDataKeys.EDITOR) ?: return | |
| val file = event.getData(CommonDataKeys.VIRTUAL_FILE) ?: return | |
| val model = FindModel() | |
| model.isProjectScope = false | |
| model.isGlobal = true | |
| model.customScope = GlobalSearchScope.fileScope(project, file) | |
| model.isCustomScope = true | |
| val initialText = editor.selectionModel.selectedText | |
| if (!initialText.isNullOrBlank()) { | |
| model.stringToFind = initialText | |
| } | |
| FindManager.getInstance(project).showFindDialog(model, {}) | |
| } | |
| } | |
| registerAction(id = "Find in Current File...", keyStroke = "ctrl F", action = FindInCurrentFileAction()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment