Skip to content

Commit

Permalink
Add icons to gutter
Browse files Browse the repository at this point in the history
  • Loading branch information
Nigel Scott committed Jan 20, 2020
1 parent 93c224f commit 6b8506d
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 193 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ Both `defaultHighlight` and `customHighlight` allow for the following settings:

`background` - used to set the background colour of the highlight in the editor.

*Note: Foreground and background colours can be one of "red", "green", "blue", "yellow", "magenta", "cyan", "grey", "white" or "black". RGB values can also be used (e.g. "#80FF00"). You can also use colours from the current theme, e.g. `peekViewResult.background`.*

`opacity` - percentage value used with the background colour. 100% will produce an opaque background which will obscure selection and other decorations. *Note: opacity is ignored when theme colours are used.*

`fontWeight`, `fontStyle`, `textDecoration` - can be used to style the highlight with standard CSS values.

`borderRadius` - used to set the border radius of the background of the highlight.

Foreground and background colours can be one of "red", "green", "blue", "yellow", "magenta", "cyan", "grey", "white" or "black". RGB values can also be used (e.g. "#80FF00"). You can also use colours from the current theme, e.g. `peekViewResult.background`.

`icon` - used to set a different icon in the tree view. Must be a valid octicon (see https://octicons.github.com/). Defaults to a tick if it's not valid. You can also use "todo-tree", or "todo-tree-filled" if you want to use the icon from the activity view.

`iconColour` - used to set the colour of the icon in the tree. If not specified, it will try to use the foreground colour, the background colour and then the older settings, in that order.

`gutterIcon` - set to true to show the icon in the editor gutter.

`rulerColour` - used to set the colour of the marker in the overview ruler. If not specified, it will to use the foreground colour.

`rulerLane` - used to set the lane for the marker in the overview ruler. If not specified, it will default to the right hand lane. Use one of "left", "center", "right", or "full". You can also use "none" to disable the ruler markers.
Expand Down Expand Up @@ -70,7 +72,8 @@ Example:
},
"FIXME": {
"foreground": "black",
"iconColour": "yellow"
"iconColour": "yellow",
"gutterIcon": true
}
}
```
Expand Down
60 changes: 60 additions & 0 deletions attributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
var vscode = require( 'vscode' );

function getAttribute( tag, attribute, defaultValue )
{
function getCustomHighlightSettings( customHighlight, tag )
{
var result;
Object.keys( customHighlight ).map( function( t )
{
var flags = '';
if( vscode.workspace.getConfiguration( 'todo-tree.regex' ).get( 'regexCaseSensitive' ) === false )
{
flags += 'i';
}
t = t.replace( /\\/g, '\\\\' );
t = t.replace( /[|{}()[\]^$+*?.-]/g, '\\$&' );

var regex = new RegExp( t, flags );

if( tag.match( regex ) )
{
result = customHighlight[ tag ];
}
} );
return result;
}

var config = vscode.workspace.getConfiguration( 'todo-tree.highlights' );
var tagSettings = getCustomHighlightSettings( config.customHighlight, tag );
if( tagSettings && tagSettings[ attribute ] !== undefined )
{
return tagSettings[ attribute ];
}
else
{
var defaultHighlight = config.get( 'defaultHighlight' );
if( defaultHighlight[ attribute ] !== undefined )
{
return defaultHighlight[ attribute ];
}
}
return defaultValue;
}

function getIcon( tag )
{
return getAttribute( tag, 'icon', undefined );
}

function getIconColour( tag )
{
var foreground = getAttribute( tag, 'foreground', undefined );
var background = getAttribute( tag, 'background', undefined );

return getAttribute( tag, 'iconColour', foreground ? foreground : ( background ? background : "green" ) );
}

module.exports.getAttribute = getAttribute;
module.exports.getIcon = getIcon;
module.exports.getIconColour = getIconColour;
114 changes: 114 additions & 0 deletions colours.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
var vscode = require( 'vscode' );

var utils = require( './utils.js' );

var defaultColours = [ "red", "green", "blue", "yellow", "magenta", "cyan", "grey", "white", "black" ];

var defaultLightColours = {
"red": "#CC0000",
"green": "#008f00",
"blue": "#0433ff",
"yellow": "#c8c800",
"magenta": "#bb60bb",
"cyan": "#76d6ff",
"grey": "#888888",
"white": "#ffffff",
"black": "#000000"
};

var defaultDarkColours = {
"red": "#CC0000",
"green": "#6AC259",
"blue": "#0433ff",
"yellow": "#fffb00",
"magenta": "#ff85ff",
"cyan": "#76d6ff",
"grey": "#aaaaaa",
"white": "#ffffff",
"black": "#000000"
};

var complementaryColours = {};

function getColourList()
{
return defaultColours;
}

function complementaryColour( colour )
{
var hex = colour.split( / / )[ 0 ].replace( /[^\da-fA-F]/g, '' );
var digits = hex.length / 3;
var red = parseInt( hex.substr( 0, digits ), 16 );
var green = parseInt( hex.substr( 1 * digits, digits ), 16 );
var blue = parseInt( hex.substr( 2 * digits, digits ), 16 );
var c = [ red / 255, green / 255, blue / 255 ];
for( var i = 0; i < c.length; ++i )
{
if( c[ i ] <= 0.03928 )
{
c[ i ] = c[ i ] / 12.92;
} else
{
c[ i ] = Math.pow( ( c[ i ] + 0.055 ) / 1.055, 2.4 );
}
}
var l = 0.2126 * c[ 0 ] + 0.7152 * c[ 1 ] + 0.0722 * c[ 2 ];
return l > 0.179 ? "#000000" : "#ffffff";
}

function getOtherColours()
{
function addColour( colour )
{
if( colour !== undefined )
{
colours.push( colour );
}
}

var colours = [];

var config = vscode.workspace.getConfiguration( 'todo-tree.highlights' );
var customHighlight = config.get( 'customHighlight' );

addColour( config.get( 'defaultHighlight' ).foreground );
addColour( config.get( 'defaultHighlight' ).background );
Object.keys( customHighlight ).map( function( tag )
{
addColour( customHighlight[ tag ].foreground );
addColour( customHighlight[ tag ].background );
} );

return colours;
}

function refreshComplementaryColours()
{
complementaryColours = {};

Object.keys( defaultLightColours ).forEach( function( colour )
{
complementaryColours[ defaultLightColours[ colour ] ] = complementaryColour( defaultLightColours[ colour ] );
} );
Object.keys( defaultDarkColours ).forEach( function( colour )
{
complementaryColours[ defaultDarkColours[ colour ] ] = complementaryColour( defaultDarkColours[ colour ] );
} );

var otherColours = getOtherColours();

otherColours.forEach( function( colour )
{
if( utils.isHexColour( colour ) )
{
complementaryColours[ colour ] = complementaryColour( colour );
}
} );
}

module.exports.getColourList = getColourList;
module.exports.refreshComplementaryColours = refreshComplementaryColours;
module.exports.complementaryColours = complementaryColours;
module.exports.defaultLightColours = defaultLightColours;
module.exports.defaultDarkColours = defaultDarkColours;
5 changes: 3 additions & 2 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var os = require( 'os' );
var fs = require( 'fs' );

var tree = require( "./tree.js" );
var colours = require( './colours.js' );
var highlights = require( './highlights.js' );
var config = require( './config.js' );
var utils = require( './utils.js' );
Expand Down Expand Up @@ -1152,7 +1153,7 @@ function activate( context )
e.affectsConfiguration( "todo-tree.highlights.defaultHighlight" ) ||
e.affectsConfiguration( "todo-tree.highlights.customHighlight" ) )
{
highlights.refreshComplementaryColours();
colours.refreshComplementaryColours();
if( vscode.window.activeTextEditor )
{
documentChanged( vscode.window.activeTextEditor.document );
Expand Down Expand Up @@ -1203,7 +1204,7 @@ function activate( context )

resetOutputChannel();

highlights.refreshComplementaryColours();
colours.refreshComplementaryColours();

migrateSettings();
setButtonsAndContext();
Expand Down
Loading

0 comments on commit 6b8506d

Please sign in to comment.