diff --git a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.html b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.html index 098a4af1a7..42a262a2ed 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.html +++ b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.html @@ -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) { diff --git a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder_test.html b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder_test.html index 1b0ba04286..294d08538b 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder_test.html +++ b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder_test.html @@ -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); }); });