Skip to content

Commit

Permalink
Implement decoration management in minimap model
Browse files Browse the repository at this point in the history
The biggest change so far is that changes are not stacked in the model
but emitted as events.
  • Loading branch information
abe33 committed Dec 12, 2014
1 parent e65d23f commit f6181c9
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
17 changes: 16 additions & 1 deletion lib/minimap.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
{CompositeDisposable} = require 'event-kit'
{Emitter, CompositeDisposable} = require 'event-kit'
DecorationManagement = require './mixins/decoration-management'

module.exports =
class Minimap
DecorationManagement.includeInto(this)

constructor: ({@textEditor}) ->
@emitter = new Emitter
@subscriptions = new CompositeDisposable
@subscribeToConfig()
@initializeDecorations()

onDidChangeScreenLines: (callback) ->
@emitter.on 'did-change-screen-lines', callback

getTextEditor: -> @textEditor

Expand Down Expand Up @@ -34,6 +42,13 @@ class Minimap

canScroll: -> @getMinimapMaxScrollTop() > 0

getMarker: (id) -> @textEditor.getMarker(id)

markBufferRange: (range) -> @textEditor.markBufferRange(range)

stackChanges: (changes) ->
@emitter.emit('did-change-screen-lines', changes)

subscribeToConfig: ->
@subscriptions.add atom.config.observe 'minimap.charHeight', (@charHeight) =>
@subscriptions.add atom.config.observe 'minimap.charWidth', (@charWidth) =>
Expand Down
61 changes: 60 additions & 1 deletion spec/minimap-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,63 @@ describe 'Minimap', ->
expect(minimap.getFirstVisibleScreenRow()).toEqual(largeLineCount - 10)

it 'computes the last visible row in the minimap', ->
expect(minimap.getLastVisibleRow()).toEqual(largeLineCount)
expect(minimap.getLastVisibleScreenRow()).toEqual(largeLineCount)

# ######## ######## ###### #######
# ## ## ## ## ## ## ##
# ## ## ## ## ## ##
# ## ## ###### ## ## ##
# ## ## ## ## ## ##
# ## ## ## ## ## ## ##
# ######## ######## ###### #######

describe '::decorateMarker', ->
[marker, decoration, changeSpy] = []

beforeEach ->
changeSpy = jasmine.createSpy('didChangeScreenLines')
minimap.onDidChangeScreenLines(changeSpy)

marker = minimap.markBufferRange [[0,6], [0,11]]
decoration = minimap.decorateMarker marker, type: 'highlight', class: 'dummy'

it 'creates a decoration for the given marker', ->
expect(minimap.decorationsByMarkerId[marker.id]).toBeDefined()

it 'creates a change corresponding to the marker range', ->
expect(changeSpy).toHaveBeenCalled()
expect(changeSpy.calls[0].args[0].start).toEqual(0)
expect(changeSpy.calls[0].args[0].end).toEqual(0)

describe 'destroying the marker', ->
beforeEach ->
marker.destroy()

it 'removes the decoration from the render view', ->
expect(minimap.decorationsByMarkerId[marker.id]).toBeUndefined()

it 'creates a change corresponding to the marker range', ->
expect(changeSpy.calls[1].args[0].start).toEqual(0)
expect(changeSpy.calls[1].args[0].end).toEqual(0)

describe 'destroying the decoration', ->
beforeEach ->
decoration.destroy()

it 'removes the decoration from the render view', ->
expect(minimap.decorationsByMarkerId[marker.id]).toBeUndefined()

it 'creates a change corresponding to the marker range', ->
expect(changeSpy.calls[1].args[0].start).toEqual(0)
expect(changeSpy.calls[1].args[0].end).toEqual(0)

describe 'destroying all the decorations for the marker', ->
beforeEach ->
minimap.removeAllDecorationsForMarker(marker)

it 'removes the decoration from the render view', ->
expect(minimap.decorationsByMarkerId[marker.id]).toBeUndefined()

it 'creates a change corresponding to the marker range', ->
expect(changeSpy.calls[1].args[0].start).toEqual(0)
expect(changeSpy.calls[1].args[0].end).toEqual(0)

0 comments on commit f6181c9

Please sign in to comment.