Skip to content

Commit 0ced320

Browse files
committed
refactor selectMultipleWithCtrl to depend on multipleAllowed
1 parent c4323a1 commit 0ced320

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

web/dropdown.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Dropdown {
3737
* @returns The Dropdown instance.
3838
* @param selectMultipleWithCtrl Select multiple items using Ctrl
3939
*/
40-
constructor(id: string, showInfo: boolean, multipleAllowed: boolean, dropdownType: string, changeCallback: (values: string[]) => void, selectMultipleWithCtrl: boolean = true) {
40+
constructor(id: string, showInfo: boolean, multipleAllowed: boolean, dropdownType: string, changeCallback: (values: string[]) => void, selectMultipleWithCtrl: boolean = false) {
4141
this.showInfo = showInfo;
4242
this.multipleAllowed = multipleAllowed;
4343
this.selectMultipleWithCtrl = selectMultipleWithCtrl;
@@ -64,7 +64,7 @@ class Dropdown {
6464
this.currentValueElem = this.elem.appendChild(document.createElement('div'));
6565
this.currentValueElem.className = 'dropdownCurrentValue';
6666

67-
alterClass(this.elem, 'multi', (multipleAllowed || selectMultipleWithCtrl));
67+
alterClass(this.elem, 'multi', (multipleAllowed));
6868
this.elem.appendChild(this.menuElem);
6969

7070
document.addEventListener('click', (e) => {
@@ -127,7 +127,7 @@ class Dropdown {
127127
*/
128128
public isSelected(value: string) {
129129
if (this.options.length > 0) {
130-
if ((this.multipleAllowed || this.selectMultipleWithCtrl) && this.optionsSelected[0]) {
130+
if ((this.multipleAllowed) && this.optionsSelected[0]) {
131131
// Multiple options can be selected, and "Show All" is selected.
132132
return true;
133133
}
@@ -147,7 +147,7 @@ class Dropdown {
147147
public selectOption(value: string) {
148148
const optionIndex = this.options.findIndex((option) => value === option.value);
149149
if (optionIndex < 0 && (this.optionsSelected[0] || this.optionsSelected[optionIndex])) return;
150-
if (this.multipleAllowed) {
150+
if (this.multipleAllowed && !this.selectMultipleWithCtrl) {
151151
// Select the option with the specified value
152152
this.optionsSelected[optionIndex] = true;
153153
} else {
@@ -173,7 +173,7 @@ class Dropdown {
173173
public unselectOption(value: string) {
174174
const optionIndex = this.options.findIndex((option) => value === option.value);
175175
if (optionIndex < 0 && (this.optionsSelected[0] || this.optionsSelected[optionIndex])) return;
176-
if (this.multipleAllowed || this.selectMultipleWithCtrl) {
176+
if (this.multipleAllowed) {
177177
if (this.optionsSelected[0]) {
178178
// Show All is currently selected, so unselect it, and select all branch options
179179
this.optionsSelected[0] = false;
@@ -237,7 +237,7 @@ class Dropdown {
237237
for (let i = 0; i < this.options.length; i++) {
238238
const escapedName = escapeHtml(this.options[i].name);
239239
html += '<div class="dropdownOption' + (this.optionsSelected[i] ? ' ' + CLASS_SELECTED : '') + '" data-id="' + i + '" title="' + escapedName + '">' +
240-
((this.multipleAllowed || this.selectMultipleWithCtrl) && this.optionsSelected[i] ? '<div class="dropdownOptionMultiSelected">' + SVG_ICONS.check + '</div>' : '') +
240+
(this.multipleAllowed && this.optionsSelected[i] ? '<div class="dropdownOptionMultiSelected">' + SVG_ICONS.check + '</div>' : '') +
241241
escapedName + (typeof this.options[i].hint === 'string' && this.options[i].hint !== '' ? '<span class="dropdownOptionHint">' + escapeHtml(this.options[i].hint!) + '</span>' : '') +
242242
(this.showInfo ? '<div class="dropdownOptionInfo" title="' + escapeHtml(this.options[i].value) + '">' + SVG_ICONS.info + '</div>' : '') +
243243
'</div>';
@@ -276,7 +276,7 @@ class Dropdown {
276276
*/
277277
private getSelectedOptions(names: boolean) {
278278
let selected = [];
279-
if ((this.multipleAllowed || this.selectMultipleWithCtrl) && this.optionsSelected[0]) {
279+
if (this.multipleAllowed && this.optionsSelected[0]) {
280280
// Note: Show All is always the first option (0 index) when multiple selected items are allowed
281281
return [names ? this.options[0].name : this.options[0].value];
282282
}
@@ -295,18 +295,19 @@ class Dropdown {
295295
let change = false;
296296
let doubleClick = this.doubleClickTimeout !== null && this.lastClicked === option;
297297
if (this.doubleClickTimeout !== null) this.clearDoubleClickTimeout();
298-
298+
// eslint-disable-next-line no-console
299+
console.log('test');
299300
if (doubleClick) {
300301
// Double click
301-
if ((this.multipleAllowed || this.selectMultipleWithCtrl) && option === 0) {
302+
if ((this.multipleAllowed) && option === 0) {
302303
for (let i = 1; i < this.optionsSelected.length; i++) {
303304
this.optionsSelected[i] = !this.optionsSelected[i];
304305
}
305306
change = true;
306307
}
307308
} else {
308309
// Single Click
309-
if (this.multipleAllowed || (this.selectMultipleWithCtrl && event && (event.ctrlKey || event.metaKey))) {
310+
if (this.multipleAllowed && (!this.selectMultipleWithCtrl || (event && (event.ctrlKey || event.metaKey)))) {
310311
// Multiple dropdown options can be selected
311312
if (option === 0) {
312313
// Show All was selected

web/main.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,20 @@ class GitGraphView {
8686
this.loadRepo(values[0]);
8787
});
8888

89-
this.branchDropdown = new Dropdown('branchDropdown', false, this.config.selectMultipleBranches, 'Branches', (values) => {
89+
this.branchDropdown = new Dropdown('branchDropdown', false, true, 'Branches', (values) => {
9090
this.currentBranches = values;
9191
this.maxCommits = this.config.initialLoadCommits;
9292
this.saveState();
9393
this.clearCommits();
9494
this.requestLoadRepoInfoAndCommits(true, true);
95-
});
96-
this.authorDropdown = new Dropdown('authorDropdown', false, this.config.selectMultipleAuthors, 'Authors', (values) => {
95+
}, !this.config.selectMultipleBranches);
96+
this.authorDropdown = new Dropdown('authorDropdown', false, true, 'Authors', (values) => {
9797
this.currentAuthors = values;
9898
this.maxCommits = this.config.initialLoadCommits;
9999
this.saveState();
100100
this.clearCommits();
101101
this.requestLoadRepoInfoAndCommits(true, true);
102-
});
102+
}, !this.config.selectMultipleAuthors);
103103
this.showRemoteBranchesElem = <HTMLInputElement>document.getElementById('showRemoteBranchesCheckbox')!;
104104
this.showRemoteBranchesElem.addEventListener('change', () => {
105105
this.saveRepoStateValue(this.currentRepo, 'showRemoteBranchesV2', this.showRemoteBranchesElem.checked ? GG.BooleanOverride.Enabled : GG.BooleanOverride.Disabled);

0 commit comments

Comments
 (0)