From e2efa95d1370161faff1bfb16899da21bd22fa30 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 22 Jun 2012 16:07:08 -0600 Subject: [PATCH] Ensure that 'change-screen-range' events are triggered on selections by backspace --- spec/app/edit-session-spec.coffee | 11 ++++++++++- src/app/selection.coffee | 12 ++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 5031eb9ba..0ae037450 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -740,6 +740,13 @@ describe "EditSession", -> describe ".backspace()", -> 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", -> it "removes the character before the cursor", -> editSession.setCursorScreenPosition(row: 1, column: 7) @@ -750,6 +757,7 @@ describe "EditSession", -> line = buffer.lineForRow(1) expect(line).toBe " var ort = function(items) {" expect(editSession.getCursorScreenPosition()).toEqual {row: 1, column: 6} + expect(changeScreenRangeHandler).toHaveBeenCalled() describe "when the cursor is at the beginning of a line", -> it "joins it with the line above", -> @@ -764,9 +772,10 @@ describe "EditSession", -> line1 = buffer.lineForRow(1) expect(line0).toBe "var quicksort = function () { var sort = function(items) {" expect(line1).toBe " if (items.length <= 1) return items;" - expect(editSession.getCursorScreenPosition()).toEqual [0, originalLine0.length] + expect(changeScreenRangeHandler).toHaveBeenCalled() + describe "when the cursor is at the first column of the first line", -> it "does nothing, but doesn't raise an error", -> editSession.setCursorScreenPosition(row: 0, column: 0) diff --git a/src/app/selection.coffee b/src/app/selection.coffee index 2569a3a27..8385959d5 100644 --- a/src/app/selection.coffee +++ b/src/app/selection.coffee @@ -164,10 +164,9 @@ class Selection includeNewline = bufferRange.start.column == 0 or bufferRange.start.row >= fold.startRow bufferRange = bufferRange.union(fold.getBufferRange({ includeNewline })) - @editSession.buffer.delete(bufferRange) unless bufferRange.isEmpty() - if @cursor - @cursor.setBufferPosition(bufferRange.start) - @clear() + @modifyScreenRange => + @editSession.buffer.delete(bufferRange) unless bufferRange.isEmpty() + @cursor?.setBufferPosition(bufferRange.start) indentSelectedRows: -> range = @getBufferRange() @@ -222,8 +221,9 @@ class Selection modifyScreenRange: (fn) -> oldScreenRange = @getScreenRange() fn() - newScreenRange = @getScreenRange() - @trigger 'change-screen-range', newScreenRange unless oldScreenRange.isEqual(newScreenRange) + if @cursor + newScreenRange = @getScreenRange() + @trigger 'change-screen-range', newScreenRange unless oldScreenRange.isEqual(newScreenRange) placeAnchor: -> @anchor = @editSession.addAnchor()