Skip to content

Commit 8cbc1d1

Browse files
committed
refactor(completion): remove commented code and clean up CompletionPopup and DevInEditorInput #453
1 parent 02fffc3 commit 8cbc1d1

File tree

2 files changed

+2
-24
lines changed

2 files changed

+2
-24
lines changed

mpp-ui/src/commonMain/kotlin/cc/unitmesh/devins/ui/compose/editor/DevInEditorInput.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ fun DevInEditorInput(
129129

130130

131131

132-
// 应用补全
133132
fun applyCompletion(item: CompletionItem) {
134133
val insertHandler = item.insertHandler
135134
val result = if (insertHandler != null) {
@@ -405,12 +404,11 @@ fun DevInEditorInput(
405404
newPosition,
406405
CompletionTriggerType.COMMAND
407406
)
408-
if (context != null && manager != null) {
407+
if (context != null) {
409408
currentTriggerType = CompletionTriggerType.COMMAND
410409
completionItems = manager.getFilteredCompletions(context)
411410
selectedCompletionIndex = 0
412411
showCompletion = completionItems.isNotEmpty()
413-
println("🔍 / 补全触发: items=${completionItems.size}")
414412
}
415413
}
416414
},
@@ -420,7 +418,6 @@ fun DevInEditorInput(
420418
}
421419
}
422420

423-
// 补全弹窗
424421
if (showCompletion && completionItems.isNotEmpty()) {
425422
CompletionPopup(
426423
items = completionItems,
@@ -439,7 +436,6 @@ fun DevInEditorInput(
439436
}
440437
}
441438

442-
// 自动聚焦
443439
LaunchedEffect(Unit) {
444440
focusRequester.requestFocus()
445441
}

mpp-ui/src/commonMain/kotlin/cc/unitmesh/devins/ui/compose/editor/completion/CompletionPopup.kt

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ import cc.unitmesh.devins.completion.CompletionContext
2626
import cc.unitmesh.devins.completion.CompletionTriggerType
2727
import kotlinx.coroutines.launch
2828

29-
/**
30-
* 补全弹窗组件
31-
*/
3229
@Composable
3330
fun CompletionPopup(
3431
items: List<CompletionItem>,
@@ -47,7 +44,6 @@ fun CompletionPopup(
4744
val listState = rememberLazyListState()
4845
val scope = rememberCoroutineScope()
4946

50-
// 当选中项改变时,滚动到可见区域
5147
LaunchedEffect(selectedIndex) {
5248
if (selectedIndex in items.indices) {
5349
scope.launch {
@@ -96,9 +92,6 @@ fun CompletionPopup(
9692
}
9793
}
9894

99-
/**
100-
* 单个补全项行
101-
*/
10295
@Composable
10396
private fun CompletionItemRow(
10497
item: CompletionItem,
@@ -121,7 +114,6 @@ private fun CompletionItemRow(
121114
.padding(horizontal = 12.dp, vertical = 6.dp),
122115
verticalAlignment = Alignment.CenterVertically
123116
) {
124-
// 图标(emoji)
125117
item.icon?.let { icon ->
126118
Text(
127119
text = icon,
@@ -130,9 +122,7 @@ private fun CompletionItemRow(
130122
)
131123
}
132124

133-
// 主要内容
134125
Column(modifier = Modifier.weight(1f)) {
135-
// 显示文本
136126
Text(
137127
text = item.displayText,
138128
style = MaterialTheme.typography.bodyMedium.copy(
@@ -144,7 +134,6 @@ private fun CompletionItemRow(
144134
overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis
145135
)
146136

147-
// 描述文本
148137
item.description?.let { description ->
149138
Text(
150139
text = description,
@@ -158,7 +147,6 @@ private fun CompletionItemRow(
158147
}
159148
}
160149

161-
// 右侧信息(如文件扩展名)
162150
if (item.description != "Directory") {
163151
val fileExtension = item.text.substringAfterLast('.', "")
164152
if (fileExtension.isNotEmpty() && fileExtension.length <= 4) {
@@ -179,9 +167,6 @@ private fun CompletionItemRow(
179167
}
180168
}
181169

182-
/**
183-
* 补全触发器 - 检测是否应该触发补全
184-
*/
185170
object CompletionTrigger {
186171
fun shouldTrigger(char: Char): Boolean {
187172
return char in setOf('@', '/', '$', ':', '`')
@@ -203,7 +188,6 @@ object CompletionTrigger {
203188
cursorPosition: Int,
204189
triggerType: CompletionTriggerType
205190
): CompletionContext? {
206-
// 找到最近的触发字符
207191
val triggerChar = when (triggerType) {
208192
CompletionTriggerType.AGENT -> '@'
209193
CompletionTriggerType.COMMAND -> '/'
@@ -215,10 +199,8 @@ object CompletionTrigger {
215199
val triggerOffset = fullText.lastIndexOf(triggerChar, cursorPosition - 1)
216200
if (triggerOffset < 0) return null
217201

218-
// 提取查询文本(触发字符后到光标的文本)
219202
val queryText = fullText.substring(triggerOffset + 1, cursorPosition)
220-
221-
// 检查查询文本是否有效(不包含空白字符或换行)
203+
222204
if (queryText.contains('\n') || queryText.contains(' ')) {
223205
return null
224206
}

0 commit comments

Comments
 (0)