Better folding for mulitline strings (KT-21441)
#KT-21441 Fixed
This commit is contained in:
@@ -100,16 +100,20 @@ class KotlinFoldingBuilder : CustomFoldingBuilder(), DumbAware {
|
||||
override fun getLanguagePlaceholderText(node: ASTNode, range: TextRange): String = when {
|
||||
node.elementType == KtTokens.BLOCK_COMMENT -> "/${getFirstLineOfComment(node)}.../"
|
||||
node.elementType == KDocTokens.KDOC -> "/**${getFirstLineOfComment(node)}...*/"
|
||||
node.elementType == KtNodeTypes.STRING_TEMPLATE -> "\"\"\"${getFirstLineOfString(node)}...\"\"\""
|
||||
node.elementType == KtNodeTypes.STRING_TEMPLATE -> "\"\"\"${getTrimmedFirstLineOfString(node).addSpaceIfNeeded()}...\"\"\""
|
||||
node.psi is KtImportList -> "..."
|
||||
else -> "{...}"
|
||||
}
|
||||
|
||||
private fun getFirstLineOfString(node: ASTNode): String {
|
||||
val targetStringLine = node.text.split("\n").asSequence().map {
|
||||
it.replace("\"\"\"", "")
|
||||
}.firstOrNull(String::isNotBlank) ?: return ""
|
||||
return " ${targetStringLine.replace("\"\"\"", "").trim()} "
|
||||
private fun getTrimmedFirstLineOfString(node: ASTNode): String {
|
||||
val lines = node.text.split("\n")
|
||||
val firstLine = lines.asSequence().map { it.replace("\"\"\"", "").trim() }.firstOrNull(String::isNotEmpty)
|
||||
return firstLine ?: ""
|
||||
}
|
||||
|
||||
private fun String.addSpaceIfNeeded(): String {
|
||||
if (isEmpty() || endsWith(" ")) return this
|
||||
return this + " "
|
||||
}
|
||||
|
||||
private fun getFirstLineOfComment(node: ASTNode): String {
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
val result1 = <fold text='""" 14.55576559546314 - 0.25, 3.0, 0.25, 0.25, 1.0, 0.25, 1.0, 2.0, 1.0, 0.25, 1.0, 0.5, 2.0, 3.0, 3.0 ..."""' expand='true'>"""
|
||||
val result1 = <fold text='"""14.55576559546314 - 0.25, 3.0, 0.25, 0.25, 1.0, 0.25, 1.0, 2.0, 1.0, 0.25, 1.0, 0.5, 2.0, 3.0, 3.0 ..."""' expand='true'>"""
|
||||
14.55576559546314 - 0.25, 3.0, 0.25, 0.25, 1.0, 0.25, 1.0, 2.0, 1.0, 0.25, 1.0, 0.5, 2.0, 3.0, 3.0
|
||||
14.55576559546314 - 0.25, 4.0, 1.0, 0.5, 1.0, 1.0, 3.0, 4.0, 3.0, 0.25, 3.0, 0.5, 3.0, 3.0, 2.0
|
||||
14.55576559546314 - 0.25, 3.0, 0.25, 0.25, 1.0, 0.25, 2.0, 2.0, 1.0, 0.5, 1.0, 0.5, 2.0, 3.0, 3.0
|
||||
@@ -22,7 +22,7 @@ val result1 = <fold text='""" 14.55576559546314 - 0.25, 3.0, 0.25, 0.25, 1.0,
|
||||
14.55576559546314 - 0.25, 3.0, 0.25, 0.25, 1.0, 0.25, 1.0, 2.0, 3.0, 0.3333333333333333, 1.0, 0.5, 3.0, 3.0, 2.5
|
||||
"""</fold>
|
||||
|
||||
val result2 = <fold text='""" other multiline string ..."""' expand='true'>"""other multiline string
|
||||
val result2 = <fold text='"""other multiline string ..."""' expand='true'>"""other multiline string
|
||||
without spaces
|
||||
"""</fold>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user