Skip to content

Commit

Permalink
Early work on Dark/Light Theme mode #49
Browse files Browse the repository at this point in the history
  • Loading branch information
jgclark committed Apr 13, 2023
1 parent df12cb0 commit f63412e
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"keyword",
"annotation"
],
"version": "2.0.8",
"version": "2.0.9",
"publisher": "jgclark",
"license": "MIT",
"icon": "assets/icon.png",
Expand Down Expand Up @@ -134,6 +134,14 @@
"type": "string",
"description": "The text background color."
},
"backgroundColorDark": {
"type": "string",
"description": "The text background color (in dark mode)"
},
"backgroundColorLight": {
"type": "string",
"description": "The text background color (in light mode)"
},
"border": {
"type": "string",
"description": "The border style for the highlight, as a CSS string."
Expand Down Expand Up @@ -197,6 +205,14 @@
"type": "string",
"description": "The background color for the highlight."
},
"backgroundColorDark": {
"type": "string",
"description": "The background color for the highlight (used in dark themes)."
},
"backgroundColorLight": {
"type": "string",
"description": "The background color for the highlight (used in light themes)."
},
"border": {
"type": "string",
"description": "The border style for the highlight, as a CSS string."
Expand All @@ -205,6 +221,14 @@
"type": "string",
"markdownDescription": "The text color."
},
"colorDark": {
"type": "string",
"markdownDescription": "The text color (used in dark themes)."
},
"colorLight": {
"type": "string",
"markdownDescription": "The text color (used in light themes)."
},
"cursor": {
"type": "string",
"description": "The style for the cursor shown over the highlight, as a CSS property."
Expand Down
8 changes: 8 additions & 0 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ function activate(context) {

function updateDecorations() {

if (!settings.get('isEnable')) {
return;
}
if (!activeEditor || !activeEditor.document) {
return;
}
Expand Down Expand Up @@ -155,6 +158,7 @@ function activate(context) {
diagnostics.set(activeEditor.document.uri, problems);
}


function init(settings) {
var customDefaultStyle = settings.get('defaultStyle');
keywordsPattern = settings.get('keywordsPattern');
Expand All @@ -167,6 +171,10 @@ function activate(context) {
window.outputChannel = window.createOutputChannel('TodoHighlight');
}

let isDarkTheme = vscode.window.dark ?? false

vscode.window.showInformationMessage(`Current theme is ${vscode.window.activeColorTheme} type ${isDarkTheme ? 'dark' : 'light'}`);

decorationTypes = {};

if (keywordsPattern.trim()) {
Expand Down
48 changes: 40 additions & 8 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,26 @@ var DEFAULT_STYLE = {
backgroundColor: "#ffeb3b",
};

/**
* Get the details for each defined highlight, using the DEFAULT_STYLE where necessary.
* @param {Object | Array<string>} keywords
* @param {Object} customDefaultStyle
* @param {boolean} isCaseSensitive
* @returns {null | boolean | ?}
*/
function getAssembledData(keywords, customDefaultStyle, isCaseSensitive) {
var result = {}, regex = [], reg;
// Object.keys(keywords).forEach((v) => {
keywords.forEach((v) => {
v = typeof v == 'string' ? { text: v } : v;
v = typeof v === 'string' ? { text: v } : v;
var text = v.text;
if (!text) return;//NOTE: in case of the text is empty
if (!text) return; //NOTE: in case of the text is empty

if (!isCaseSensitive) {
text = text.toUpperCase();
}

if (text == 'TODO:' || text == 'FIXME:') {
if (text === 'TODO:' || text === 'FIXME:') {
v = Object.assign({}, DEFAULT_KEYWORDS[text], v);
}
v.diagnosticSeverity = SeverityMap[v.diagnosticSeverity]
Expand Down Expand Up @@ -85,7 +93,7 @@ function chooseAnnotationType(availableAnnotationTypes) {
}

//get the include/exclude config
function getPathes(config) {
function getPaths(config) {
return Array.isArray(config) ?
'{' + config.join(',') + ',' + '}'
: (typeof config == 'string' ? config : '');
Expand All @@ -94,8 +102,8 @@ function getPathes(config) {
function isFileNameOk(filename) {

var settings = workspace.getConfiguration('todohighlight');
var includePatterns = getPathes(settings.get('include')) || '{**/*}';
var excludePatterns = getPathes(settings.get('exclude'));
var includePatterns = getPaths(settings.get('include')) || '{**/*}';
var excludePatterns = getPaths(settings.get('exclude'));

if (minimatch(filename, includePatterns) && !minimatch(filename, excludePatterns)) {
return true;
Expand All @@ -108,8 +116,8 @@ function isFileNameOk(filename) {
function searchAnnotations(workspaceState, pattern, callback) {

var settings = workspace.getConfiguration('todohighlight');
var includePattern = getPathes(settings.get('include')) || '{**/*}';
var excludePattern = getPathes(settings.get('exclude'));
var includePattern = getPaths(settings.get('include')) || '{**/*}';
var excludePattern = getPaths(settings.get('exclude'));
var limitationForSearch = settings.get('maxFilesForSearch', 5120);

var statusMsg = ` Searching...`;
Expand Down Expand Up @@ -161,6 +169,13 @@ function searchAnnotations(workspaceState, pattern, callback) {
});
}

/**
* Search 'file'. Rest is not clear to me.
* @param {*} file
* @param {*} annotations
* @param {*} annotationList
* @param {RegExp} regexp
*/
function searchAnnotationInFile(file, annotations, annotationList, regexp) {
var fileInUri = file.uri.toString();
var pathWithoutFile = fileInUri.substring(7, fileInUri.length);
Expand Down Expand Up @@ -193,6 +208,13 @@ function searchAnnotationInFile(file, annotations, annotationList, regexp) {
}
}

/**
* Show all annotations in Output channel
* Confusingly also shows err as well??
* @param {string ?} err
* @param {?} annotations - Note: not used
* @param {?} annotationList
*/
function annotationsFound(err, annotations, annotationList) {
if (err) {
console.log('todohighlight err:', err);
Expand All @@ -206,6 +228,10 @@ function annotationsFound(err, annotations, annotationList) {
showOutputChannel(annotationList);
}

/**
* Show each item in the 'data' in Output channel
* @param {?} data
*/
function showOutputChannel(data) {
if (!window.outputChannel) return;
window.outputChannel.clear();
Expand Down Expand Up @@ -241,6 +267,12 @@ function showOutputChannel(data) {
window.outputChannel.show();
}

/**
* Get content of 'lineText' that matches 'match' ?
* @param {string} lineText
* @param {string} match
* @returns {string}
*/
function getContent(lineText, match) {
return lineText.substring(lineText.indexOf(match[0]), lineText.length);
};
Expand Down
Binary file added vscode-todo-highlight-2.0.9.vsix
Binary file not shown.

0 comments on commit f63412e

Please sign in to comment.