Skip to content

Commit 0ee09ca

Browse files
committed
fix: fold blocks separately
1 parent 073294e commit 0ee09ca

File tree

1 file changed

+19
-35
lines changed

1 file changed

+19
-35
lines changed

src/main/kotlin/com/github/xepozz/php_dump/startup/EditorListener.kt

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.github.xepozz.php_dump.startup
22

33
import com.github.xepozz.php_dump.services.EditorProvider
44
import com.github.xepozz.php_opcodes_language.language.PHPOpFile
5-
import com.github.xepozz.php_opcodes_language.language.psi.PHPOpBlockName
5+
import com.github.xepozz.php_opcodes_language.language.psi.PHPOpBlock
66
import com.intellij.openapi.editor.FoldingGroup
77
import com.intellij.openapi.editor.ScrollType
88
import com.intellij.openapi.editor.event.EditorMouseEvent
@@ -39,48 +39,32 @@ class EditorListener : EditorMouseListener {
3939

4040
val psiFile = psiDocumentManager.getPsiFile(opcodesEditor.document) as? PHPOpFile ?: return
4141

42-
PsiTreeUtil.findChildrenOfType(psiFile, PHPOpBlockName::class.java)
43-
.firstOrNull { it.methodName?.name == method.name }
44-
?.let {
45-
opcodesEditor.scrollingModel.scrollTo(
46-
opcodesEditor.offsetToLogicalPosition(it.textOffset), ScrollType.CENTER_DOWN
47-
)
42+
val blocks = PsiTreeUtil.findChildrenOfType(psiFile, PHPOpBlock::class.java)
4843

49-
val block = it.parent
44+
val selectedBlock = blocks.firstOrNull { it.blockName.methodName?.name == method.name } ?: return
5045

51-
// opcodesEditor.markupModel.apply {
52-
// removeAllHighlighters()
53-
// addRangeHighlighter(
54-
// block.startOffset,
55-
// block.endOffset,
56-
// 0,
57-
// TextAttributes().apply {
58-
// effectType = EffectType.BOXED
59-
// effectColor = JBColor.RED
60-
// },
61-
// HighlighterTargetArea.EXACT_RANGE,
62-
// )
63-
// }
6446

65-
opcodesEditor.foldingModel.apply {
66-
runBatchFoldingOperation {
67-
clearFoldRegions()
47+
opcodesEditor.foldingModel.apply {
48+
runBatchFoldingOperation {
49+
clearFoldRegions()
50+
51+
blocks
52+
.filter { it !== selectedBlock }
53+
.forEach { block ->
6854
createFoldRegion(
69-
0,
70-
block.startOffset - 1,
71-
"...",
55+
block.startOffset,
56+
block.endOffset - 1,
57+
block.blockName.name ?: "...",
7258
FoldingGroup.newGroup("before block"),
7359
false,
7460
)?.apply { isExpanded = false }
75-
createFoldRegion(
76-
block.endOffset,
77-
block.containingFile.textLength,
78-
"...",
79-
FoldingGroup.newGroup("after block"),
80-
false,
81-
)?.apply { isExpanded = false }
8261
}
83-
}
8462
}
63+
}
64+
65+
opcodesEditor.scrollingModel.scrollTo(
66+
opcodesEditor.offsetToLogicalPosition(selectedBlock.textOffset),
67+
ScrollType.CENTER_DOWN
68+
)
8569
}
8670
}

0 commit comments

Comments
 (0)