-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fixes #708 - Prompt for file path when missing from revision #2825
Conversation
f27c94d
to
9ea07d3
Compare
Would love to get this reviewed (and hopefully merged) @eamodio 😃 |
Rebased the PR onto the latest main branch again, eagerly awaiting a review 😄 |
@mogelbrod Thanks for this -- I've started taking a pass through this and having issues with the But before I dig more into this, I'd love to have the 2 parts split apart. So split out the |
src/git/actions/commit.ts
Outdated
export async function pickFileAtRevision( | ||
uri: GitUri, | ||
options: { | ||
title: string; | ||
initialPath?: string; | ||
}, | ||
): Promise<Uri | undefined> { | ||
const disposables: Disposable[] = []; | ||
try { | ||
const picker = window.createQuickPick(); | ||
Object.assign(picker, { | ||
title: options.title, | ||
value: options.initialPath ?? uri.relativePath, | ||
placeholder: 'Enter path to file...', | ||
busy: true, | ||
ignoreFocusOut: getQuickPickIgnoreFocusOut(), | ||
}); | ||
picker.show(); | ||
|
||
const tree = await Container.instance.git.getTreeForRevision(uri.repoPath, uri.sha!); | ||
picker.items = tree.filter(file => file.type === 'blob').map((file): QuickPickItem => ({ label: file.path })); | ||
picker.busy = false; | ||
|
||
const pick = await new Promise<string | undefined>(resolve => { | ||
disposables.push( | ||
picker, | ||
picker.onDidHide(() => resolve(undefined)), | ||
picker.onDidAccept(() => { | ||
if (picker.activeItems.length === 0) return; | ||
resolve(picker.activeItems[0].label); | ||
}), | ||
); | ||
}); | ||
|
||
return pick | ||
? Container.instance.git.getRevisionUri(uri.sha!, `${uri.repoPath}/${pick}`, uri.repoPath!) | ||
: undefined; | ||
} finally { | ||
disposables.forEach(d => { | ||
d.dispose(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this into src/quickpicks/revisionPicker.ts
similar to the other pickers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Should it be called fileRevisionPicker
(or a variation thereof) or revisionPicker
? I'm leaning towards the former since it's technically picking a file at a specific revision, rather than picking a revision (unless the "file" part is implicit for revisions?).
src/git/actions/commit.ts
Outdated
const tree = await Container.instance.git.getTreeForRevision(uri.repoPath, uri.sha!); | ||
picker.items = tree.filter(file => file.type === 'blob').map((file): QuickPickItem => ({ label: file.path })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to try only putting the base filename as the label and putting the rest of the folder path in the description -- closer to the vscode picker. Will need to enable picker.matchOnDescription
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this now, but vscode appears to not match any of the following items when
picker.value = 'directory/file.tsx'
:
[
{ label: 'file.tsx', description: 'directory' },
{ label: 'file.tsx', description: 'directory/' },
}
src/git/actions/commit.ts
Outdated
const pick = await new Promise<string | undefined>(resolve => { | ||
disposables.push( | ||
picker, | ||
picker.onDidHide(() => resolve(undefined)), | ||
picker.onDidAccept(() => { | ||
if (picker.activeItems.length === 0) return; | ||
resolve(picker.activeItems[0].label); | ||
}), | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to add the extra keyboard (right arrow) support here to open the selected file in a preview editor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know about this functionality 😄 Not sure how though, do you have any pointers to existing implementations?
Would it potentially break text selections using left/right arrow keys in the text field?
src/quickpicks/revisionPicker.ts
Outdated
// FIXME: Remove this unless we opt to show the directory in the description | ||
// const parsed = path.parse(file.path) | ||
// return { label: parsed.base, description: parsed.dir } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left this code in if you wanted to try it out yourself @eamodio. It does depend on path
, which appears to be a forbidden import.
Thanks for taking the time to dig into this @eamodio! I've extracted the |
- Avoids breaking ctrl+[left|right] in input - Introduces structured `keyboard` object to handle keypress event bindings and actions
Improves the `openFileAtRevision()` function by: - Asking user to enter another path when the requested file doesn't exist in the selected revision. - Showing an error message on subsequent failure (or if an error is thrown). The above function is used by a number of commands: - `gitlens.openFileRevision` - `gitlens.openFileRevisionFrom` - `gitlens.openRevisionFile`
Adds keyboard nav to revision picker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
Fixes #708 - Prompt for file path when missing from revision
Improves the
openFileAtRevision()
function by:selected revision.
The above function is used by a number of commands:
gitlens.openFileRevision
gitlens.openFileRevisionFrom
gitlens.openRevisionFile
Checklist
Fixes $XXX -
orCloses #XXX -
prefix to auto-close the issue that your PR addresses