Skip to content

Commit

Permalink
Added feature to center, scroll from top or bottom after jump.
Browse files Browse the repository at this point in the history
Added new configuration options.
  • Loading branch information
mbuc82 committed May 17, 2017
1 parent 51b31d2 commit 79631fa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
17 changes: 17 additions & 0 deletions lib/symbols-list-config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,20 @@ module.exports =
type: "boolean"
default: false
description: "Hide the list if empty"
positioning:
order: 2
type: "object"
properties:
positionAfterJump:
order: 1
title: "Position After Jump"
type: "string"
default: "ScrollFromTop"
description: "Center = center the line after jump; ScrollFromTop = Scroll the line from the top (using Position Scroll); ScrollFromBottom = Scroll the line from the bottom (using Position Scroll)"
enum: ["Center", "ScrollFromTop", "ScrollFromBottom"]
positionScroll:
order: 2
title: "Position Scroll"
type: ["integer"]
default: 20
description: "positive value = scroll from top / negative value = scroll from bottom"
26 changes: 23 additions & 3 deletions lib/symbols-list.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ module.exports =
@SymbolsListView.selectItemView( @SymbolsListView.list.find('li').eq( key ) )

recursiveScanRegex: ( scopeArray, regexGroup, start ) ->

current = window.performance.now()
recursive_time_limit = 500.0
for key,val of regexGroup
Expand All @@ -133,9 +134,28 @@ module.exports =
@recursiveScanRegex( scopeArray.slice(1), val, start )

moveToRange: (range) ->
@editor = atom.workspace.getActiveTextEditor()
@editor.setCursorBufferPosition(range.start)
@editor.scrollToCursorPosition({center: false})

PositionAfterJump = atom.config.get('symbols-list.positioning.positionAfterJump')

Editor = atom.workspace.getActiveTextEditor()
Editor.setCursorBufferPosition(range.start)

Cursor = Editor.getCursorScreenPosition()
View = atom.views.getView(Editor);
PixelPosition = View.pixelPositionForScreenPosition(Cursor).top

if PositionAfterJump == 'Center'
PixelPosition -= (Editor.getHeight() / 2);
Editor.setScrollTop PixelPosition
else
PositionScroll = atom.config.get('symbols-list.positioning.positionScroll')
LineHeight = Editor.getLineHeightInPixels()
if PositionAfterJump == 'ScrollFromTop'
PixelPosition -= (LineHeight * PositionScroll);
Editor.setScrollTop PixelPosition
else
PixelPosition += (LineHeight * PositionScroll);
Editor.setScrollBottom PixelPosition

deactivate: ->
@panel.destroy()
Expand Down

0 comments on commit 79631fa

Please sign in to comment.