Skip to content

Commit 6100336

Browse files
committed
add ctrl support for select branch in context menu
1 parent 86df3b8 commit 6100336

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

web/contextMenu.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const CLASS_CONTEXT_MENU_ACTIVE = 'contextMenuActive';
33
interface ContextMenuAction {
44
readonly title: string;
55
readonly visible: boolean;
6-
readonly onClick: () => void;
6+
readonly onClick: (e?: MouseEvent) => void;
77
readonly checked?: boolean; // Required in checked context menus
88
}
99

@@ -46,15 +46,15 @@ class ContextMenu {
4646
* @param className An optional class name to add to the context menu.
4747
*/
4848
public show(actions: ContextMenuActions, checked: boolean, target: ContextMenuTarget | null, event: MouseEvent, frameElem: HTMLElement, onClose: (() => void) | null = null, className: string | null = null) {
49-
let html = '', handlers: (() => void)[] = [], handlerId = 0;
49+
let html = '', handlers: ((e?: MouseEvent) => void)[] = [], handlerId = 0;
5050
this.close();
5151

5252
for (let i = 0; i < actions.length; i++) {
5353
let groupHtml = '';
5454
for (let j = 0; j < actions[i].length; j++) {
5555
if (actions[i][j].visible) {
5656
groupHtml += '<li class="contextMenuItem" data-index="' + handlerId++ + '">' + (checked ? '<span class="contextMenuItemCheck">' + (actions[i][j].checked ? SVG_ICONS.check : '') + '</span>' : '') + actions[i][j].title + '</li>';
57-
handlers.push(actions[i][j].onClick);
57+
handlers.push((e?: MouseEvent) => actions[i][j].onClick(e));
5858
}
5959
}
6060

@@ -92,7 +92,9 @@ class ContextMenu {
9292
// The user clicked on a context menu item => call the corresponding handler
9393
e.stopPropagation();
9494
this.close();
95-
handlers[parseInt((<HTMLElement>(<Element>e.target).closest('.contextMenuItem')!).dataset.index!)]();
95+
const handlerIndex = parseInt((<HTMLElement>(<Element>e.target).closest('.contextMenuItem')!).dataset.index!);
96+
const handler = handlers[handlerIndex];
97+
handler?.(e instanceof MouseEvent ? e : undefined);
9698
});
9799

98100
menu.addEventListener('click', (e) => {

web/dropdown.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ class Dropdown {
152152
* Select a specific value in the dropdown.
153153
* @param value The value to select.
154154
*/
155-
public selectOption(value: string) {
155+
public selectOption(value: string, event: MouseEvent | undefined) {
156156
const optionIndex = this.options.findIndex((option) => value === option.value);
157157
if (optionIndex < 0 && (this.optionsSelected[0] || this.optionsSelected[optionIndex])) return;
158-
if (this.multipleAllowed && !this.selectMultipleWithCtrl && !this.optionsSelected[0]) {
158+
if (this.multipleAllowed && !this.optionsSelected[0] && (!this.selectMultipleWithCtrl || (event && (event.ctrlKey || event.metaKey)))) {
159159
// Select the option with the specified value
160160
this.optionsSelected[optionIndex] = true;
161161
} else {

web/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ class GitGraphView {
11351135
{
11361136
title: 'Select in Branches Dropdown',
11371137
visible: visibility.selectInBranchesDropdown && (!isSelectedInBranchesDropdown || this.branchDropdown.isShowAllSelected()),
1138-
onClick: () => this.branchDropdown.selectOption(refName)
1138+
onClick: (e) => this.branchDropdown.selectOption(refName, e)
11391139
},
11401140
{
11411141
title: 'Unselect in Branches Dropdown',
@@ -1373,7 +1373,7 @@ class GitGraphView {
13731373
{
13741374
title: 'Select in Branches Dropdown',
13751375
visible: visibility.selectInBranchesDropdown && !isSelectedInBranchesDropdown,
1376-
onClick: () => this.branchDropdown.selectOption(prefixedRefName)
1376+
onClick: (e) => this.branchDropdown.selectOption(prefixedRefName, e)
13771377
},
13781378
{
13791379
title: 'Unselect in Branches Dropdown',

0 commit comments

Comments
 (0)