vscode#TextEditorSelectionChangeKind TypeScript Examples

The following examples show how to use vscode#TextEditorSelectionChangeKind. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: extension.ts    From vscode-autohide with MIT License 5 votes vote down vote up
export function activate(context: vscode.ExtensionContext) {

    if (vscode.workspace.getConfiguration("autoHide").hideOnOpen) {
        vscode.commands.executeCommand("workbench.action.closePanel");
        vscode.commands.executeCommand("workbench.action.closeSidebar");
    };

    vscode.window.onDidChangeTextEditorSelection(selection => {
        let config = vscode.workspace.getConfiguration("autoHide");
        let path = vscode.window.activeTextEditor.document.fileName;
        let pathIsFile = path.includes(".") || path.includes("\\") || path.includes("/");

        if (selection.kind != TextEditorSelectionChangeKind.Mouse // selection was not from a click
            || selection.selections.length != 1                   // no selections or multiselections
            || selection.selections.find(a=>a.isEmpty) == null    // multiselections
            || !pathIsFile) {                                     // The debug window editor
            return;
        } else {
            setTimeout(function() {
                if (config.autoHidePanel) {
                    vscode.commands.executeCommand("workbench.action.closePanel");
                }
            }, config.panelDelay);

            setTimeout(function() {
                if (config.autoHideSideBar) {
                    vscode.commands.executeCommand("workbench.action.closeSidebar");
                }
            }, config.sideBarDelay);
        };
    });

    context.subscriptions.push(
        vscode.commands.registerCommand("autoHide.toggleHidePanel", async() => {
            let config = vscode.workspace.getConfiguration("autoHide");
            await config.update("autoHidePanel", !config.autoHidePanel, vscode.ConfigurationTarget.Workspace);
        }));
    context.subscriptions.push(
        vscode.commands.registerCommand("autoHide.toggleHideSideBar", async() => {
            let config = vscode.workspace.getConfiguration("autoHide");
            await config.update("autoHideSideBar", !config.autoHideSideBar, vscode.ConfigurationTarget.Workspace);
        }));
}