enjalot / Inlet

Bret Victor inspired slider & color picker plugin for CodeMirror
http://enjalot.github.com/Inlet
Other
74 stars 11 forks source link

Hover previews (image, color, etc:) #30

Closed michaelsboost closed 8 years ago

michaelsboost commented 8 years ago

Any idea on how to add hover event previews?

Best example I can give is when you hover over an image tag in html or say a background image in css. The image will show in a preview.

Brackets and Dabblet have this feature integrated if you want to see it in action.

georules commented 8 years ago

Right now, the core of inlet works by finding the location of the cursor https://github.com/enjalot/Inlet/blob/ed840d98625f418f0ac01df869d3db06e30c56df/src/inlet.js#L186 in the onclick function https://github.com/enjalot/Inlet/blob/ed840d98625f418f0ac01df869d3db06e30c56df/src/inlet.js#L178 fired by mouseup https://github.com/enjalot/Inlet/blob/ed840d98625f418f0ac01df869d3db06e30c56df/src/inlet.js#L32

matching for URLs and determining a preview for images shouldn't be too hard to add similar to these click events. I am more inclined to like the idea of needing a click than hovers so that you don't accidentally cover code when you move your mouse around (and hovers are not mobile friendly), but I do like the demo you posted.

You can attach a mouseover handler to any element in the editor, but we need to know what is under the hovering mouse, and if it's something to preview. One idea:

michaelsboost commented 8 years ago

I was playing with this idea for a bit today: http://kodeweave.sourceforge.net/editor/#f5643481378a470cd08ea0d848319883

Not the best solution, but something to work with encase anyone wants to go further with integration.

Basically when you hover over .CodemIrror-lines it searches the string in line to see if it has a color value, if it does color is displayed, and the same goes for if the string contains an image.

NOTE: .Codemirror-lines is a pre tag which in Codemirror is a display block element so when hovered on the far right your color/image will still show.

Here's a preview.
editor previewer

georules commented 8 years ago

This is awesome. My only comment is that we might want to handle multiple colors on one line (I don't think this is too uncommon when doing datavis programming)

michaelsboost commented 8 years ago

That's very common in CSS. Especially when working with gradients.

background: radial-gradient(ellipse at center,  rgba(255,255,255,1) 0%, #827bd1 100%);

but also would have to handle images and colors on the same line too.

background: url("http://i.imgbox.com/GR1ChmDu.png"), radial-gradient(ellipse at center,  rgba(255,255,255,1) 0%, #d179ca 100%);