Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
- Fixed Todo and embedded file grouping so similarly prefixed sibling folders are not treated as workspace roots.
- Preserved CRLF line endings when merging tasks into existing archive files.
- Fixed embedded todo type icons so changes to `todo.colors.types` apply without restarting VS Code.
- Fixed embedded todo type icons so `todo.colors.dark.types` and `todo.colors.light.types` apply in their matching themes.
- Added optional whole-line background colors for configured special tags with `todo.colors.tags.lineBackground`. Fixes: https://github.com/vycdev/vscode-todo-plus-two/issues/93
- Added TextMate syntax scopes so Todo projects, standard statuses, tags, and formatting are visible in the editor minimap. Fixes: https://github.com/vycdev/vscode-todo-plus-two/issues/70
- Added a command to copy the project at the cursor with its rendered statistics included as text. Fixes: https://github.com/vycdev/vscode-todo-plus-two/issues/73
Expand Down
39 changes: 26 additions & 13 deletions src/utils/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ const View = {
icons: {},

getTypeIcon(type) {
//TODO: Add support for light/dark colors

const color = Consts.colors.types[type];

if (!color) return;
Expand All @@ -37,23 +35,38 @@ const View = {

if (!storagePath) return;

const colorHash = sha1(color),
iconPath = path.join(storagePath, `type-color-${colorHash}.svg`),
iconKey = `${type}:${colorHash}`;
const getIconPath = (iconColor: string) => {
const colorHash = sha1(iconColor),
iconPath = path.join(storagePath, `type-color-${colorHash}.svg`),
iconKey = `${type}:${colorHash}`;

if (View.icons[iconKey]) return View.icons[iconKey];

mkdirp.sync(storagePath);

if (!fs.existsSync(iconPath)) {
const image = `<?xml version="1.0" encoding="utf-8"?><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 16 16" style="enable-background:new 0 0 16 16;" xml:space="preserve"><circle fill="${iconColor}" cx="8" cy="8" r="5.4"/></svg>`;

if (View.icons[iconKey]) return View.icons[iconKey];
fs.writeFileSync(iconPath, image);
}

mkdirp.sync(storagePath);
View.icons[iconKey] = iconPath;

if (!fs.existsSync(iconPath)) {
const image = `<?xml version="1.0" encoding="utf-8"?><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 16 16" style="enable-background:new 0 0 16 16;" xml:space="preserve"><circle fill="${color}" cx="8" cy="8" r="5.4"/></svg>`;
return iconPath;
};

fs.writeFileSync(iconPath, image);
}
const darkColor =
(Consts.colors.dark && Consts.colors.dark.types && Consts.colors.dark.types[type]) || color,
lightColor =
(Consts.colors.light && Consts.colors.light.types && Consts.colors.light.types[type]) ||
color;

View.icons[iconKey] = iconPath;
if (darkColor === color && lightColor === color) return getIconPath(color);

return iconPath;
return {
dark: getIconPath(darkColor),
light: getIconPath(lightColor),
};
},
};

Expand Down
20 changes: 20 additions & 0 deletions test/view-icons.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ describe('View type icons', () => {
});
});

it('uses theme-specific type colors for light and dark icons', () => {
withView(
{
types: { TODO: '#ff0000' },
dark: { types: { TODO: '#00ff00' } },
light: { types: { TODO: '#0000ff' } },
},
(view, writtenPaths) => {
expect(view.getTypeIcon('TODO')).to.deep.equal({
dark: path.join('/storage', 'type-color-hash-#00ff00.svg'),
light: path.join('/storage', 'type-color-hash-#0000ff.svg'),
});
expect(writtenPaths).to.deep.equal([
path.join('/storage', 'type-color-hash-#00ff00.svg'),
path.join('/storage', 'type-color-hash-#0000ff.svg'),
]);
}
);
});

it('uses extension-wide storage when no workspace is open', () => {
withView(
{ types: { TODO: '#ff0000' } },
Expand Down
Loading