Skip to content

fix: resolve stale highlights and settings reload issues #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,36 @@ function activate(context) {

workspace.onDidChangeConfiguration(function () {
settings = workspace.getConfiguration('todohighlight');

//NOTE: if disabled, do not re-initialize the data or we will not be able to clear the style immediatly via 'toggle highlight' command
if (!settings.get('isEnable')) return;

init(settings);

// Clear all existing decorations first
Object.keys(decorationTypes).forEach((v) => {
decorationTypes[v].dispose();
});
decorationTypes = {};

// Only reinitialize if enabled
if (settings.get('isEnable')) {
init(settings);
}

triggerUpdateDecorations();
}, null, context.subscriptions);

function updateDecorations() {

if (!activeEditor || !activeEditor.document) {
return;
}

// Clear all existing decorations first
Object.keys(decorationTypes).forEach((v) => {
activeEditor.setDecorations(decorationTypes[v], []);
});

// Only proceed with new decorations if enabled
if (!settings.get('isEnable')) {
return;
}

var text = activeEditor.document.getText();
var mathes = {}, match;
while (match = pattern.exec(text)) {
Expand All @@ -108,14 +124,14 @@ function activate(context) {
}
}

// Apply new decorations
Object.keys(decorationTypes).forEach((v) => {
if (!isCaseSensitive) {
v = v.toUpperCase();
}
var rangeOption = settings.get('isEnable') && mathes[v] ? mathes[v] : [];
var decorationType = decorationTypes[v];
activeEditor.setDecorations(decorationType, rangeOption);
})
var rangeOption = mathes[v] ? mathes[v] : [];
activeEditor.setDecorations(decorationTypes[v], rangeOption);
});
}

function init(settings) {
Expand Down