Skip to content

Commit 241a097

Browse files
committed
feat: Refactor configuration saving logic and enhance auto-save functionality in UI
1 parent be7d5e5 commit 241a097

File tree

1 file changed

+45
-30
lines changed

1 file changed

+45
-30
lines changed

src/providers/uiProvider.ts

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,6 @@ export class UiProvider implements vscode.WebviewViewProvider {
9292
);
9393

9494
await Promise.all([
95-
workspaceConfig.update(
96-
"github.token",
97-
config.githubToken,
98-
vscode.ConfigurationTarget.Global
99-
),
100-
workspaceConfig.update(
101-
"github.owner",
102-
config.githubOwner,
103-
vscode.ConfigurationTarget.Workspace
104-
),
105-
workspaceConfig.update(
106-
"github.repo",
107-
config.githubRepo,
108-
vscode.ConfigurationTarget.Workspace
109-
),
11095
workspaceConfig.update(
11196
"suites",
11297
config.suites,
@@ -117,11 +102,6 @@ export class UiProvider implements vscode.WebviewViewProvider {
117102
config.languages,
118103
vscode.ConfigurationTarget.Workspace
119104
),
120-
workspaceConfig.update(
121-
"codeqlPath",
122-
config.codeqlPath,
123-
vscode.ConfigurationTarget.Global
124-
),
125105
workspaceConfig.update(
126106
"threatModel",
127107
config.threatModel,
@@ -2010,20 +1990,22 @@ export class UiProvider implements vscode.WebviewViewProvider {
20101990
const vscode = acquireVsCodeApi();
20111991
20121992
function saveConfig() {
1993+
console.log('Saving configuration...');
20131994
const config = {
2014-
githubToken: document.getElementById('githubToken').value,
2015-
githubOwner: document.getElementById('githubOwner').value,
2016-
githubRepo: document.getElementById('githubRepo').value,
20171995
suites: [getSelectedSuite()],
20181996
languages: getSelectedLanguages(),
2019-
codeqlPath: document.getElementById('codeqlPath').value,
20201997
threatModel: getSelectedThreatModel()
20211998
};
20221999
2000+
console.log('Configuration to save:', config);
2001+
20232002
vscode.postMessage({
20242003
command: 'saveConfig',
20252004
config: config
20262005
});
2006+
2007+
// Show auto-save indicator for automatic saves
2008+
showAutoSaveIndicator();
20272009
}
20282010
20292011
function getSelectedSuite() {
@@ -2131,18 +2113,42 @@ export class UiProvider implements vscode.WebviewViewProvider {
21312113
21322114
// Add event listener for automatic configuration saving
21332115
checkbox.addEventListener('change', function() {
2134-
// Auto-save configuration when language selection changes
2135-
saveConfig();
2136-
2116+
console.log('Language checkbox changed:', lang, 'checked:', checkbox.checked);
2117+
21372118
// Update visual state
21382119
if (checkbox.checked) {
21392120
checkboxContainer.classList.add('selected');
21402121
} else {
21412122
checkboxContainer.classList.remove('selected');
21422123
}
2124+
2125+
// Auto-save configuration when language selection changes
2126+
saveConfig();
21432127
});
21442128
checkbox.setAttribute('data-listener-attached', 'true');
21452129
2130+
// Add direct event listener to the toggle slider for better UX
2131+
toggleSlider.addEventListener('click', function(e) {
2132+
console.log('Toggle slider clicked for:', lang);
2133+
e.preventDefault();
2134+
e.stopPropagation();
2135+
checkbox.checked = !checkbox.checked;
2136+
console.log('Checkbox state changed to:', checkbox.checked);
2137+
// Manually trigger the change event which will call saveConfig()
2138+
checkbox.dispatchEvent(new Event('change'));
2139+
});
2140+
2141+
// Also add event listener to the entire toggle container for maximum clickable area
2142+
toggleContainer.addEventListener('click', function(e) {
2143+
console.log('Toggle container clicked for:', lang);
2144+
e.preventDefault();
2145+
e.stopPropagation();
2146+
checkbox.checked = !checkbox.checked;
2147+
console.log('Checkbox state changed to:', checkbox.checked, 'via toggle container');
2148+
// Manually trigger the change event which will call saveConfig()
2149+
checkbox.dispatchEvent(new Event('change'));
2150+
});
2151+
21462152
const icon = document.createElement('span');
21472153
icon.className = 'language-icon language-' + lang;
21482154
icon.textContent = getLanguageIcon(lang);
@@ -2151,10 +2157,19 @@ export class UiProvider implements vscode.WebviewViewProvider {
21512157
label.htmlFor = 'lang-' + lang;
21522158
label.innerHTML = icon.outerHTML + '<span>' + lang + '</span>';
21532159
2154-
// Make the entire container clickable
2160+
// Make the entire container clickable, but prevent double events
21552161
checkboxContainer.addEventListener('click', function(e) {
2156-
if (e.target !== checkbox) {
2157-
checkbox.click();
2162+
console.log('Container clicked for:', lang, 'target:', e.target.className, 'checkbox:', e.target === checkbox, 'toggleSlider:', e.target === toggleSlider);
2163+
2164+
// Only trigger click if the target is not the checkbox itself or its toggle components
2165+
if (e.target !== checkbox && e.target !== toggleSlider && !toggleContainer.contains(e.target)) {
2166+
console.log('Container click triggering checkbox change for:', lang);
2167+
e.preventDefault();
2168+
checkbox.checked = !checkbox.checked;
2169+
// Manually trigger the change event
2170+
checkbox.dispatchEvent(new Event('change'));
2171+
} else {
2172+
console.log('Container click ignored for:', lang, 'due to target being toggle component');
21582173
}
21592174
});
21602175

0 commit comments

Comments
 (0)