Skip to content

Commit

Permalink
Implement highlight update on palette refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Jun 3, 2014
1 parent 5d22b9e commit a0aa45f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/atom-color-highlight-model.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
_ = require 'underscore-plus'
{Emitter} = require 'emissary'
{Emitter, Subscriber} = require 'emissary'
{OnigRegExp} = require 'oniguruma'
Color = require 'pigments'

module.exports =
class AtomColorHighlightModel
Emitter.includeInto(this)
Subscriber.includeInto(this)

@Color: Color

Expand All @@ -14,7 +15,11 @@ class AtomColorHighlightModel

constructor: (@editor, @buffer) ->
finder = atom.packages.getLoadedPackage('project-palette-finder')
Color = require(finder.path).constructor.Color if finder?
if finder?
module = require(finder.path)
Color = module.constructor.Color
@subscribe module, 'palette:ready', @update

@constructor.Color = Color

update: =>
Expand All @@ -26,10 +31,10 @@ class AtomColorHighlightModel
@updateMarkers()

subscribeToBuffer: ->
@buffer.on 'contents-modified', @update
@subscribe @buffer, 'contents-modified', @update

unsubscribeFromBuffer: ->
@buffer.off 'contents-modified', @update
@unsubscribe @buffer, 'contents-modified', @update
@buffer = null

init: ->
Expand All @@ -39,8 +44,8 @@ class AtomColorHighlightModel
@update()

dispose: ->
if @buffer?
@unsubscribeFromBuffer()
@unsubscribe()
@unsubscribeFromBuffer() if @buffer?

eachColor: (block) ->
return Color.scanBufferForColors(@buffer, block) if @buffer?
Expand Down
2 changes: 2 additions & 0 deletions spec/other_sample.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

other_red = stylus_red

0 comments on commit a0aa45f

Please sign in to comment.