Skip to content

Commit 0ebd2ac

Browse files
committed
refactor(editor): simplify expand/collapse label logic
Remove redundant state checks and simplify the logic for updating the expand/collapse label in the editor. The label now consistently shows "More lines" with a chevron down icon when the line count exceeds the threshold.
1 parent e4e82e3 commit 0ebd2ac

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ open class CodeHighlightSketch(
116116
val normalizedText = StringUtil.convertLineSeparators(text)
117117
document?.replaceString(0, document.textLength, normalizedText)
118118

119-
document?.lineCount?.let {
120-
if (it > editorLineThreshold) {
121-
editorFragment?.updateExpandCollapseLabel()
122-
}
123-
if (complete) {
124-
if (isDevIns && it > minDevinLineThreshold) {
125-
editorFragment?.resizeForNewThreshold(minDevinLineThreshold)
126-
}
119+
val lineCount = document?.lineCount ?: 0
120+
if (lineCount > editorLineThreshold) {
121+
editorFragment?.updateExpandCollapseLabel()
122+
}
123+
124+
if (complete) {
125+
if (isDevIns) {
126+
editorFragment?.resizeForNewThreshold(minDevinLineThreshold)
127127
}
128128
}
129129
}
@@ -223,7 +223,7 @@ open class CodeHighlightSketch(
223223

224224
try {
225225
EditorFactory.getInstance().createViewer(document, project, EditorKind.PREVIEW) as EditorEx
226-
} catch (e: Throwable){
226+
} catch (e: Throwable) {
227227
throw e
228228
}
229229
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,11 @@ class EditorFragment(var editor: EditorEx, private val editorLineThreshold: Int
104104
}
105105

106106
fun resizeForNewThreshold(newThreshold: Int) {
107-
setCollapsed(false)
108-
109107
content.preferredSize = calculatePreferredSize(content.preferredSize, newThreshold)
110108

111-
val linesCount = editor.document.lineCount
112-
expandCollapseTextLabel.isVisible = linesCount > editorLineThreshold
113-
expandCollapseTextLabel.text = if (collapsed) "More lines" else ""
114-
expandCollapseTextLabel.icon = if (collapsed) AllIcons.General.ChevronDown else AllIcons.General.ChevronUp
109+
expandCollapseTextLabel.isVisible = true
110+
expandCollapseTextLabel.text = "More lines"
111+
expandCollapseTextLabel.icon = AllIcons.General.ChevronDown
115112

116113
content.revalidate()
117114
content.repaint()

0 commit comments

Comments
 (0)