-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref #5 Restore saved highlights on extension start up
- Loading branch information
Showing
5 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
const {Event} = require('./const'); | ||
|
||
class SavedHighlightsRestorer { | ||
|
||
constructor(params) { | ||
this._configStore = params.configStore; | ||
this._decorationOperatorFactory = params.decorationOperatorFactory; | ||
this._patternFactory = params.patternFactory; | ||
this._eventBus = params.eventBus; | ||
|
||
this._registerListeners(); | ||
} | ||
|
||
_registerListeners() { | ||
this._eventBus.on(Event.EXTENSION_READY, this._restore.bind(this)); | ||
} | ||
|
||
_restore() { | ||
const decorationsData = this._configStore.get('savedHighlights'); | ||
const decorationOperator = this._decorationOperatorFactory.createForVisibleEditors(); | ||
decorationsData.forEach(decorationData => this._addDecoration(decorationData, decorationOperator)); | ||
} | ||
|
||
_addDecoration(decorationData, decorationOperator) { | ||
const pattern = this._patternFactory.create(decorationData.pattern); | ||
decorationOperator.addDecoration(pattern); | ||
} | ||
|
||
} | ||
|
||
module.exports = SavedHighlightsRestorer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
const EventEmitter = require('events'); | ||
const {Event} = require('../../lib/const'); | ||
const SavedHighlightsRestorer = require('../../lib/saved-highlights-restorer'); | ||
|
||
suite('SavedHighlightsRestorer', () => { | ||
|
||
test('it restores saved highlights', done => { | ||
const eventBus = new EventEmitter(); | ||
const configStore = {get: stubWithArgs(['savedHighlights'], [{pattern: 'PATTERN_DATA'}])}; | ||
const decorationOperator = {addDecoration: sinon.spy()}; | ||
const decorationOperatorFactory = {createForVisibleEditors: () => decorationOperator}; | ||
const patternFactory = {create: stubWithArgs(['PATTERN_DATA'], 'PATTERN')}; | ||
new SavedHighlightsRestorer({eventBus, configStore, decorationOperatorFactory, patternFactory}); // eslint-disable-line no-new | ||
|
||
eventBus.on(Event.EXTENSION_READY, () => { | ||
expect(decorationOperator.addDecoration).to.have.been.calledWith('PATTERN'); | ||
done(); | ||
}); | ||
|
||
eventBus.emit(Event.EXTENSION_READY); | ||
}); | ||
|
||
}); |