oleg-shilo / sublime-codemap

CodeMap - is a ST3 plugin for showing the code tree representing the code structure of the active view/document
MIT License
41 stars 4 forks source link

Add option to disable Scroll past EOF only in Code - Map panel or solve issue where it auto scrolls to the end.. #26

Closed Acecool closed 2 months ago

Acecool commented 6 years ago

I like having Scroll past EOF enabled for code -but the Code - Map panel doesn't necessarily need it...

The main problem I'm encountering is ( even before the new issue to auto-sync - which I do like ) in some instances the Code - Map panel will scroll all the way to the bottom hiding most of the text...

I'm proposing two things: Instead of scrolling all the way to the end, to an empty line or something, scroll to the top when that happens...

and.. Add an additional option to disable scroll past EOF in the Code - Map panel only while allowing it to be enabled in the standard panels...

I'll be disabling it in the meantime and hopefully that'll solve the first issue for the time being...

Acecool commented 6 years ago

I've tried a lot of different things but I can't reproduce is as of yet...

I've attempted:

Selecting multiple lines and switching between multiple languages and multiple files of varying output ( to code map ) length... and it seems to either use the previous position or a random position...

If I don't save a file and I switch from it when it is at the top, I switch back to the file and the code-map panel scrolls back to the previous position ( ie when I switched to it the first time it is at the bottom - I scroll it to the top, switch away and then switch back and it goes back to the bottom instead of the top )..

Sometimes it does stay at the top - maybe when switching between the same language? nope - seems to be random when switching between the same language..

Is it possible, if a function can't be found in the output ( which happens to auto-sync on save ) that it scrolls to the top?

Or, when you switch from one file to another, if a function is selected in the code that it automatically syncs to that?

Acecool commented 6 years ago

Got it

        ## Grab all of the active views for the current window...
        _views = sublime.active_window( ).views( )

        ## Code - Map is typically the LAST view, always...
        _code_map = _views[ len( _views ) - 1 ]

        ## if ( _code_map
        if ( not _code_map.file_name( ).strip( ).endswith( 'Code - Map' ) ):
            ## Let the user know
            print( 'Suspected Code - Map Panel is incorrent.. loop needed!' )

            ## Unset it..
            _code_map = None

            ## Loop through up to all views - 1 to find the Code - Map Panel if the above one is incorrect... We don't need to look at the last one because we tried that up above...
            for _i in range( len( _views ) - 1 ):
                _view = _views[ _i ]
                if ( _view.file_name( ).strip( ).endswith( 'Code - Map' ) ):
                    print( '>> Code - Map Panel Identified: ID: "' + str( _view.id( ) ) + '" / Name: "' + _view.name( ) + '" / File-Name: "' + _view.file_name( ) + '"' )
                    _code_map = _view
                    break
        else:
            ## Let the user know...
            print( '>> Suspected Code - Map Panel CONFIRMED!' )

        ## Just in case...
        if ( _code_map != None ):
            ## Notify the user...
            print( ' >> Code - Map Panel >> Updating Configuration!' )

            ## Disable Scroll Past End...
            print( ' >> Code - Map Panel >> scroll_pass_end set to False!' )
            _code_map.settings( ).set( 'scroll_past_end', False )

I've added this to XCodeMapper - but it could also be added / merged to CodeMap in order to set up configuration, etc...

In all cases I've found the LAST panel to be CodeMap, but just in case it isn't ( or isn't open ), the other code looks... Then if the panel exists and is found it updates config..

Note: I only check the active window because that's all that matters - and it is where it'd run...

oleg-shilo commented 6 years ago

Great, thank you.

Can you please elaborate where this code snippet is supposed to go.

oleg-shilo commented 2 months ago

Closing as no longer active