Skip to content

Commit 809f6a1

Browse files
committed
refactor(EditorFragment): simplify and optimize layout calculations
1 parent 8c0bb92 commit 809f6a1

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

core/src/main/kotlin/com/intellij/temporary/gui/block/EditorFragment.kt

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ class EditorFragment(private val project: Project, private val editor: EditorEx,
6868
val lineHeight = editor.lineHeight
6969
val insets = editor.scrollPane.getInsets()
7070
val height = lineHeight * editorLineThreshold + insets.height
71+
7172
var editorMaxHeight = height + expandCollapseTextLabel.preferredSize.height + getInsets().height
72-
val it = editor.headerComponent
73-
if (it != null) {
74-
editorMaxHeight += it.getPreferredSize().height
73+
val header = editor.headerComponent
74+
if (header != null) {
75+
editorMaxHeight += header.getPreferredSize().height
7576
}
77+
7678
return Dimension(preferredSize.width, editorMaxHeight)
7779
}
7880

@@ -83,7 +85,7 @@ class EditorFragment(private val project: Project, private val editor: EditorEx,
8385
content.setBorder(
8486
JBUI.Borders.compound(
8587
JBUI.Borders.empty(10, 0),
86-
JBUI.Borders.customLine(JBColor(13949150, 4740710))
88+
JBUI.Borders.customLine(JBColor(0xD4E1570, 0x474071))
8789
)
8890
)
8991
content.setOpaque(false)
@@ -96,12 +98,12 @@ class EditorFragment(private val project: Project, private val editor: EditorEx,
9698
override fun mouseClicked(e: MouseEvent?) {
9799
setCollapsed(!getCollapsed())
98100
}
99-
} as MouseListener)
101+
})
100102
}
101103

102-
fun getCollapsed(): Boolean {
103-
return collapsed
104-
}
104+
fun getContent(): JComponent = content
105+
106+
fun getCollapsed(): Boolean = collapsed
105107

106108
fun setCollapsed(value: Boolean) {
107109
collapsed = value
@@ -111,18 +113,8 @@ class EditorFragment(private val project: Project, private val editor: EditorEx,
111113
fun updateExpandCollapseLabel() {
112114
val linesCount = editor.document.lineCount
113115
expandCollapseTextLabel.isVisible = linesCount > editorLineThreshold
114-
if (collapsed) {
115-
expandCollapseTextLabel.text = "More lines"
116-
expandCollapseTextLabel.icon = AllIcons.General.ChevronDown
117-
return
118-
}
119-
120-
expandCollapseTextLabel.text = ""
121-
expandCollapseTextLabel.icon = AllIcons.General.ChevronUp
122-
}
123-
124-
fun getContent(): JComponent {
125-
return content
116+
expandCollapseTextLabel.text = if (collapsed) "More lines" else ""
117+
expandCollapseTextLabel.icon = if (collapsed) AllIcons.General.ChevronDown else AllIcons.General.ChevronUp
126118
}
127119
}
128120

0 commit comments

Comments
 (0)