Skip to content

Commit 7006e18

Browse files
authored
The compiler path selection control is not in sync with the textbox (#12678)
1 parent f077665 commit 7006e18

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

Extension/ui/settings.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ class SettingsApp {
109109
document.getElementById(elementId.configName)?.addEventListener("change", this.onConfigNameChanged.bind(this));
110110
document.getElementById(elementId.configSelection)?.addEventListener("change", this.onConfigSelect.bind(this));
111111
document.getElementById(elementId.addConfigBtn)?.addEventListener("click", this.onAddConfigBtn.bind(this));
112-
document.getElementById(elementId.addConfigOk)?.addEventListener("click", this.OnAddConfigConfirm.bind(this, true));
113-
document.getElementById(elementId.addConfigCancel)?.addEventListener("click", this.OnAddConfigConfirm.bind(this, false));
112+
document.getElementById(elementId.addConfigOk)?.addEventListener("click", this.onAddConfigConfirm.bind(this, true));
113+
document.getElementById(elementId.addConfigCancel)?.addEventListener("click", this.onAddConfigConfirm.bind(this, false));
114114
}
115115

116116
private onTabKeyDown(e: any): void {
@@ -148,7 +148,7 @@ class SettingsApp {
148148
this.showElement(elementId.addConfigInputDiv, true);
149149
}
150150

151-
private OnAddConfigConfirm(request: boolean): void {
151+
private onAddConfigConfirm(request: boolean): void {
152152
this.showElement(elementId.addConfigInputDiv, false);
153153
this.showElement(elementId.addConfigDiv, true);
154154

@@ -204,18 +204,30 @@ class SettingsApp {
204204
if (this.updating) {
205205
return;
206206
}
207-
const el: HTMLInputElement = <HTMLInputElement>document.getElementById(elementId.knownCompilers);
207+
const el: HTMLSelectElement = <HTMLSelectElement>document.getElementById(elementId.knownCompilers);
208208
(<HTMLInputElement>document.getElementById(elementId.compilerPath)).value = el.value;
209209
this.onChanged(elementId.compilerPath);
210210

211211
// Post message that this control was used for telemetry
212212
this.vsCodeApi.postMessage({
213213
command: "knownCompilerSelect"
214214
});
215+
}
215216

216-
// Reset selection to none
217-
el.value = "";
217+
// To enable custom entries, the compiler path control is a text box on top of a select control.
218+
// This function ensures that the select control is updated when the text box is changed.
219+
private fixKnownCompilerSelection(): void {
220+
const compilerPath = (<HTMLInputElement>document.getElementById(elementId.compilerPath)).value.toLowerCase();
221+
const knownCompilers = <HTMLSelectElement>document.getElementById(elementId.knownCompilers);
222+
for (let n = 0; n < knownCompilers.options.length; n++) {
223+
if (compilerPath === knownCompilers.options[n].value.toLowerCase()) {
224+
knownCompilers.value = knownCompilers.options[n].value;
225+
return;
226+
}
227+
}
228+
knownCompilers.value = '';
218229
}
230+
219231
private onChangedCheckbox(id: string): void {
220232
if (this.updating) {
221233
return;
@@ -235,6 +247,9 @@ class SettingsApp {
235247
}
236248

237249
const el: HTMLInputElement = <HTMLInputElement>document.getElementById(id);
250+
if (id === elementId.compilerPath) {
251+
this.fixKnownCompilerSelection();
252+
}
238253
this.vsCodeApi.postMessage({
239254
command: "change",
240255
key: id,
@@ -268,6 +283,7 @@ class SettingsApp {
268283
// Basic settings
269284
(<HTMLInputElement>document.getElementById(elementId.configName)).value = config.name;
270285
(<HTMLInputElement>document.getElementById(elementId.compilerPath)).value = config.compilerPath ? config.compilerPath : "";
286+
this.fixKnownCompilerSelection();
271287
(<HTMLInputElement>document.getElementById(elementId.compilerArgs)).value = joinEntries(config.compilerArgs);
272288

273289
(<HTMLInputElement>document.getElementById(elementId.intelliSenseMode)).value = config.intelliSenseMode ? config.intelliSenseMode : "${default}";

0 commit comments

Comments
 (0)