Skip to content

Commit 83418ed

Browse files
committed
refactor(chat): improve input handling and UI adjustments #257
- Update input minimum height and border handling in `AutoDevInputSection`. - Simplify new line insertion logic in `AutoDevInput` and add support for Shift+Enter shortcut. - Move `RelatedFileListCellRenderer` to `ui` package for better organization.
1 parent d433f44 commit 83418ed

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

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

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import com.intellij.util.EventDispatcher
3131
import com.intellij.util.messages.MessageBusConnection
3232
import com.intellij.util.ui.JBUI
3333
import java.awt.Color
34+
import java.awt.event.InputEvent
3435
import java.awt.event.KeyEvent
3536
import java.util.*
3637
import javax.swing.KeyStroke
@@ -57,32 +58,31 @@ class AutoDevInput(
5758
}
5859

5960
DumbAwareAction.create {
60-
object : AnAction() {
61-
override fun actionPerformed(actionEvent: AnActionEvent) {
62-
val editor = editor ?: return
63-
// Insert a new line
64-
CommandProcessor.getInstance().executeCommand(project, {
65-
val eol = "\n"
66-
val document = editor.document
67-
val caretOffset = editor.caretModel.offset
68-
val lineEndOffset = document.getLineEndOffset(document.getLineNumber(caretOffset))
69-
val textAfterCaret = document.getText(TextRange(caretOffset, lineEndOffset))
70-
71-
WriteCommandAction.runWriteCommandAction(project) {
72-
if (textAfterCaret.isBlank()) {
73-
document.insertString(caretOffset, eol)
74-
} else {
75-
document.insertString(caretOffset, eol)
76-
editor.caretModel.moveToOffset(caretOffset + eol.length)
77-
}
78-
}
79-
}, "Insert New Line", null)
61+
val editor = editor ?: return@create
62+
// Insert a new line
63+
CommandProcessor.getInstance().executeCommand(project, {
64+
val eol = "\n"
65+
val document = editor.document
66+
val caretOffset = editor.caretModel.offset
67+
val lineEndOffset = document.getLineEndOffset(document.getLineNumber(caretOffset))
68+
val textAfterCaret = document.getText(TextRange(caretOffset, lineEndOffset))
69+
70+
WriteCommandAction.runWriteCommandAction(project) {
71+
if (textAfterCaret.isBlank()) {
72+
document.insertString(caretOffset, eol)
73+
// move to next line
74+
EditorModificationUtil.moveCaretRelatively(editor, 1)
75+
} else {
76+
document.insertString(caretOffset, eol)
77+
editor.caretModel.moveToOffset(caretOffset + eol.length)
78+
}
8079
}
81-
}
80+
}, "Insert New Line", null)
8281
}.registerCustomShortcutSet(
8382
CustomShortcutSet(
8483
KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_DOWN_MASK), null),
85-
KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.META_DOWN_MASK), null)
84+
KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.META_DOWN_MASK), null),
85+
KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK), null),
8686
), this
8787
)
8888

@@ -113,6 +113,7 @@ class AutoDevInput(
113113
editor.caretModel.moveToOffset(0)
114114
editor.scrollPane.setBorder(border)
115115
editor.contentComponent.setOpaque(false)
116+
116117
return editor
117118
}
118119

@@ -160,7 +161,13 @@ class AutoDevInput(
160161
"Append text",
161162
"intentions.write.action",
162163
{
163-
insertStringAndSaveChange(project, text, this.editor!!.document, this.editor!!.document.textLength, false)
164+
insertStringAndSaveChange(
165+
project,
166+
text,
167+
this.editor!!.document,
168+
this.editor!!.document.textLength,
169+
false
170+
)
164171
})
165172
}
166173
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import cc.unitmesh.devti.AutoDevIcons
55
import cc.unitmesh.devti.agent.configurable.customAgentSetting
66
import cc.unitmesh.devti.agent.model.CustomAgentConfig
77
import cc.unitmesh.devti.agent.model.CustomAgentState
8+
import cc.unitmesh.devti.gui.chat.ui.RelatedFileListCellRenderer
89
import cc.unitmesh.devti.llms.tokenizer.Tokenizer
910
import cc.unitmesh.devti.llms.tokenizer.TokenizerFactory
10-
import cc.unitmesh.devti.provider.RelatedClassesProvider.Companion
1111
import cc.unitmesh.devti.settings.AutoDevSettingsState
1212
import com.intellij.codeInsight.lookup.LookupManagerListener
1313
import com.intellij.icons.AllIcons
@@ -163,7 +163,7 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
163163
}
164164
customRag.selectedItem = defaultRag
165165

166-
input.minimumSize = Dimension(input.minimumSize.width, 48)
166+
input.minimumSize = Dimension(input.minimumSize.width, 64)
167167
layoutPanel.addToLeft(customRag)
168168
}
169169

@@ -295,8 +295,7 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
295295

296296
fun initEditor() {
297297
val editorEx = this.input.editor as? EditorEx ?: return
298-
299-
setBorder(AutoDevCoolBorder(editorEx, this))
298+
this.input.setBorder(AutoDevCoolBorder(editorEx, this))
300299
UIUtil.setOpaqueRecursively(this, false)
301300
this.revalidate()
302301
}

core/src/main/kotlin/cc/unitmesh/devti/gui/chat/RelatedFileListCellRenderer.kt renamed to core/src/main/kotlin/cc/unitmesh/devti/gui/chat/ui/RelatedFileListCellRenderer.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
package cc.unitmesh.devti.gui.chat
1+
package cc.unitmesh.devti.gui.chat.ui
22

3+
import cc.unitmesh.devti.gui.chat.ModelWrapper
34
import com.intellij.icons.AllIcons
45
import com.intellij.util.ui.JBUI
56
import java.awt.BorderLayout

0 commit comments

Comments
 (0)