Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensibility API command for moving cursor to line. #6695

Closed
PatoBeltran opened this issue May 23, 2016 · 2 comments
Closed

Extensibility API command for moving cursor to line. #6695

PatoBeltran opened this issue May 23, 2016 · 2 comments
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)

Comments

@PatoBeltran
Copy link

PatoBeltran commented May 23, 2016

I'm working in a vscode extension and I would like to open a file with the cursor in a given line (just as the -g flag of the command line tool). I've been looking at the API commands and I don't see any command that does this.

The solution that I was looking at was the following:

private openFileAtLocation(filename: string, lineNumber: number): Q.Promise<any> {
    return Q(vscode.commands.executeCommand("vscode.openFolder", vscode.Uri.file(filename))).then(() => {
        vscode.commands.executeCommand("workbench.action.gotoLine", lineNumber);
    });
}

but the workbench.action.gotoLine only opens the Go to Line dialog. Is there any support for this feature in the API? or can this command be modified so that if a line number is provided as an argument it automatically jumps to the line?

Thanks!

@f111fei
Copy link
Contributor

f111fei commented May 24, 2016

Maybe you can try to do like this.

let editor = vscode.window.activeTextEditor;
let range = editor.document.lineAt(lineNumber-1).range;
editor.selection =  new vscode.Selection(range.start, range.end);
editor.revealRange(range);

@jrieken jrieken added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label May 24, 2016
@jrieken
Copy link
Member

jrieken commented May 24, 2016

revealRange is the way to go on this.

@jrieken jrieken closed this as completed May 24, 2016
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)
Projects
None yet
Development

No branches or pull requests

3 participants