alefragnani / vscode-ext-selection

NPM Package with helper functions to work with "text selection" while developing VS Code extensions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vscode-ext-selection

This module contains a set of helper functions to work with text selection while developing VS Code extensions.

Installation

npm install vscode-ext-selection

Usage

    import { Directions, selectLines, expandSelectionToPosition, shrinkSelectionToPosition } from "vscode-ext-selection";

    ...

    if (selectWordAtCursorPosition(editor)) {
        vscode.env.clipboard.writeText(editor.document.getText(editor.selection));
    } else {
        vscode.commands.executeCommand("editor.action.clipboardCopyAction");
    }

    ...

    const lines: number[] = [];
    for (const bookmark of bookmarks.activeBookmark.bookmarks) {
        lines.push(bookmark.line);
    }
    selectLines(vscode.window.activeTextEditor, lines);

    ...

    const line = 10;
    const column = 20;
    const nextPosition = new vscode.Position(line, column);
    expandSelectionToPosition(vscode.window.activeTextEditor, nextPosition, Directions.Forward);
    shrinkSelectionToPosition(vscode.window.activeTextEditor, nextPosition, Directions.Backward);

Support

If you find it useful, please consider supporting it.

License

MIT © Alessandro Fragnani

About

NPM Package with helper functions to work with "text selection" while developing VS Code extensions

License:MIT License


Languages

Language:TypeScript 100.0%