Skip to content

Feat: Allow for relative movement in gotoLineQuickAccess #246831

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/vs/editor/contrib/quickAccess/browser/gotoLineQuickAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,21 @@ export abstract class AbstractGotoLineQuickAccessProvider extends AbstractEditor
private parsePosition(editor: IEditor, value: string): IPosition {

// Support line-col formats of `line,col`, `line:col`, `line#col`
const numbers = value.split(/,|:|#/).map(part => parseInt(part, 10)).filter(part => !isNaN(part));
const endLine = this.lineCount(editor) + 1;
const parts = value.split(/,|:|#/).filter(part => !isNaN(parseInt(part, 10)));
const numbers = parts.map(part => parseInt(part, 10));

// If number starts with + or - we add it to the current cursor position for relative positioning
const currentPosition = editor.getPosition() || { lineNumber: 1, column: 1 };
const lineNumberRelative = parts.length > 0 && /^[+-]/.test(parts[0]);
const columnRelative = parts.length > 1 && /^[+-]/.test(parts[1]);

return {
lineNumber: numbers[0] > 0 ? numbers[0] : endLine + numbers[0],
column: numbers[1]
lineNumber: lineNumberRelative
? (numbers[0] + currentPosition.lineNumber)
: numbers[0],
column: columnRelative
? (numbers[1] + currentPosition.column)
: numbers[1]
};
}

Expand Down