Skip to content

Commit

Permalink
refs #4 Use overviewRuler to point out where the highlighted texts ex…
Browse files Browse the repository at this point in the history
…ist in the file
  • Loading branch information
ryu1kn committed Nov 4, 2016
1 parent caf55bc commit 53a2b68
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/app-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ class AppFactory {
create(vscode, logger) {
const configStore = new ConfigStore({workspace: vscode.workspace});
const colourRegistry = new ColourRegistry({configStore});
const decorationRegistry = new DecorationRegistry({colourRegistry, window: vscode.window});
const decorationRegistry = new DecorationRegistry({
colourRegistry,
window: vscode.window,
OverviewRulerLane: vscode.OverviewRulerLane
});
const textLocator = new TextLocator({Range: vscode.Range});
const textDecorator = new TextDecorator({textLocator});
const decorationOperatorFactory = new DecorationOperatorFactory({textDecorator, decorationRegistry});
Expand Down
15 changes: 14 additions & 1 deletion lib/decoration-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@

const _ = require('lodash');

const OVERVIEW_RULER_COLOUR = 'violet';

class DecorationRegistry {

constructor(params) {
this._colourRegistry = params.colourRegistry;
this._window = params.window;
this._textDecorationMap = {};

// NOTE: OverviewRulerLane should be set as module variable; but it
// doesn't work as the contents of vscode module is different
// at real execution and test time..., so I use DI here.
this._OverviewRulerLane = params.OverviewRulerLane;
}

inquire(string) {
Expand Down Expand Up @@ -36,8 +44,13 @@ class DecorationRegistry {
}

_generateDecorationType(colour) {
return this._window.createTextEditorDecorationType({backgroundColor: colour});
return this._window.createTextEditorDecorationType({
backgroundColor: colour,
overviewRulerColor: OVERVIEW_RULER_COLOUR,
overviewRulerLane: this._OverviewRulerLane.Center
});
}

}

module.exports = DecorationRegistry;
21 changes: 16 additions & 5 deletions test/lib/decoration-registry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ const DecorationRegistry = require('../../lib/decoration-registry');

suite('DecorationRegistry', () => {

const OverviewRulerLane = {Center: 'OVERVIEW_RULER_LANE'};

test('it returns a registered decoration type for the passed string', () => {
const window = {createTextEditorDecorationType: () => 'DECORATION_TYPE'};
const colourRegistry = {issue: () => 'pink'};
const registry = new DecorationRegistry({colourRegistry, window});
const registry = new DecorationRegistry({colourRegistry, window, OverviewRulerLane});
registry.issue('TEXT');
expect(registry.inquire('TEXT')).to.eql('DECORATION_TYPE');
});
Expand All @@ -17,7 +19,7 @@ suite('DecorationRegistry', () => {
issue: () => 'pink',
revoke: () => {}
};
const registry = new DecorationRegistry({colourRegistry, window});
const registry = new DecorationRegistry({colourRegistry, window, OverviewRulerLane});
registry.issue('TEXT');
registry.revoke('TEXT');
expect(registry.inquire('TEXT')).to.be.null;
Expand All @@ -28,7 +30,7 @@ suite('DecorationRegistry', () => {
const window = {
createTextEditorDecorationType: () => decorationTypes.shift()};
const colourRegistry = {issue: () => 'pink'};
const registry = new DecorationRegistry({colourRegistry, window});
const registry = new DecorationRegistry({colourRegistry, window, OverviewRulerLane});
registry.issue('TEXT_1');
registry.issue('TEXT_2');
expect(registry.retrieveAll()).to.eql({
Expand All @@ -40,12 +42,21 @@ suite('DecorationRegistry', () => {
test('it issues new decoration with new color', () => {
const window = {createTextEditorDecorationType: sinon.stub().returns('DECORATION_TYPE')};
const colourRegistry = {issue: stubReturns('pink', 'yellow')};
const registry = new DecorationRegistry({colourRegistry, window});
const registry = new DecorationRegistry({colourRegistry, window, OverviewRulerLane});
registry.issue('TEXT_1');
registry.issue('TEXT_2');

expect(window.createTextEditorDecorationType.args).to.eql([
[{backgroundColor: 'pink'}], [{backgroundColor: 'yellow'}]
[{
backgroundColor: 'pink',
overviewRulerColor: 'violet',
overviewRulerLane: 'OVERVIEW_RULER_LANE'
}],
[{
backgroundColor: 'yellow',
overviewRulerColor: 'violet',
overviewRulerLane: 'OVERVIEW_RULER_LANE'
}]
]);
});

Expand Down

0 comments on commit 53a2b68

Please sign in to comment.