mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Scan buffer to remove trailing whitespace
This commit is contained in:
@@ -3414,7 +3414,7 @@ describe "TextEditor", ->
|
||||
it "joins the line below with the current line separated by a space and moves the cursor to the start of line that was moved up", ->
|
||||
editor.joinLines()
|
||||
expect(editor.lineTextForBufferRow(0)).toBe 'var quicksort = function () { var sort = function(items) {'
|
||||
expect(editor.getCursorBufferPosition()).toEqual [0, 30]
|
||||
expect(editor.getCursorBufferPosition()).toEqual [0, 29]
|
||||
|
||||
describe "when the line below is empty", ->
|
||||
it "deletes the line below and moves the cursor to the end of the line", ->
|
||||
|
||||
@@ -476,25 +476,37 @@ class Selection extends Model
|
||||
for row in [0...rowCount]
|
||||
@cursor.setBufferPosition([selectedRange.start.row])
|
||||
@cursor.moveToEndOfLine()
|
||||
|
||||
# Remove traing whitespace from line
|
||||
scanRange = @cursor.getCurrentLineBufferRange()
|
||||
trailingWhitespaceRange = null
|
||||
@editor.scanInBufferRange /[ \t]+$/, scanRange, ({range}) ->
|
||||
trailingWhitespaceRange = range
|
||||
if trailingWhitespaceRange?
|
||||
@setBufferRange(trailingWhitespaceRange)
|
||||
@deleteSelectedText()
|
||||
|
||||
nextRow = selectedRange.start.row + 1
|
||||
if nextRow <= @editor.buffer.getLastRow() and @editor.buffer.lineLengthForRow(nextRow) > 0
|
||||
insertSpace = nextRow <= @editor.buffer.getLastRow() and
|
||||
@editor.buffer.lineLengthForRow(nextRow) > 0 and
|
||||
@editor.buffer.lineLengthForRow(selectedRange.start.row) > 0
|
||||
|
||||
if insertSpace
|
||||
@insertText(' ')
|
||||
@cursor.moveToEndOfLine()
|
||||
@selectToPreviousWordBoundary()
|
||||
@deleteSelectedText()
|
||||
@modifySelection =>
|
||||
@cursor.moveRight()
|
||||
@cursor.moveToFirstCharacterOfLine()
|
||||
@deleteSelectedText()
|
||||
@insertText(' ')
|
||||
|
||||
@modifySelection =>
|
||||
@cursor.moveRight()
|
||||
@cursor.moveToFirstCharacterOfLine()
|
||||
@deleteSelectedText()
|
||||
|
||||
@cursor.moveLeft() if insertSpace
|
||||
|
||||
if joinMarker?
|
||||
newSelectedRange = joinMarker.getBufferRange()
|
||||
@setBufferRange(newSelectedRange)
|
||||
joinMarker.destroy()
|
||||
|
||||
@cursor.moveLeft()
|
||||
|
||||
# Public: Removes one level of indent from the currently selected rows.
|
||||
outdentSelectedRows: ->
|
||||
[start, end] = @getBufferRowRange()
|
||||
|
||||
Reference in New Issue
Block a user