 # -------------------------
 class Pair extends TextObject
   @extend(false)
-
-  _newStyle: true # REMOVE after rewrite DONE
-
   allowNextLine: false
   adjustInnerRange: true
   pair: null


  getPairInfo: (from) ->
    pairInfo = null
    if @_newStyle
      closeRange = @findClose(from)
      openRange = @findOpen(closeRange.end) if closeRange?
    else
      pattern = @getPattern()
      closeRange = @findClose(from, pattern)
      openRange = @findOpen(closeRange.end, pattern) if closeRange?

    unless (openRange? and closeRange?)
      return null

  getLineTextToBufferPosition
} = require './utils'

getRuleForPair = (editor, pair) ->
  [open, close] = pair

  if open is close
    pattern = ///(#{_.escapeRegExp(open)})///g
    getPairState = (event) ->
      pairStateInBufferRange(editor, event)

  else
    pattern = ///(#{_.escapeRegExp(open)})|(#{_.escapeRegExp(close)})///g
    getPairState = ({match}) ->
      switch
        when match[1] then 'open'
        when match[2] then 'close'

  {pattern, getPairState}

findPairRange = (options, fn) ->
  {editor, from, pair, which, direction, filters, allowNextLine} = options
  switch direction
    when 'forward'
      scanRange = new Range(from, editor.buffer.getEndPosition())
      scanFunctionName = 'scanInBufferRange'
    when 'backward'
      scanRange = new Range([0, 0], from)
      scanFunctionName = 'backwardsScanInBufferRange'

  stack = []
  range = null
  {pattern, getPairState} = getRuleForPair(editor, pair)
  editor[scanFunctionName] pattern, scanRange, (event) ->
    if not allowNextLine and (from.row isnt event.range.start.row)
      event.stop()
      return
