Skip to content

Commit

Permalink
Update syntax of TabCloseHandler.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPl292 committed Jul 16, 2020
1 parent bd9c40a commit 26aa753
Showing 1 changed file with 19 additions and 55 deletions.
74 changes: 19 additions & 55 deletions src/com/maddyhome/idea/vim/ex/handler/TabCloseHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,87 +71,51 @@ class TabCloseHandler : CommandHandler.SingleExecution() {
*/
private fun getTabIndexToClose(arg: String, current: Int, last: Int): Int? {

if (arg.isEmpty()) {
return current
}

if (last < 0) {
return null
}
if (arg.isEmpty()) return current
if (last < 0) return null

val sb = StringBuilder()
var sign = Char.MIN_VALUE
var end = false

for (c in arg) {
when {
c in '0'..'9' && !end -> {
sb.append(c)
}
c in '0'..'9' && !end -> sb.append(c)

(c == '-' || c == '+') && !end && sb.isEmpty() && sign == Char.MIN_VALUE -> {
sign = c
}
(c == '-' || c == '+') && !end && sb.isEmpty() && sign == Char.MIN_VALUE -> sign = c

c == '$' && sb.isEmpty() && sign == Char.MIN_VALUE -> {
end = true
}
c == '$' && sb.isEmpty() && sign == Char.MIN_VALUE -> end = true

c == ' ' -> {
//ignore
}
else -> return null

else -> return null
}
}


val idxStr = sb.toString()

val index = when {
end -> {
last
}
sb.isEmpty() -> {
end -> last

idxStr.isEmpty() -> {
when (sign) {
'+' -> {
current + 1
}
'-' -> {
current - 1
}
else -> {
current
}
'+' -> current + 1
'-' -> current - 1
else -> current
}
}

else -> {
try {
val idx = Integer.valueOf(idxStr)
when (sign) {
'+' -> {
current + idx
}

'-' -> {
current - idx
}

else -> {
idx
}

}
} catch (e: NumberFormatException) {
return null
val idx = idxStr.toIntOrNull() ?: return null
when (sign) {
'+' -> current + idx
'-' -> current - idx
else -> idx
}
}
}
if (index < 0) return 0
if (index > last) return last
return index

return index.coerceIn(0, last)
}


}

0 comments on commit 26aa753

Please sign in to comment.