Merge "Move annotation layer initialization from attached() to render()"

This commit is contained in:
Yuke Liao 2018-11-30 21:56:32 +00:00 committed by Gerrit Code Review
commit 36786eaf54
2 changed files with 28 additions and 22 deletions

View File

@ -124,26 +124,13 @@ limitations under the License.
'_groupsChanged(_groups.splices)',
],
attached() {
// Setup annotation layers.
const layers = [
this._createTrailingWhitespaceLayer(),
this.$.syntaxLayer,
this._createIntralineLayer(),
this._createTabIndicatorLayer(),
this.$.rangeLayer,
];
// Get layers from plugins (if any).
for (const pluginLayer of this.$.jsAPI.getDiffLayers(
this.diffPath, this.changeNum, this.patchNum)) {
layers.push(pluginLayer);
}
this._layers = layers;
},
render(keyLocations, prefs) {
// Setting up annotation layers must happen after plugins are
// installed, and |render| satisfies the requirement, however,
// |attached| doesn't because in the diff view page, the element is
// attached before plugins are installed.
this._setupAnnotationLayers();
this.$.syntaxLayer.enabled = prefs.syntax_highlighting;
this._showTabs = !!prefs.show_tabs;
this._showTrailingWhitespace = !!prefs.show_whitespace_errors;
@ -188,6 +175,24 @@ limitations under the License.
});
},
_setupAnnotationLayers() {
const layers = [
this._createTrailingWhitespaceLayer(),
this.$.syntaxLayer,
this._createIntralineLayer(),
this._createTabIndicatorLayer(),
this.$.rangeLayer,
];
// Get layers from plugins (if any).
for (const pluginLayer of this.$.jsAPI.getDiffLayers(
this.diffPath, this.changeNum, this.patchNum)) {
layers.push(pluginLayer);
}
this._layers = layers;
},
getLineElByChild(node) {
while (node) {
if (node instanceof Element) {

View File

@ -582,13 +582,14 @@ limitations under the License.
setup(() => {
element = fixture('basic');
element._showTrailingWhitespace = true;
element._setupAnnotationLayers();
initialLayersCount = element._layers.length;
});
test('no plugin layers', () => {
const getDiffLayersStub = sinon.stub(element.$.jsAPI, 'getDiffLayers')
.returns([]);
element.attached();
element._setupAnnotationLayers();
assert.isTrue(getDiffLayersStub.called);
assert.equal(element._layers.length, initialLayersCount);
});
@ -596,9 +597,9 @@ limitations under the License.
test('with plugin layers', () => {
const getDiffLayersStub = sinon.stub(element.$.jsAPI, 'getDiffLayers')
.returns([{}, {}]);
element.attached();
element._setupAnnotationLayers();
assert.isTrue(getDiffLayersStub.called);
assert.equal(element._layers.length, initialLayersCount+2);
assert.equal(element._layers.length, initialLayersCount + 2);
});
});