Skip to content

Commit 6b74688

Browse files
committed
feat(codehighlight): improve editor visibility logic
- Add user/DevIns status check to shouldUseCollapsedView() - Enhance toggleEditorVisibility() with conditional label handling based on line count - Update auto-collapse logic with better status awareness
1 parent f3bdf18 commit 6b74688

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/code/CodeHighlightSketch.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ open class CodeHighlightSketch(
8686
displayName == "Markdown" -> false
8787
ideaLanguage == PlainTextLanguage.INSTANCE -> false
8888
displayName == plainText -> false
89+
!isUser && !isDevIns -> false
8990
else -> true
9091
}
9192
}
@@ -265,16 +266,19 @@ open class CodeHighlightSketch(
265266

266267
private fun toggleEditorVisibility() {
267268
if (isCollapsed) {
268-
// 展开:移除折叠面板,添加编辑器内容和折叠标签
269269
remove(collapsedPanel)
270270
add(editorFragment!!.getContent())
271271

272-
val fewerLinesLabel = createFewerLinesLabel()
273-
add(fewerLinesLabel)
272+
val lineCount = editorFragment?.editor?.document?.lineCount ?: 0
273+
if (lineCount > editorLineThreshold) {
274+
editorFragment?.updateExpandCollapseLabel()
275+
} else {
276+
val fewerLinesLabel = createFewerLinesLabel()
277+
add(fewerLinesLabel)
278+
}
274279

275280
isCollapsed = false
276281
} else {
277-
// 折叠:移除所有内容,只显示折叠面板
278282
removeAll()
279283
add(collapsedPanel!!)
280284
isCollapsed = true
@@ -349,6 +353,7 @@ open class CodeHighlightSketch(
349353
}
350354

351355
// Auto-collapse view when complete (only for collapsible views)
356+
// 注意:现在 shouldUseCollapsedView() 已经考虑了 isUser 和 isDevIns 状态
352357
if (complete && !isCollapsed && shouldUseCollapsedView()) {
353358
toggleEditorVisibility()
354359
}

0 commit comments

Comments
 (0)