bkbooth / color-gutter

Show color swatches in the atom.io gutter
MIT License
12 stars 4 forks source link

Commented lines aren't being found on first load #7

Open bkbooth opened 10 years ago

bkbooth commented 10 years ago

From https://discuss.atom.io/t/editor-isbufferrowcommented-not-working-on-first-load/11308/2?u=bkbooth

This method relies on tokens, which are created asynchronously, hence the issue if your code try to know if a line is commented before the tokenized buffer have been completely initialized.

# atom/atom/blob/master/src/editor.coffee#L473-L476
isBufferRowCommented: (bufferRow) ->
  if match = @lineForBufferRow(bufferRow).match(/\S/)
    scopes = @tokenForBufferPosition([bufferRow, match.index]).scopes
    new TextMateScopeSelector('comment.*').matches(scopes)

You should try to hook onto the tokenized event on the displayBuffer of the editor prior to any access to methods that uses tokens.