Skip to content

Commit a7a1432

Browse files
committed
refactor(gui): improve text handling in AutoDevInputSection
- Replace `text` property with separate methods for rendering and setting text - Update text manipulation in NormalChatCodingPanel and SketchInputListener - Adjust text input methods in SketchToolWindow
1 parent 0a95f3c commit a7a1432

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

core/src/main/kotlin/cc/unitmesh/devti/gui/chat/NormalChatCodingPanel.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ class NormalChatCodingPanel(private val chatCodingService: ChatCodingService, va
106106
}
107107

108108
override fun onSubmit(component: AutoDevInputSection, trigger: AutoDevInputTrigger) {
109-
var prompt = component.text
110-
component.text = ""
109+
var prompt = component.renderText()
110+
component.clearText()
111111

112112

113113
if (prompt.isEmpty() || prompt.isBlank()) {
@@ -282,7 +282,7 @@ class NormalChatCodingPanel(private val chatCodingService: ChatCodingService, va
282282
}
283283

284284
fun setInput(trimMargin: String) {
285-
inputSection.text = trimMargin.trim()
285+
inputSection.setText(trimMargin.trim())
286286
this.focusInput()
287287
}
288288

core/src/main/kotlin/cc/unitmesh/devti/gui/chat/ui/AutoDevInputSection.kt

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,22 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
9191
null
9292
}
9393

94-
// TODO: refactor
95-
var text: String
96-
get() {
97-
val files = workspaceFilePanel.getAllFilesFormat()
98-
relatedFileListViewModel.clearAllFiles()
99-
workspaceFilePanel.clear()
100-
return input.text + "\n" + files
101-
}
102-
set(text) {
103-
input.recreateDocument()
104-
input.text = text
105-
}
94+
fun renderText(): String {
95+
val files = workspaceFilePanel.getAllFilesFormat()
96+
relatedFileListViewModel.clearAllFiles()
97+
workspaceFilePanel.clear()
98+
return input.text + "\n" + files
99+
}
100+
101+
fun clearText() {
102+
input.recreateDocument()
103+
input.text = ""
104+
}
105+
106+
fun setText(text: String) {
107+
input.recreateDocument()
108+
input.text = text
109+
}
106110

107111
init {
108112
input = AutoDevInput(project, listOf(), disposable, this)
@@ -382,7 +386,7 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
382386
}
383387

384388
customAgent.selectedItem = defaultRag
385-
text = ""
389+
input.text = ""
386390
workspaceFilePanel.clear()
387391
}
388392

core/src/main/kotlin/cc/unitmesh/devti/sketch/SketchInputListener.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ open class SketchInputListener(
5252
}
5353

5454
override fun onSubmit(component: AutoDevInputSection, trigger: AutoDevInputTrigger) {
55-
val userInput = component.text
56-
component.text = ""
55+
val userInput = component.renderText()
56+
component.clearText()
5757

5858
if (userInput.isEmpty() || userInput.isBlank()) {
5959
component.showTooltip(AutoDevBundle.message("chat.input.tips"))

core/src/main/kotlin/cc/unitmesh/devti/sketch/SketchToolWindow.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ open class SketchToolWindow(
281281
}
282282

283283
fun setInput(text: String) {
284-
inputSection.text = text.trim()
284+
inputSection.setText(text.trim())
285285
}
286286

287287
fun createSingleTextView(text: String, language: String = "markdown"): DialogPanel {
@@ -426,15 +426,15 @@ open class SketchToolWindow(
426426
}
427427

428428
fun sendInput(text: String) {
429-
inputSection.text += text.trim()
429+
inputSection.setText(text.trim())
430430
ApplicationManager.getApplication().invokeLater {
431431
inputSection.send()
432432
}
433433
}
434434

435435
fun putText(text: String) {
436436
runInEdt {
437-
inputSection.text = text
437+
inputSection.setText(text.trim())
438438
}
439439
}
440440

0 commit comments

Comments
 (0)