fun exchangeIndices()

in src/main/kotlin/git4ideaClasses/IRGitModel.kt [139:162]


    fun exchangeIndices(
        oldIndex: Int,
        newIndex: Int,
    ) {
        rows.modifyList {
            val elementsToMove: List<Element<T>> =
                when (val element = rows[oldIndex]) {
                    is Element.UniteRoot -> element.uniteGroup
                    is Element.Simple -> listOf(element)
                    is Element.UniteChild -> {
                        val newElement = removeAndMoveUniteChild(element, Type.NonUnite.KeepCommit.Pick)
                        if (newElement.index == newIndex) {
                            // moved to the last position of current UniteGroup
                            addToUniteGroup(newElement.index, element.root)
                            listOf()
                        } else {
                            listOf(newElement)
                        }
                    }
                }
            moveElements(elementsToMove, newIndex)
            addToUniteGroupIfNeeded(elementsToMove)
        }
    }