Home > Blockchain >  How do you focus on a panel view programmatically given an id
How do you focus on a panel view programmatically given an id

Time:11-18

I'd like to be able to toggle open the panel (termainl, debug, output, etc.. area) and focus on a specific custom view given an id. I know this is possible since there are focus commands for terminal debug etc but searching them up in the vscode source code just gives string references and not publicly usable functions. Any help would be appreciated. (Please don't give shortcut answers like ctrl j, I want to do this with code)

I tried copying the format of the focus view commands above but the focus of the custom view didn't work. Seems like its not an automatic thing.

CodePudding user response:

I think you want this. Every custom TreeView or WebView gets some commands added automatically by vscode. For example, my Editor Manager ViewContainer, with this view:

        "views": {
            "editorManager": [
                {
                    "id": "editor-groups",
                    "name": "Groups",
                    "size": 1,
                    "visibility": "visible"
                }
            ]
        }

gets these commands added automatically (they can be found in the Keyboard Shortcuts, at least when the extension is activated):

editor-groups.focus
workbench.actions.treeView.editor-groups.refresh
workbench.actions.treeView.editor-groups.collapseAll

workbench.view.extension.editorManager
workbench.view.extension.editorManager.resetViewContainerLocation

You probably want the first one to focus your view in the Panel.

vscode.commands.executeCommand("editor-groups.focus");
  • Related