       row
 
 class MoveUp extends MoveVertically
-  nextValidRow: (count) ->
-    @nextValidRowWithIncrement(count, -1)
+  # Internal: The direction to move the cursor. Use -1
+  # for moving up, 1 for moving down.
+  #
+  # Returns -1
+  directionIncrement: ->
+    -1
 
   select: (count=1) ->
     _.times count, =>


class MoveVertically extends Motion
  execute: (count=1) ->
    {row, column} = @editor.getCursorScreenPosition()

    nextRow = @nextValidRow(count)


  #
  # count - The number of folded 'buffer' rows away from
  #         the current row.
  #
  # Returns an integer row index.
  nextValidRow: (count) ->
    {row, column} = @editor.getCursorBufferPosition()

    maxRow = @editor.getLastBufferRow()
    minRow = 0

    # For each count, add 1 'directionIncrement' to
    # row. Folded rows count as a single row.
    _.times count, =>
      if @editor.isFoldedAtBufferRow(row)
        while @editor.isFoldedAtBufferRow(row)
          row += @directionIncrement()
      else
        row += @directionIncrement()

    if row > maxRow
      maxRow
