Fix potential crash in console autocomplete (#11568)

This commit is contained in:
SomeTroglodyte
2024-05-11 20:35:57 +02:00
committed by GitHub
parent 0f4b52aaea
commit 7bbe218bf0

View File

@ -73,9 +73,11 @@ open class ConsoleAction(val format: String, val action: (console: DevConsolePop
it.removeSurrounding("<",">").removeSurrounding("[","]").removeSurrounding("\"")
}
if (formatParams.size < params.size) return ""
val formatParam = formatParams[params.lastIndex]
// It is possible we're here *with* another format parameter but an *empty* params (e.g. `tile addriver ` and hit tab) -> see else branch
val (formatParam, lastParam) = if (params.lastIndex in formatParams.indices)
formatParams[params.lastIndex] to params.last()
else formatParams.first() to ""
val lastParam = params.last()
val options = when (formatParam) {
"civName" -> console.gameInfo.civilizations.map { it.civName }
"unitName" -> console.gameInfo.ruleset.units.keys