Skip to content

Commit 99bf0f9

Browse files
committed
refactor(input): adjust input size and improve new line insertion #257
- Change `preferredSize` to `minimumSize` for input field to ensure consistent sizing. - Refactor new line insertion logic to handle text after caret and use `WriteCommandAction` for thread safety.
1 parent 91abe1b commit 99bf0f9

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,20 @@ class AutoDevInput(
6363
// Insert a new line
6464
CommandProcessor.getInstance().executeCommand(project, {
6565
val eol = "\n"
66+
val document = editor.document
6667
val caretOffset = editor.caretModel.offset
67-
editor.document.insertString(caretOffset, eol)
68-
editor.caretModel.moveToOffset(caretOffset + eol.length)
69-
EditorModificationUtil.scrollToCaret(editor)
70-
}, null, null)
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)
7180
}
7281
}
7382
}.registerCustomShortcutSet(

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,8 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
138138

139139
input.addDocumentListener(documentListener)
140140
input.recreateDocument()
141-
142141
input.border = JBEmptyBorder(10)
143142

144-
// addToCenter(input)
145143
this.add(input, BorderLayout.CENTER)
146144
this.add(elementsList, BorderLayout.NORTH)
147145

@@ -164,7 +162,7 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
164162
}
165163
customRag.selectedItem = defaultRag
166164

167-
input.preferredSize = Dimension(input.preferredSize.width, 48)
165+
input.minimumSize = Dimension(input.minimumSize.width, 48)
168166
layoutPanel.addToLeft(customRag)
169167
}
170168

0 commit comments

Comments
 (0)