diff --git a/src/main/kotlin/com/smallcloud/refactai/code_lens/CodeLensAction.kt b/src/main/kotlin/com/smallcloud/refactai/code_lens/CodeLensAction.kt index 06050b17..6dd4eab1 100644 --- a/src/main/kotlin/com/smallcloud/refactai/code_lens/CodeLensAction.kt +++ b/src/main/kotlin/com/smallcloud/refactai/code_lens/CodeLensAction.kt @@ -9,6 +9,7 @@ import com.intellij.openapi.wm.ToolWindowManager import com.smallcloud.refactai.Resources import com.smallcloud.refactai.panes.RefactAIToolboxPaneFactory import kotlin.io.path.relativeTo +import kotlinx.coroutines.* class CodeLensAction( private val editor: Editor, @@ -34,6 +35,7 @@ class CodeLensAction( }.minBy { it.toString().length } } + return contentMsg .replace("%CURRENT_FILE%", relativePath?.toString() ?: filePath.toString()) .replace("%CURSOR_LINE%", line1.toString()) @@ -46,5 +48,19 @@ class CodeLensAction( RefactAIToolboxPaneFactory.chat?.requestFocus() RefactAIToolboxPaneFactory.chat?.executeCodeLensCommand(formatMessage(), sendImmediately, openNewTab) } + + // If content is empty, then it's "Open Chat" instruction, selecting range of code in active tab + if (contentMsg.isEmpty()) { + CoroutineScope(Dispatchers.Main).launch { + delay(500) + val pos1 = LogicalPosition(line1, 0) + val pos2 = LogicalPosition(line2, editor.document.getLineEndOffset(line2)) + + editor.selectionModel.setSelection( + editor.logicalPositionToOffset(pos1), + editor.logicalPositionToOffset(pos2) + ) + } + } } } \ No newline at end of file