in src/main/kotlin/org/jetbrains/mcpserverplugin/general/textTools.kt [100:119]
override fun handle(project: Project, args: ReplaceSelectedTextArgs): Response {
var response: Response? = null
application.invokeAndWait {
runWriteCommandAction(project, "Replace Selected Text", null, {
val editor = FileEditorManager.getInstance(project).selectedTextEditor
val document = editor?.document
val selectionModel = editor?.selectionModel
if (document != null && selectionModel != null && selectionModel.hasSelection()) {
document.replaceString(selectionModel.selectionStart, selectionModel.selectionEnd, args.text)
PsiDocumentManager.getInstance(project).commitDocument(document)
response = Response("ok")
} else {
response = Response(error = "no text selected")
}
})
}
return response ?: Response(error = "unknown error")
}