Skip to content

Commit

Permalink
Fix gf with a line number (#8708)
Browse files Browse the repository at this point in the history
  • Loading branch information
Foo-x authored Nov 17, 2023
1 parent 7c2d3de commit 49dd3dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/actions/commands/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ class CommandOpenFile extends BaseCommand {
bang: false,
opt: [],
file: filePath,
cmd: isNaN(line) ? undefined : { type: 'line_number', line },
cmd: isNaN(line) ? undefined : { type: 'line_number', line: line - 1 },
createFileIfNotExists: false,
});
fileCommand.execute(vimState);
Expand Down
11 changes: 6 additions & 5 deletions src/cmd_line/commands/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type LegacyArgs = {
};
function getLegacyArgs(args: IFileCommandArguments): LegacyArgs {
if (args.name === 'edit') {
return { file: args.file, bang: args.bang, createFileIfNotExists: true };
return { file: args.file, bang: args.bang, cmd: args.cmd, createFileIfNotExists: true };
} else if (args.name === 'enew') {
return { bang: args.bang, createFileIfNotExists: true };
} else if (args.name === 'new') {
Expand Down Expand Up @@ -229,7 +229,7 @@ export class FileCommand extends ExCommand {
}

const doc = await vscode.workspace.openTextDocument(fileUri);
await vscode.window.showTextDocument(doc);
const editor = await vscode.window.showTextDocument(doc);

const lineNumber =
args.cmd?.type === 'line_number'
Expand All @@ -238,9 +238,10 @@ export class FileCommand extends ExCommand {
? vscode.window.activeTextEditor!.document.lineCount - 1
: undefined;
if (lineNumber !== undefined && lineNumber >= 0) {
vscode.window.activeTextEditor!.revealRange(
new vscode.Range(new vscode.Position(lineNumber, 0), new vscode.Position(lineNumber, 0)),
);
const pos = new vscode.Position(lineNumber, 0);
editor.selection = new vscode.Selection(pos, pos);
const range = new vscode.Range(pos, pos);
editor.revealRange(range);
}
await hidePreviousEditor();
}
Expand Down

0 comments on commit 49dd3dc

Please sign in to comment.