Created
April 26, 2015 13:52
-
-
Save aloncarmel/6c85431a36f8dcdbc1c8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
AtomAdapter.prototype.setOtherCursor = function(cursor, color, clientId) { | |
var clazz, css, cursorRange, end, justCursor, start, _ref, | |
_this = this; | |
if (this.otherCursors == null) { | |
this.otherCursors = {}; | |
} | |
cursorRange = this.otherCursors[clientId]; | |
if (cursorRange) { | |
cursorRange.selection.clear(); | |
editor = atom.workspace.getActiveEditor() | |
curs = editor.getCursors(); | |
for (i=0;curs.length > 0;i++) { | |
curs[i].destroy() | |
} | |
} | |
start = this.posFromIndex(cursor.position); | |
end = this.posFromIndex(cursor.selectionEnd); | |
if (cursor.selectionEnd < cursor.position) { | |
_ref = [end, start], start = _ref[0], end = _ref[1]; | |
} | |
clazz = "other-client-selection-" + (color.replace('#', '')); | |
justCursor = cursor.position === cursor.selectionEnd; | |
if (justCursor) { | |
end.column += 1; | |
clazz = clazz.replace('selection', 'cursor'); | |
} | |
css = ".atom-text-editor ."+clazz+", atom-text-editor::shadow ."+clazz+" {\n position: absolute;\n z-index:1; background: " + (justCursor ? 'transparent' : color) + ";\n border-left: 2px solid " + color + ";\n}"; | |
this.addStyleRule(css); | |
this.otherCursors[clientId] = cursorRange = new Range([start.row, start.column], [end.row, end.column]); | |
//cursorRange.start = new Point(start.row, start.column); | |
//cursorRange.end = new Point(end.row,end.column); | |
cursorRange.id = this.atom.markBufferRange(cursorRange); | |
cursorRange.cursor = cursor; | |
cursorRange.decoration = this.atom.decorateMarker(cursorRange.id, {type:'line',class:clazz}); | |
//cursorRange.selection = this.atom.setSelectedBufferRange(cursorRange.id.getBufferRange()); | |
cursorRange.selection = this.atom.addSelectionForBufferRange(cursorRange.id.getBufferRange()); | |
return { | |
clear: function() { | |
editor = atom.workspace.getActiveEditor() | |
curs = editor.getCursors(); | |
for (i=0;curs.length > 0;i++) { | |
curs[i].destroy() | |
} | |
return cursorRange.selection.clear(); | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment