Skip to content

Sticky scroll - keep containers headers visible when scrolling #26757

Closed

Description

@gulshan

This is a feature request. Starting with an example. Suppose we have following c# file-

using System;

namespace ExampleNamespace
{
    class ExampleClass
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }

        static void ExampleMethod1()
        {
            Console.WriteLine("ExampleMethod1");
        }

        static void ExampleMethod2()
        {
            var methodName = "ExampleMethod2";

            foreach(var c in methodName)
            {
                if(char.IsUpper(c))
                {
                    Console.WriteLine("Upper case");
                }
                else
                {
                    Console.WriteLine("Lower case");
                }
            }
        }
    }
}

If we are browsing the file at the end, it looks like this now-
current

And with this feature, I wish it to look something like this-
requested

It means the parent syntax nodes of the area being browsed is automatically freezed, so that the user can easily guess the context of the current code, regardless of how far the parent nodes are. Some points being-

  • I think this should be a toggle keystroke to on/off feature, may or may not backed by a setting.
  • The parent syntax nodes should smoothly stack up or goes out of stack while scrolling.
  • This should be tied with the current viewport and not current cursor position in my opinion.
  • It would be nice to have previous sibling nodes included in the stack for if-else chains and switch cases.
  • By default, this can be solely based on indentation instead of actual syntax tree of the language, just like how folding currently works in vscode.
  • There should be a minimum height of the viewport with actual code (without parent nodes). Or maximum height of parent node (header) lines. When that value will be reached (like for heavily nested code), furthest or top most parent nodes can be hidden in that order. The closes parent nodes will remain visible.

Edit:
Found a nice illustration for this feature from this tweet-

freeze_header

Activity

  1. aeschli commented on May 17, 2017

    @aeschli
    Contributor

    Interesting idea! Erich Gamma (@egamma) alexandrudima FYI.

  2. added
    feature-request
    editor-folding
    on May 17, 2017
  3. changed the title [-]Option for freezing parent syntax nodes while browsing code[/-] [+]Automatic Smart code folding (Freeze parent syntax node headers)[/+] on May 23, 2017
  4. PEZO19 commented on Jun 2, 2017

    @PEZO19

    I really like the idea, I have something very similar. I believe code folding could be use many ways to make code easier to absorb.
    I wonder is there any other editor which has similar code folding strategy?

  5. gulshan commented on Jun 5, 2017

    @gulshan
    Author

    I don't know any other editor with this kind of code folding feature.

  6. pr-yemibedu commented on Aug 1, 2017

    @pr-yemibedu
    Contributor

    Hello,
    This Peeking fold is nice. Some settings could be:

    • folding.enablePeeking = true
    • folding.peekingDepth = {0 = unlimited, 1 = one level in, 2 = two levels in, ... , n}

    So what I would like to see is more (+) in the left border to indicate a way to collapse or expand. Also this can be a lot easier to get in vscode if there are not a lot of limits. The OP made six points ATTOW and so:

    1. it could be a keyboard ready toggle, but being backed by a setting gives a user the choice to anchor the toggle direction.
    2. ? the code tells the tale told by the programmer, no ?
    3. agreed
    4. special cases break expectations of ident based folding.
    5. agreed
    6. sounds like my second setting, but it maybe not poping into a fold based on anymore than matching the current level count

    This is one of those so simple looking additions to the editor that it would be a crime to leave out. Thank you. Good day.

  7. gulshan commented on Nov 2, 2017

    @gulshan
    Author

    I thought user may not want to keep this settings on always. It will help more in code exploring situations. But may be someone will want to keep it on permanently. Then I have no objection to a permanent settings.

    Regarding branching nodes like if, else-if, else, cases for switch or others, it's true that freezing previous sibling node headers violates indent based folding expectations and the feature will then require language awareness of some sort. So the first or baseline implementation can leave it. But I think it's still a nice to have enhancement and language servers should be able to contribute to this part.

  8. gulshan commented on Jan 10, 2018

    @gulshan
    Author

    One thing! When this feature is turned on, the usual code-folding has to be turned off. So enabling this can be part of editor.folding settings.

  9. gulshan commented on Jun 16, 2019

    @gulshan
    Author
  10. wayou commented on Jun 17, 2019

    @wayou

    Since the frozen part will take vertical space, it's better to limit the rows and collapse the middle rows with an explicit expand button.

    Something like this:

    class Foo{
    ...Expand 3+ hidden parent nodes...
    	constructor(public name:string){
    ---------------------------------------
    	// other codes...
    	}
    }
  11. jrieken commented on Jun 19, 2019

    @jrieken
    Contributor

    This should be tied with the current viewport and not current cursor position in my opinion.

    We could try that for breadcrumbs. I have created #75776 to make breadcrumbs being driven by the viewport, not the selection

  12. 33 remaining items

  13. BenBE commented on Aug 7, 2022

    @BenBE

    I'm properly seeing the semantic scroll work in C (haven't checked C++ yet), but with the headings only generated for the actual function I'm in, but not control structures within the function. Is this intentional? Or could there at least be a setting to enable this? With just the top-level header of the function this doesn't bring any advantages over the existing line above it:

    Image of some code from htop in ScreenManager.c scrolled half-way through the function
    I'd prefer if the while (!quit) from line 224, the if (ch == KEY_MOUSE && this->settings->enableMouse) { from line 239, the if (ok == OK) { from line 243 and if (mevent.bstate & BUTTON1_RELEASED) { from line 244 were all kept in view.

    Also I noticed a minor strangeness in that trying to scroll up, the cursor seems to move into a line hidden by the sticky-scroll display.

    Overall I like the feature and am looking forward to see these minor issues resolved in an upcoming version.

    NB: Screenshot done against htop-dev/htop@3e1908b in case someone needs the exact source to reproduce. Feel free to ask for further details as needed.

  14. The-Compiler commented on Aug 11, 2022

    @The-Compiler
  15. gjsjohnmurray commented on Aug 11, 2022

    @gjsjohnmurray
    Contributor
  16. The-Compiler commented on Aug 11, 2022

    @The-Compiler

    Whoops, I missed that - thanks for the pointer and sorry for the noise! 👍

  17. aiday-mar commented on Aug 12, 2022

    @aiday-mar
    Collaborator

    Thank you for all your comments and interest. If you are interested to see the latest new behavior of sticky scroll you may install the VSCode Insiders release for testing (https://code.visualstudio.com/insiders/). Some of the recurring issues have been solved there. These changes will appear in next month's stable release.

  18. changed the title [-]Semantic scroll - keep containers headers visible when scrolling[/-] [+]Sticky scroll - keep containers headers visible when scrolling[/+] on Aug 22, 2022
  19. aiday-mar commented on Aug 22, 2022

    @aiday-mar
    Collaborator

    To verify:

    Open a file, scroll in it
    Verify that the correct sticky headers are stuck to the top
    Use simple click to jump to the line
    Use control click to jump to the definitions of the variable

  20. locked and limited conversation to collaborators on Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

editor-sticky-scrollfeature-requestverification-neededverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions