Join parameter/argument list: use document to delete whitespaces
Otherwise fix has no effect in IDE. Related to KT-23266
This commit is contained in:
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||||
|
|
||||||
abstract class AbstractChopListIntention<TList : KtElement, TElement : KtElement>(
|
abstract class AbstractChopListIntention<TList : KtElement, TElement : KtElement>(
|
||||||
private val listClass: Class<TList>,
|
protected val listClass: Class<TList>,
|
||||||
private val elementClass: Class<TElement>,
|
private val elementClass: Class<TElement>,
|
||||||
text: String
|
text: String
|
||||||
) : SelfTargetingOffsetIndependentIntention<TList>(listClass, text), LowPriorityAction {
|
) : SelfTargetingOffsetIndependentIntention<TList>(listClass, text), LowPriorityAction {
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ package org.jetbrains.kotlin.idea.intentions
|
|||||||
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||||
|
|
||||||
abstract class AbstractJoinListIntention<TList : KtElement, TElement : KtElement>(
|
abstract class AbstractJoinListIntention<TList : KtElement, TElement : KtElement>(
|
||||||
listClass: Class<TList>,
|
listClass: Class<TList>,
|
||||||
@@ -21,9 +23,14 @@ abstract class AbstractJoinListIntention<TList : KtElement, TElement : KtElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun applyTo(element: TList, editor: Editor?) {
|
override fun applyTo(element: TList, editor: Editor?) {
|
||||||
|
val document = editor!!.document
|
||||||
val elements = element.elements()
|
val elements = element.elements()
|
||||||
prevBreak(elements.first())?.delete()
|
|
||||||
elements.forEach { nextBreak(it)?.delete() }
|
nextBreak(elements.last())?.let { document.deleteString(it.startOffset, it.endOffset) }
|
||||||
|
elements.dropLast(1).asReversed().forEach {
|
||||||
|
nextBreak(it)?.let { document.replaceString(it.startOffset, it.endOffset, " ") }
|
||||||
|
}
|
||||||
|
prevBreak(elements.first())?.let { document.deleteString(it.startOffset, it.endOffset) }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user