Skip to content

Instantly share code, notes, and snippets.

@t9md
Created August 1, 2017 14:57
Show Gist options
  • Save t9md/7fabf65ab76a72cc94ba4ffb6ab59853 to your computer and use it in GitHub Desktop.
Save t9md/7fabf65ab76a72cc94ba4ffb6ab59853 to your computer and use it in GitHub Desktop.
getVisibleEditors = ->
(editor for pane in atom.workspace.getPanes() when editor = pane.getActiveEditor())
# because of let of `eol`
translatePointAndClip = (editor, point, direction) ->
point = Point.fromObject(point)
dontClip = false
switch direction
when 'forward'
point = point.translate([0, +1])
eol = editor.bufferRangeForBufferRow(point.row).end
if point.isEqual(eol)
dontClip = true
else if point.isGreaterThan(eol)
dontClip = true
point = new Point(point.row + 1, 0) # move point to new-line selected point
point = Point.min(point, editor.getEofBufferPosition())
when 'backward'
point = point.translate([0, -1])
if point.column < 0
dontClip = true
newRow = point.row - 1
eol = editor.bufferRangeForBufferRow(newRow).end
point = new Point(newRow, eol.column)
point = Point.max(point, Point.ZERO)
if dontClip
point
else
screenPoint = editor.screenPositionForBufferPosition(point, clipDirection: direction)
editor.bufferPositionForScreenPosition(screenPoint)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment