Skip to content

Commit eafd8dc

Browse files
committed
Add no-op command to prevent empty submenu display
1 parent 30f7ff2 commit eafd8dc

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/commandsAndMenu.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { ISettingRegistry } from '@jupyterlab/settingregistry';
1515
import { ITerminal } from '@jupyterlab/terminal';
1616
import { CommandRegistry } from '@lumino/commands';
1717
import { Menu } from '@lumino/widgets';
18-
import { toArray, ArrayExt } from '@lumino/algorithm';
18+
import { ArrayExt, toArray } from '@lumino/algorithm';
1919
import * as React from 'react';
2020
import {
2121
Diff,
@@ -710,6 +710,12 @@ export function addCommands(
710710
});
711711
}
712712
});
713+
714+
commands.addCommand(ContextCommandIDs.gitNoAction, {
715+
label: 'No actions available',
716+
isEnabled: () => false,
717+
execute: () => void 0
718+
});
713719
}
714720

715721
/**
@@ -845,7 +851,9 @@ export function addFileBrowserContextMenu(
845851

846852
const items = getSelectedBrowserItems();
847853
const statuses = new Set<Git.Status>(
848-
items.map(item => model.getFileStatus(item.path))
854+
items
855+
.map(item => model.getFileStatus(item.path))
856+
.filter(status => typeof status !== 'undefined')
849857
);
850858

851859
// get commands and de-duplicate them
@@ -858,10 +866,18 @@ export function addFileBrowserContextMenu(
858866
.filter(
859867
command =>
860868
command !== ContextCommandIDs.gitFileOpen &&
861-
command !== ContextCommandIDs.gitFileDelete
869+
command !== ContextCommandIDs.gitFileDelete &&
870+
typeof command !== 'undefined'
862871
)
863872
);
864873

874+
// if looking at a tracked file with no changes,
875+
// it has no status, nor any actions available
876+
// (although `git rm` would be a valid action)
877+
if (allCommands.size === 0 && statuses.size === 0) {
878+
allCommands.add(ContextCommandIDs.gitNoAction);
879+
}
880+
865881
const commandsChanged =
866882
!this._commands ||
867883
this._commands.length !== allCommands.size ||

src/tokens.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,8 @@ export enum ContextCommandIDs {
846846
gitFileStage = 'git:context-stage',
847847
gitFileTrack = 'git:context-track',
848848
gitIgnore = 'git:context-ignore',
849-
gitIgnoreExtension = 'git:context-ignoreExtension'
849+
gitIgnoreExtension = 'git:context-ignoreExtension',
850+
gitNoAction = 'git:no-action'
850851
}
851852

852853
/**

0 commit comments

Comments
 (0)