From 79631fa5a83cb8cf3f53e55d7348f14c5d671d35 Mon Sep 17 00:00:00 2001 From: Marco Buchholz Date: Wed, 17 May 2017 16:39:35 +0200 Subject: [PATCH] Added feature to center, scroll from top or bottom after jump. Added new configuration options. --- lib/symbols-list-config.coffee | 17 +++++++++++++++++ lib/symbols-list.coffee | 26 +++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/lib/symbols-list-config.coffee b/lib/symbols-list-config.coffee index 36c02e8..81b4590 100644 --- a/lib/symbols-list-config.coffee +++ b/lib/symbols-list-config.coffee @@ -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" diff --git a/lib/symbols-list.coffee b/lib/symbols-list.coffee index 62542ed..ee8ed80 100644 --- a/lib/symbols-list.coffee +++ b/lib/symbols-list.coffee @@ -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 @@ -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()