diff --git a/spec/display-buffer-spec.coffee b/spec/display-buffer-spec.coffee index 51a6d8429..a75f7a91e 100644 --- a/spec/display-buffer-spec.coffee +++ b/spec/display-buffer-spec.coffee @@ -1040,29 +1040,36 @@ describe "DisplayBuffer", -> expect(start.left).toBe (4 * 10) + (6 * 11) describe "decorations", -> - it "can add decorations associated with markers and remove them", -> - decoration = {type: 'gutter', class: 'one'} + [marker, decoration, decorationParams] = [] + beforeEach -> marker = displayBuffer.markBufferRange([[2, 13], [3, 15]]) + decorationParams = {type: 'gutter', class: 'one'} + decoration = displayBuffer.decorateMarker(marker, decorationParams) - decorationObject = displayBuffer.decorateMarker(marker, decoration) - expect(decorationObject).toBeDefined() - expect(decorationObject.getParams()).toBe decoration - expect(displayBuffer.decorationForId(decoration.id)).toBe decorationObject - expect(displayBuffer.decorationsForScreenRowRange(2, 3)[marker.id][0]).toBe decorationObject + it "can add decorations associated with markers and remove them", -> + expect(decoration).toBeDefined() + expect(decoration.getParams()).toBe decoration + expect(displayBuffer.decorationForId(decoration.id)).toBe decoration + expect(displayBuffer.decorationsForScreenRowRange(2, 3)[marker.id][0]).toBe decoration - decorationObject.destroy() + decoration.destroy() expect(displayBuffer.decorationsForScreenRowRange(2, 3)[marker.id]).not.toBeDefined() expect(displayBuffer.decorationForId(decoration.id)).not.toBeDefined() it "will not fail if the decoration is removed twice", -> - decoration = {type: 'gutter', class: 'one'} - marker = displayBuffer.markBufferRange([[2, 13], [3, 15]]) - decorationObject = displayBuffer.decorateMarker(marker, decoration) - - decorationObject.destroy() - decorationObject.destroy() + decoration.destroy() + decoration.destroy() expect(displayBuffer.decorationForId(decoration.id)).not.toBeDefined() + describe "when a decoration is updated via Decoration::update()", -> + it "emits an 'updated' event containing the new and old params", -> + decoration.on 'updated', updatedSpy = jasmine.createSpy() + decoration.update type: 'gutter', class: 'two' + + {oldParams, newParams} = updatedSpy.mostRecentCall.args[0] + expect(oldParams).toEqual decorationParams + expect(newParams).toEqual type: 'gutter', class: 'two', id: decoration.id + describe "::setScrollTop", -> beforeEach -> displayBuffer.manageScrollPosition = true diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index 6858af29d..626f92079 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -973,7 +973,7 @@ describe "EditorComponent", -> regions = node.querySelectorAll('.test-highlight .region') expect(regions.length).toBe 2 - describe "flashing a decoration via the Decoration::flash()", -> + describe "when flashing a decoration via Decoration::flash()", -> highlightNode = null beforeEach -> highlightNode = node.querySelector('.test-highlight') @@ -1029,6 +1029,16 @@ describe "EditorComponent", -> regionStyle = node.querySelector('.test-highlight .region').style expect(parseInt(regionStyle.top)).toBe 5 * lineHeightInPixels + describe "when a decoration is updated via Decoration::update", -> + it "renders the decoration's new params", -> + expect(node.querySelector('.test-highlight')).toBeTruthy() + + decoration.update(type: 'highlight', class: 'new-test-highlight') + runSetImmediateCallbacks() + + expect(node.querySelector('.test-highlight')).toBeFalsy() + expect(node.querySelector('.new-test-highlight')).toBeTruthy() + describe "hidden input field", -> it "renders the hidden input field at the position of the last cursor if the cursor is on screen and the editor is focused", -> editor.setVerticalScrollMargin(0) diff --git a/src/decoration.coffee b/src/decoration.coffee index d7289cd04..6b7bf21f6 100644 --- a/src/decoration.coffee +++ b/src/decoration.coffee @@ -24,7 +24,11 @@ class Decoration @emit 'destoryed' update: (newParams) -> - # TODO: implement + oldParams = @params + @params = newParams + @params.id = @id + @displayBuffer.decorationUpdated(this) + @emit 'updated', {oldParams, newParams} getParams: -> @params diff --git a/src/display-buffer.coffee b/src/display-buffer.coffee index 6ce6e4455..fa63c14d5 100644 --- a/src/display-buffer.coffee +++ b/src/display-buffer.coffee @@ -814,6 +814,9 @@ class DisplayBuffer extends Model delete @decorationMarkerChangedSubscriptions[marker.id] delete @decorationMarkerDestroyedSubscriptions[marker.id] + decorationUpdated: (decoration) -> + @emit 'decoration-updated', decoration + # Retrieves a {DisplayBufferMarker} based on its id. # # id - A {Number} representing a marker id diff --git a/src/editor-component.coffee b/src/editor-component.coffee index 53a3b79c9..bacaf4cdb 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -332,6 +332,7 @@ EditorComponent = React.createClass @subscribe editor, 'decoration-added', @onDecorationChanged @subscribe editor, 'decoration-removed', @onDecorationChanged @subscribe editor, 'decoration-changed', @onDecorationChanged + @subscribe editor, 'decoration-updated', @onDecorationChanged @subscribe editor, 'character-widths-changed', @onCharacterWidthsChanged @subscribe editor.$scrollTop.changes, @onScrollTopChanged @subscribe editor.$scrollLeft.changes, @requestUpdate diff --git a/src/editor.coffee b/src/editor.coffee index e797fbb9d..a8840bb6b 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -219,6 +219,7 @@ class Editor extends Model @subscribe @displayBuffer, "decoration-added", (args...) => @emit 'decoration-added', args... @subscribe @displayBuffer, "decoration-removed", (args...) => @emit 'decoration-removed', args... @subscribe @displayBuffer, "decoration-changed", (args...) => @emit 'decoration-changed', args... + @subscribe @displayBuffer, "decoration-updated", (args...) => @emit 'decoration-updated', args... @subscribe @displayBuffer, "character-widths-changed", (changeCount) => @emit 'character-widths-changed', changeCount getViewClass: ->