Skip to content

Commit 38cc2f4

Browse files
authored
Merge pull request #1 from char8x/feat_disable_selection_highlight
feat: notify configuration reload
2 parents dccd118 + f1dff6a commit 38cc2f4

6 files changed

Lines changed: 45 additions & 12 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ dist
33
node_modules
44
.vscode-test/
55
*.vsix
6+
test-fixture/.vscode/

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"id": "terminateAll",
108108
"type": "command",
109109
"command": "workbench.action.tasks.terminate",
110-
"args": "terminateAll" // 终止所有运行任务;如果只想终止特定任务,可手动选择
110+
"args": "terminateAll"
111111
}
112112
]
113113
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
"description": "Rendering styles for irrelevant code",
2828
"default": {
2929
"opacity": "0.2",
30-
"backgroundColor": "transparent",
31-
"border": "none"
30+
"backgroundColor": "transparent"
3231
}
3332
},
3433
"codeFader.autoUnfold": {

src/extension.ts

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,31 +144,59 @@ async function calculateRanges(
144144
);
145145
}
146146

147-
export async function activate(context: vscode.ExtensionContext) {
147+
function loadSettings() {
148148
const config = vscode.workspace.getConfiguration();
149-
let isEnabled = config.get<boolean>('codeFader.enabled');
150-
const isAutoUnfold = config.get<boolean>('codeFader.autoUnfold');
149+
151150
const decorationSetting = Object.assign(
152151
{
153152
opacity: '0.2',
154153
backgroundColor: 'transparent',
155-
border: 'none',
156154
} as vscode.ThemableDecorationRenderOptions,
157155
config.get<vscode.ThemableDecorationRenderOptions>('codeFader.decoration')
158156
);
159157
let codeDecoration =
160158
vscode.window.createTextEditorDecorationType(decorationSetting);
161159

160+
let isEnabled = config.get<boolean>('codeFader.enabled');
161+
const isAutoUnfold = config.get<boolean>('codeFader.autoUnfold');
162+
163+
return { isEnabled, codeDecoration, isAutoUnfold };
164+
}
165+
166+
function subscribeSelectionHighlightBorderChange(
167+
context: vscode.ExtensionContext
168+
) {
169+
let isPromptVisible = false;
170+
171+
async function showReloadPrompt() {
172+
if (isPromptVisible) return;
173+
174+
isPromptVisible = true;
175+
const selection = await vscode.window.showInformationMessage(
176+
'Configuration changes have been detected. Reload now?',
177+
'Reload'
178+
);
179+
isPromptVisible = false;
180+
181+
if (selection === 'Reload') {
182+
vscode.commands.executeCommand('workbench.action.reloadWindow');
183+
}
184+
}
185+
186+
// Listen for Configuration Change Events
162187
context.subscriptions.push(
163188
vscode.workspace.onDidChangeConfiguration((event) => {
164189
if (event.affectsConfiguration('codeFader.enabled')) {
165-
const updatedValue = vscode.workspace
166-
.getConfiguration()
167-
.get<boolean>('codeFader.enabled');
168-
isEnabled = updatedValue;
190+
showReloadPrompt();
169191
}
170192
})
171193
);
194+
}
195+
196+
export async function activate(context: vscode.ExtensionContext) {
197+
subscribeSelectionHighlightBorderChange(context);
198+
199+
let { isEnabled, codeDecoration, isAutoUnfold } = loadSettings();
172200

173201
let selectionVersion = 0;
174202

test-fixture/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vscode/

test-fixture/.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"editor.selectionHighlight": true
2+
"editor.selectionHighlight": true,
3+
"codeFader.enabled": true,
4+
"workbench.colorCustomizations": {
5+
"editor.selectionHighlightBorder": "default"
6+
}
37
}

0 commit comments

Comments
 (0)