Last active
March 7, 2016 16:42
-
-
Save abe33/5e4116a47b9b196f7760 to your computer and use it in GitHub Desktop.
Minimap Decorations Demo Commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
atom.packages.serviceHub.consume 'minimap', '1.0.0', (minimapAPI) -> | |
img = new Image() | |
img.src = 'file:///path/to/tile.png' | |
routine = (decoration, data) -> | |
range = decoration.getMarker().getScreenRange() | |
rowSpan = range.end.row - (range.start.row) | |
pattern = data.context.createPattern(img, 'repeat') | |
data.context.fillStyle = pattern# | |
if rowSpan == 0 | |
colSpan = range.end.column - (range.start.column) | |
data.context.fillRect range.start.column * data.charWidth, data.yRow, colSpan * data.charWidth, data.lineHeight | |
else if data.screenRow == range.start.row | |
x = range.start.column * data.charWidth | |
data.context.fillRect x, data.yRow, data.canvasWidth - x, data.lineHeight | |
else if data.screenRow == range.end.row | |
data.context.fillRect 0, data.yRow, range.end.column * data.charWidth, data.lineHeight | |
else | |
data.context.fillRect 0, data.yRow, data.canvasWidth, data.lineHeight | |
decorations = [] | |
clearDecorations = -> | |
decorations.forEach (d) -> d.destroy() | |
decorations.length = 0 | |
getCommand = (props) -> -> | |
e = atom.workspace.getActiveTextEditor() | |
m = minimapAPI.minimapForEditor(e) | |
b = 0 | |
for i in [0..4] | |
b += Math.round(Math.random() * 300) | |
start = b | |
b += Math.round(Math.random() * 300) | |
end = b | |
startPos = e.buffer.positionForCharacterIndex(start) | |
endPos = e.buffer.positionForCharacterIndex(end) | |
marker = e.markBufferRange([startPos, endPos], persistent: false, invalidate: 'touch') | |
decorations.push m.decorateMarker(marker, props) | |
img.onload = => | |
atom.commands.add 'atom-workspace', | |
'minimap:test-clean-decoration': clearDecorations | |
'minimap:test-foreground-custom-decoration': getCommand type: 'foreground-custom', render: routine | |
'minimap:test-background-custom-decoration': getCommand type: 'background-custom', render: routine | |
'minimap:test-highlight-over-decoration': getCommand type: 'highlight-over', color: 'rgba(255, 0, 0, 0.5)' | |
'minimap:test-highlight-under-decoration': getCommand type: 'highlight-under', color: 'rgba(255, 0, 0, 0.5)' | |
'minimap:test-line-decoration': getCommand type: 'line', color: 'rgba(255, 0, 0, 0.5)' | |
'minimap:test-outline-decoration': getCommand type: 'highlight-outline', color: 'rgba(255, 0, 0, 0.5)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment