1
1
mirror of https://github.com/kahole/edamagit.git synced 2024-09-11 07:15:31 +03:00

Merge pull request #284 from bzy-debug/cursor-commit-hash

feat: show commit hash under cursor when checkout
This commit is contained in:
Kristian Andersen Hole 2023-12-04 17:06:01 +01:00 committed by GitHub
commit 12e901b7cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -150,8 +150,29 @@ export default class MagitUtils {
public static async chooseRef(repository: MagitRepository, prompt: string, showCurrent = false, showHEAD = false, allowFreeform = true, remoteOnly = false): Promise<string> {
const getCursorCommitHash: () => PickMenuItem<string> | undefined = () => {
const activeEditor = vscode.window.activeTextEditor;
if (activeEditor === undefined) {
return;
}
const document = activeEditor.document;
const selection = activeEditor.selection;
const hashWordRange = document.getWordRangeAtPosition(selection.active, /[0-9a-z]{7}/);
if (hashWordRange === undefined) {
return;
}
const hash = document.getText(hashWordRange);
return { label: hash, meta: hash };
};
const refs: PickMenuItem<string>[] = [];
const cursorCommitHash = getCursorCommitHash();
if (cursorCommitHash) {
refs.push(cursorCommitHash);
}
if (showCurrent && repository.HEAD?.name) {
refs.push({
label: repository.HEAD.name,