From 71dd9463c4a6525a95704d9fca501990f5e85f93 Mon Sep 17 00:00:00 2001 From: Carl-Robert Linnupuu Date: Fri, 6 Dec 2024 10:03:35 +0000 Subject: [PATCH] fix: disable submission when current response is ongoing --- .../codegpt/ui/textarea/PromptTextField.kt | 15 +++++++-------- .../codegpt/ui/textarea/UserInputPanel.kt | 4 +++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/ee/carlrobert/codegpt/ui/textarea/PromptTextField.kt b/src/main/kotlin/ee/carlrobert/codegpt/ui/textarea/PromptTextField.kt index 55bcb718..dbadd020 100644 --- a/src/main/kotlin/ee/carlrobert/codegpt/ui/textarea/PromptTextField.kt +++ b/src/main/kotlin/ee/carlrobert/codegpt/ui/textarea/PromptTextField.kt @@ -65,12 +65,18 @@ class PromptTextField( IdeEventQueue.getInstance().addDispatcher( PromptTextFieldEventDispatcher(this, suggestionsPopupManager, appliedInlays) { onSubmit(text, appliedInlays) - clear() }, this ) } + fun clear() { + runInEdt { + text = "" + clearInlays() + } + } + fun addInlayElement(actionPrefix: String, text: String?, actionItem: SuggestionActionItem?) { editor?.let { var startOffset = it.document.text.lastIndexOf(AT_CHAR) @@ -150,13 +156,6 @@ class PromptTextField( clear() } - private fun clear() { - runInEdt { - text = "" - clearInlays() - } - } - private fun clearInlays() { runUndoTransparentWriteAction { appliedInlays.forEach { it.inlay.dispose() } diff --git a/src/main/kotlin/ee/carlrobert/codegpt/ui/textarea/UserInputPanel.kt b/src/main/kotlin/ee/carlrobert/codegpt/ui/textarea/UserInputPanel.kt index 2115fe4a..9a598e43 100644 --- a/src/main/kotlin/ee/carlrobert/codegpt/ui/textarea/UserInputPanel.kt +++ b/src/main/kotlin/ee/carlrobert/codegpt/ui/textarea/UserInputPanel.kt @@ -62,6 +62,7 @@ class UserInputPanel( ) { override fun actionPerformed(e: AnActionEvent) { handleSubmit(promptTextField.text) + promptTextField.clear() } } ) @@ -134,8 +135,9 @@ class UserInputPanel( override fun getInsets(): Insets = JBUI.insets(4) private fun handleSubmit(text: String, appliedInlays: List? = emptyList()) { - if (text.isNotEmpty()) { + if (text.isNotEmpty() && submitButton.isEnabled) { onSubmit(text, appliedInlays) + promptTextField.clear() } }