How to make my package's markers stand out?


#1

Is there any way to add decorated markers that stand out from all the others, or at least doesn’t create an unreadable mess when combined with them?

One way would be to have a button in my package that when selected hides all other markers (or decorators) in the editor and then shows my markers instead. Then turning off that button will hide mine and re-enable all the others. This would make my markers stand out temporarily.

I’m hoping there is an easier/cleaner way than going through the DOM and setting display:none on the other markers. For my own markers I can create and destroy them.

I was hoping to find a marker::hide method but I’ve had no luck. I’ve scoured many atom source files.

I will look into removing decorations from markers, saving them, and then restoring them. Decorators are objects but I’m guessing this isn’t going to be possible.


#2

Not tested, but something like this might work

for marker in editor.getMarkers()
  decoration = editor.decorationForId(marker.id)
  continue unless decoration?

  {class} = decoration.getParams()
  decoration.update({class: "hidden #{class}"})

Haven’t got time to check if it actually works as intended, but it should at least give you an idea of how to do it without having to destroy any markers or decorations. If you only want to alter the visibility of some types of decorations, e.g. gutter decorations, swap the getMarkers function call with something like

for marker in editor.findMarkers({type: "gutter"})
  # ...

#3

Why not simply putting a specific class on your markers, so that you can use a :not() rule to match every other markers?


#4

I kind of feel like disabling another package’s decorations, even temporarily, is being a bad citizen.

You could use my red-wavy-underline package to use a red wavy underline for your markers rather than a colored border or underline like most decorations. You could also use a CSS animation to make your decoration pulse or flash.

I think there are plenty of options that don’t mean messing with the operation of anyone else’s package.


#5

Wow, some good quick answers here.

@thomasjo: Thanks for the code and your trouble. Looks like it does what I asked for,

@abe: That seems too easy. I’ll give it a try.

@leedohm: I was wondering about the ethics. However, if the user hits a button in my app that temporarily hides other markers then that is their choice not mine. I understand that I have a lot of highlighting options but I would have to upgrade my CSS as other packages come out and users bitch. I’ve bitched once already to another package that showed stuff in the minimap that wasn’t visible. In any case I could do this first and cross my fingers.

When I first saw the decorations docs I thought “how will everyone co-exist?”


#6

I forgot to mention that this is not a normal text editor tab. It is a history view that you don’t edit but will still have all the editing features like syntax coloring. So the normal ethics may not apply.

The particular decorations that caused me trouble were all the instances of a variable being highlighted when the cursor is in the variable. But this feature is useful when reading my history page.

P.S. Does anyone else snicker when this discussion software says “Do you want to abandon your post?” I wonder if that was intentional.


#7

Personally I think it’s ok to change the others, as long as you do it right :smile: