       if match[1]
         unpairedCount--
         if unpairedCount < 0
-          startRange = range.translate([0, 1], [0, -match[2].length]) # Subtract < and tag name suffix from range
+          startRange = range.translate([0, 1], [0, -(match[2].length + match[3].length)]) # Subtract < and tag name suffix from range
+          until startRange.end.column > 0 # if the tag spans multiple lines, the end.column is negative, so iterate until it's not.
+            startRange.end.row -= 1 # move the end up one row
+            startRange.end.column = @editor.getBuffer().lineLengthForRow(startRange.end.row) + startRange.end.column + 2 # and set the column
           stop()
       else
         unpairedCount++

  findEnclosingTags: ->
    if ranges = @findStartEndTags()
      if @isTagRange(ranges.startRange) and @isTagRange(ranges.endRange)
        return ranges

    null

module.exports =
class TagFinder
  constructor: (@editor) ->
    @tagPattern = /(<(\/?))([^\/\s>]+)((?:[^\/>]|[^>](?!>))*)(\/?)(>)/
    @wordRegex = /(?!$)[^>]*>/
    @tagSelector = SelectorCache.get('meta.tag | punctuation.definition.tag')
    @commentSelector = SelectorCache.get('comment.*')

  patternForTagName: (tagName) ->
    tagName = _.escapeRegExp(tagName)
    new RegExp("(<#{tagName}((?:[^\/>]|[^>](?!>))*)(>))|(<\/#{tagName}>)", 'gi')

  isRangeCommented: (range) ->
    scopes = @editor.scopeDescriptorForBufferPosition(range.start).getScopesArray()
