- range = selection.cursor.getCurrentParagraphBufferRange()
- if range?
- selection.setBufferRange(range)
- selection.selectToBeginningOfNextParagraph()
- selection.selectDown()
- true
-
-module.exports = {TextObject, SelectInsideWord, SelectInsideQuotes, SelectInsideBrackets, SelectAWord, SelectInsideParagraph, SelectAParagraph}
+ @selectParagraph(selection)
+
+ # Return a range delimted by the start or the end of a paragraph
+ paragraphDelimitedRange: (startPoint) ->
+ inParagraph = @isParagraphLine(@editor.lineTextForBufferRow(startPoint.row))
+ upperRow = @searchLines(startPoint.row, -1, inParagraph)
+ lowerRow = @searchLines(startPoint.row, @editor.getLineCount(), inParagraph)
+ new Range([upperRow + 1, 0], [lowerRow, 0])
+
+ searchLines: (startRow, rowLimit, startedInParagraph) ->
+ for currentRow in [startRow..rowLimit]
+ line = @editor.lineTextForBufferRow(currentRow)
+ if startedInParagraph isnt @isParagraphLine(line)
+ return currentRow
+ rowLimit
+
+ isParagraphLine: (line) -> (/\S/.test(line))
+
+class SelectInsideParagraph extends Paragraph
+ selectParagraph: (selection) ->
+ oldRange = selection.getBufferRange()
+ startPoint = selection.cursor.getBufferPosition()
+ newRange = @paragraphDelimitedRange(startPoint)
+ selection.setBufferRange(mergeRanges(oldRange, newRange))
+ true
+
+class SelectAParagraph extends Paragraph
+ selectParagraph: (selection) ->
+ oldRange = selection.getBufferRange()
+ startPoint = selection.cursor.getBufferPosition()
+ newRange = @paragraphDelimitedRange(startPoint)
+ nextRange = @paragraphDelimitedRange(newRange.end)
+ selection.setBufferRange(mergeRanges(oldRange, [newRange.start, nextRange.end]))
+ true
+
+module.exports = {TextObject, SelectInsideWord, SelectInsideWholeWord, SelectInsideQuotes,
+ SelectInsideBrackets, SelectAWord, SelectAWholeWord, SelectInsideParagraph, SelectAParagraph}