Skip to content

Commit

Permalink
⚗️ Fix bug with not selecting all code in editors
Browse files Browse the repository at this point in the history
  • Loading branch information
sloppylopez committed Nov 28, 2024
1 parent 1f92e00 commit 19aada3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.OpenFileDescriptor
import com.intellij.openapi.fileEditor.TextEditor
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.ui.Messages
Expand Down Expand Up @@ -185,6 +186,28 @@ class ProjectService {
}
}

fun highlightTextInAllEditors(contentPromptText: String) {
val editors = getAllOpenEditors() // New helper function to get all editors
val normalizedContentPromptText = contentPromptText.replace("\r\n", "\n")

editors.forEach { editor ->
val document = editor.document
val textOffset = document.text.indexOf(normalizedContentPromptText)
if (textOffset != -1) {
editor.caretModel.moveToOffset(textOffset)
editor.selectionModel.setSelection(textOffset, textOffset + normalizedContentPromptText.length)
}
}
}

// Helper function to get all open editors in the project
private fun getAllOpenEditors(): List<Editor> {
val fileEditorManager = FileEditorManager.getInstance(this.getProject()!!)
return fileEditorManager.allEditors.mapNotNull { editor ->
(editor as? TextEditor)?.editor
}
}

private fun getCurrentEditor(): Editor? {
val project = this.getProject()!!
val file = FileEditorManager.getInstance(project)?.selectedFiles?.firstOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ class PromptPanelFactory(project: Project) : DropTargetAdapter() {
val project = service.getProject()
val expandedFileList = service.expandFolders(fileList)
addTabbedPaneToToolWindow(project!!, expandedFileList)
expandedFileList.forEach {
val fileContents = String(Files.readAllBytes(File(it.path).toPath()))
service.highlightTextInEditor(fileContents)
expandedFileList.forEach { file ->
val fileContents = String(Files.readAllBytes(File(file.path).toPath()))
service.highlightTextInAllEditors(fileContents) // Updated to use new method
}
}
} catch (e: Exception) {
Expand Down

0 comments on commit 19aada3

Please sign in to comment.