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 18c06025f8..40a90b760f 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 @@ -77,6 +77,7 @@ limitations under the License. _builder: Object, _groups: Array, _layers: Array, + _showTabs: Boolean, }, get diffElement() { @@ -92,6 +93,7 @@ limitations under the License. this._layers = [ this.$.syntaxLayer, this._createIntralineLayer(), + this._createTabIndicatorLayer(), this.$.rangeLayer, ]; @@ -102,6 +104,7 @@ limitations under the License. render: function(comments, prefs) { this.$.syntaxLayer.enabled = prefs.syntax_highlighting; + this._showTabs = !!prefs.show_tabs; // Stop the processor (if it's running). this.$.processor.cancel(); @@ -330,6 +333,31 @@ limitations under the License. }; }, + _createTabIndicatorLayer: function() { + var show = (function() { return this._showTabs; }).bind(this); + return { + addListener: function() {}, + annotate: function(el, line) { + // If visible tabs are disabled, do nothing. + if (!show()) { return; } + + // Find and annotate the locations of tabs. + var split = line.text.split('\t'); + if (!split) { return; } + for (var i = 0, pos = 0; i < split.length - 1; i++) { + // Skip forward by the length of the content + pos += split[i].length; + + GrAnnotation.annotateElement(el, pos, 1, + 'style-scope gr-diff tab-indicator'); + + // Skip forward by one tab character. + pos++; + } + }, + }; + }, + /** * In pages with large diffs, creating the first comment thread can be * slow because nested Polymer elements (particularly diff --git a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.js b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.js index 2090e98e1a..670885a21f 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.js +++ b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.js @@ -493,7 +493,7 @@ for (var i = 0; i < split.length - 1; i++) { offset += split[i].length; width = tabSize - (offset % tabSize); - result += split[i] + this._getTabWrapper(width, this._prefs.show_tabs); + result += split[i] + this._getTabWrapper(width); offset += width; } if (split.length) { @@ -503,7 +503,7 @@ return result; }; - GrDiffBuilder.prototype._getTabWrapper = function(tabSize, showTabs) { + GrDiffBuilder.prototype._getTabWrapper = function(tabSize) { // Force this to be a number to prevent arbitrary injection. tabSize = +tabSize; if (isNaN(tabSize)) { @@ -511,9 +511,6 @@ } var str = '