fun findBoundsAt()

in src/main/java/com/maddyhome/idea/vim/extension/argtextobj/VimArgTextObjExtension.kt [170:223]


  fun findBoundsAt(position: Int): Boolean {
    if (text.isEmpty()) {
      error = "empty document"
      return false
    }
    leftBound = min(position, leftBound)
    rightBound = max(position, rightBound)
    this.outOfQuotedText
    if (rightBound == leftBound) {
      if (brackets.isCloseBracket(getCharAt(rightBound).code)) {
        --leftBound
      } else {
        ++rightBound
      }
    }
    var nextLeft = leftBound
    var nextRight = rightBound
    val leftLimit = leftLimit(position)
    val rightLimit = rightLimit(position)
    //
    // Try to extend the bounds until one of the bounds is a comma.
    // This handles cases like: fun(a, (30 + <cursor>x) * 20, c)
    //
    var bothBrackets: Boolean
    do {
      leftBracket = nextLeft
      rightBracket = nextRight
      if (!findOuterBrackets(leftLimit, rightLimit)) {
        error = "not inside argument list"
        return false
      }
      leftBound = nextLeft
      findLeftBound()
      nextLeft = leftBound - 1
      rightBound = nextRight
      findRightBound()
      nextRight = rightBound + 1
      //
      // If reached text boundaries
      //
      if (nextLeft < leftLimit || nextRight > rightLimit) {
        error = "not an argument"
        return false
      }
      bothBrackets = getCharAt(leftBound) != ',' && getCharAt(rightBound) != ','
      val nonEmptyArg = (rightBound - leftBound) > 1
      if (bothBrackets && nonEmptyArg && this.isIdentPreceding) {
        // Looking at a pair of brackets preceded by an
        // identifier -- single argument function call.
        break
      }
    } while (leftBound > leftLimit && rightBound < rightLimit && bothBrackets)
    return true
  }