From 53a2b68b57231ac3ca2a3a3bb5aa0cf1079c0925 Mon Sep 17 00:00:00 2001 From: Ryuichi Inagaki Date: Fri, 4 Nov 2016 23:14:48 +1100 Subject: [PATCH] refs #4 Use overviewRuler to point out where the highlighted texts exist in the file --- lib/app-factory.js | 6 +++++- lib/decoration-registry.js | 15 ++++++++++++++- test/lib/decoration-registry.test.js | 21 ++++++++++++++++----- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/lib/app-factory.js b/lib/app-factory.js index 8645211..52272c0 100644 --- a/lib/app-factory.js +++ b/lib/app-factory.js @@ -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}); diff --git a/lib/decoration-registry.js b/lib/decoration-registry.js index b4142d7..b411a68 100644 --- a/lib/decoration-registry.js +++ b/lib/decoration-registry.js @@ -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) { @@ -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; diff --git a/test/lib/decoration-registry.test.js b/test/lib/decoration-registry.test.js index 58b8cb5..87d42b0 100644 --- a/test/lib/decoration-registry.test.js +++ b/test/lib/decoration-registry.test.js @@ -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'); }); @@ -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; @@ -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({ @@ -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' + }] ]); });