Merge branch 'master' into snippets

This commit is contained in:
Nathan Sobo 2012-06-22 16:25:33 -06:00
commit 6389b19b7c
2 changed files with 16 additions and 7 deletions

View File

@ -740,6 +740,13 @@ describe "EditSession", ->
describe ".backspace()", -> describe ".backspace()", ->
describe "when there is a single cursor", -> describe "when there is a single cursor", ->
changeScreenRangeHandler = null
beforeEach ->
selection = editSession.getLastSelection()
changeScreenRangeHandler = jasmine.createSpy('changeScreenRangeHandler')
selection.on 'change-screen-range', changeScreenRangeHandler
describe "when the cursor is on the middle of the line", -> describe "when the cursor is on the middle of the line", ->
it "removes the character before the cursor", -> it "removes the character before the cursor", ->
editSession.setCursorScreenPosition(row: 1, column: 7) editSession.setCursorScreenPosition(row: 1, column: 7)
@ -750,6 +757,7 @@ describe "EditSession", ->
line = buffer.lineForRow(1) line = buffer.lineForRow(1)
expect(line).toBe " var ort = function(items) {" expect(line).toBe " var ort = function(items) {"
expect(editSession.getCursorScreenPosition()).toEqual {row: 1, column: 6} expect(editSession.getCursorScreenPosition()).toEqual {row: 1, column: 6}
expect(changeScreenRangeHandler).toHaveBeenCalled()
describe "when the cursor is at the beginning of a line", -> describe "when the cursor is at the beginning of a line", ->
it "joins it with the line above", -> it "joins it with the line above", ->
@ -764,9 +772,10 @@ describe "EditSession", ->
line1 = buffer.lineForRow(1) line1 = buffer.lineForRow(1)
expect(line0).toBe "var quicksort = function () { var sort = function(items) {" expect(line0).toBe "var quicksort = function () { var sort = function(items) {"
expect(line1).toBe " if (items.length <= 1) return items;" expect(line1).toBe " if (items.length <= 1) return items;"
expect(editSession.getCursorScreenPosition()).toEqual [0, originalLine0.length] expect(editSession.getCursorScreenPosition()).toEqual [0, originalLine0.length]
expect(changeScreenRangeHandler).toHaveBeenCalled()
describe "when the cursor is at the first column of the first line", -> describe "when the cursor is at the first column of the first line", ->
it "does nothing, but doesn't raise an error", -> it "does nothing, but doesn't raise an error", ->
editSession.setCursorScreenPosition(row: 0, column: 0) editSession.setCursorScreenPosition(row: 0, column: 0)

View File

@ -164,10 +164,9 @@ class Selection
includeNewline = bufferRange.start.column == 0 or bufferRange.start.row >= fold.startRow includeNewline = bufferRange.start.column == 0 or bufferRange.start.row >= fold.startRow
bufferRange = bufferRange.union(fold.getBufferRange({ includeNewline })) bufferRange = bufferRange.union(fold.getBufferRange({ includeNewline }))
@editSession.buffer.delete(bufferRange) unless bufferRange.isEmpty() @modifyScreenRange =>
if @cursor @editSession.buffer.delete(bufferRange) unless bufferRange.isEmpty()
@cursor.setBufferPosition(bufferRange.start) @cursor?.setBufferPosition(bufferRange.start)
@clear()
indentSelectedRows: -> indentSelectedRows: ->
range = @getBufferRange() range = @getBufferRange()
@ -222,8 +221,9 @@ class Selection
modifyScreenRange: (fn) -> modifyScreenRange: (fn) ->
oldScreenRange = @getScreenRange() oldScreenRange = @getScreenRange()
fn() fn()
newScreenRange = @getScreenRange() if @cursor
@trigger 'change-screen-range', newScreenRange unless oldScreenRange.isEqual(newScreenRange) newScreenRange = @getScreenRange()
@trigger 'change-screen-range', newScreenRange unless oldScreenRange.isEqual(newScreenRange)
placeAnchor: -> placeAnchor: ->
@anchor = @editSession.addAnchor() @anchor = @editSession.addAnchor()