diff --git a/polygerrit-ui/app/elements/diff/gr-diff-selection/gr-diff-selection.js b/polygerrit-ui/app/elements/diff/gr-diff-selection/gr-diff-selection.js index 10f04c6048..c354882a65 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-selection/gr-diff-selection.js +++ b/polygerrit-ui/app/elements/diff/gr-diff-selection/gr-diff-selection.js @@ -24,6 +24,8 @@ RIGHT: 'selected-right', }; + var getNewCache = function() { return {left: null, right: null}; }; + Polymer({ is: 'gr-diff-selection', @@ -32,10 +34,14 @@ _cachedDiffBuilder: Object, _linesCache: { type: Object, - value: function() { return {left: null, right: null}; }, + value: getNewCache(), }, }, + observers: [ + '_diffChanged(diff)', + ], + listeners: { 'copy': '_handleCopy', 'down': '_handleDown', @@ -53,6 +59,10 @@ return this._cachedDiffBuilder; }, + _diffChanged: function() { + this._linesCache = getNewCache(); + }, + _handleDown: function(e) { var lineEl = this.diffBuilder.getLineElByChild(e.target); if (!lineEl) { diff --git a/polygerrit-ui/app/elements/diff/gr-diff-selection/gr-diff-selection_test.html b/polygerrit-ui/app/elements/diff/gr-diff-selection/gr-diff-selection_test.html index d517a801a3..86edf6b40c 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-selection/gr-diff-selection_test.html +++ b/polygerrit-ui/app/elements/diff/gr-diff-selection/gr-diff-selection_test.html @@ -325,5 +325,12 @@ limitations under the License. 'is is a co'); }); }); + + test('cache is reset when diff changes', function() { + element._linesCache = {left: 'test', right: 'test'}; + element.diff = {}; + flushAsynchronousOperations(); + assert.deepEqual(element._linesCache, {left: null, right: null}); + }); }); </script>