2016-06-01 11:41:47 -07:00
|
|
|
<!--
|
|
|
|
Copyright (C) 2016 The Android Open Source Project
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
-->
|
|
|
|
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
2016-08-18 16:45:05 -07:00
|
|
|
<link rel="import" href="../../core/gr-reporting/gr-reporting.html">
|
2016-08-08 16:35:01 -07:00
|
|
|
<link rel="import" href="../gr-diff-comment-thread/gr-diff-comment-thread.html">
|
2017-01-27 15:33:08 -08:00
|
|
|
<link rel="import" href="../gr-diff-comment-thread-group/gr-diff-comment-thread-group.html">
|
2016-06-27 12:19:21 -07:00
|
|
|
<link rel="import" href="../gr-diff-processor/gr-diff-processor.html">
|
2016-07-14 12:31:09 -07:00
|
|
|
<link rel="import" href="../gr-ranged-comment-layer/gr-ranged-comment-layer.html">
|
2016-06-22 17:18:06 -07:00
|
|
|
<link rel="import" href="../gr-syntax-layer/gr-syntax-layer.html">
|
2016-08-18 16:45:05 -07:00
|
|
|
|
2016-06-01 11:41:47 -07:00
|
|
|
<dom-module id="gr-diff-builder">
|
|
|
|
<template>
|
|
|
|
<div class="contentWrapper">
|
|
|
|
<content></content>
|
|
|
|
</div>
|
2016-07-14 12:31:09 -07:00
|
|
|
<gr-ranged-comment-layer
|
|
|
|
id="rangeLayer"
|
|
|
|
comments="[[comments]]"></gr-ranged-comment-layer>
|
2016-06-22 17:18:06 -07:00
|
|
|
<gr-syntax-layer
|
|
|
|
id="syntaxLayer"
|
|
|
|
diff="[[diff]]"></gr-syntax-layer>
|
2016-06-28 16:40:46 -07:00
|
|
|
<gr-diff-processor
|
|
|
|
id="processor"
|
|
|
|
groups="{{_groups}}"></gr-diff-processor>
|
2016-08-18 16:45:05 -07:00
|
|
|
<gr-reporting id="reporting"></gr-reporting>
|
2016-06-01 11:41:47 -07:00
|
|
|
</template>
|
|
|
|
<script src="../gr-diff/gr-diff-line.js"></script>
|
|
|
|
<script src="../gr-diff/gr-diff-group.js"></script>
|
2016-07-13 10:59:10 -07:00
|
|
|
<script src="../gr-diff-highlight/gr-annotation.js"></script>
|
2016-06-01 11:41:47 -07:00
|
|
|
<script src="gr-diff-builder.js"></script>
|
|
|
|
<script src="gr-diff-builder-side-by-side.js"></script>
|
|
|
|
<script src="gr-diff-builder-unified.js"></script>
|
|
|
|
<script src="gr-diff-builder-image.js"></script>
|
|
|
|
<script>
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var DiffViewMode = {
|
|
|
|
SIDE_BY_SIDE: 'SIDE_BY_SIDE',
|
|
|
|
UNIFIED: 'UNIFIED_DIFF',
|
|
|
|
};
|
|
|
|
|
2016-08-09 15:52:04 -07:00
|
|
|
var TimingLabel = {
|
|
|
|
TOTAL: 'Diff Total Render',
|
|
|
|
CONTENT: 'Diff Content Render',
|
|
|
|
SYNTAX: 'Diff Syntax Render',
|
|
|
|
};
|
|
|
|
|
2016-10-10 17:05:32 -07:00
|
|
|
// If any line of the diff is more than the character limit, then disable
|
|
|
|
// syntax highlighting for the entire file.
|
|
|
|
var SYNTAX_MAX_LINE_LENGTH = 500;
|
|
|
|
|
2016-11-17 12:03:51 -08:00
|
|
|
var TRAILING_WHITESPACE_PATTERN = /\s+$/;
|
|
|
|
|
2016-06-01 11:41:47 -07:00
|
|
|
Polymer({
|
|
|
|
is: 'gr-diff-builder',
|
|
|
|
|
2016-09-29 15:29:18 -07:00
|
|
|
/**
|
|
|
|
* Fired when the diff begins rendering.
|
|
|
|
*
|
|
|
|
* @event render-start
|
|
|
|
*/
|
|
|
|
|
2016-06-01 11:41:47 -07:00
|
|
|
/**
|
|
|
|
* Fired when the diff is rendered.
|
|
|
|
*
|
|
|
|
* @event render
|
|
|
|
*/
|
|
|
|
|
|
|
|
properties: {
|
2016-07-21 22:19:25 -07:00
|
|
|
diff: Object,
|
2016-06-01 11:41:47 -07:00
|
|
|
viewMode: String,
|
2016-07-14 12:31:09 -07:00
|
|
|
comments: Object,
|
2016-06-01 11:41:47 -07:00
|
|
|
isImageDiff: Boolean,
|
|
|
|
baseImage: Object,
|
|
|
|
revisionImage: Object,
|
|
|
|
_builder: Object,
|
2016-06-28 16:40:46 -07:00
|
|
|
_groups: Array,
|
2016-07-14 12:31:09 -07:00
|
|
|
_layers: Array,
|
Improves visible tabs rendering
This change reverts visible tabs to use the » character. A few different
approaches have been used for rendering these tab indicators:
I: Before the Annotation Pipeline, tab indicators were configured by a
class that was optionally applied to tab elements by the diff
builder. The class was guarded by the show_tabs preference and a CSS
rule created a `::before` pseudo element to insert the character.
(Thus also preventing the » from being copyable text.)
II: When the Annotation Pipeline was implemented, the ordering of layers
called for intraline difference elements being rendered *inside* tab
indicators. As a result, the » indicator would sometimes have a
different background than the intraline difference, looking sloppy.
To solve this, the pseudo element was positioned using absolute,
allowing the pseudo element to consume no horizontal space and and
the intraline background to extend across the entire tab.
III:When performance tuning, it was discovered that the
absolute-positioned tab indicators were positioned incorrectly when
GPU acceleration was hinted for the diff, so the containing tab
elements were made relative.
IV: Continuing performance tuning, the tab indicators seemed to slow
scrolling on very large diffs with tabs. It was mistakenly assumed
(by me) that this was related to the pseudo-elements when it was
actually caused by the thousands of positioning contexts they
created using relative and absolute.
Instead they were modified to use strike-through instead of a pseudo
element, which was more-performant, but less-usable (it looked bad).
With this change, we roll-back the clock a little and solve a core
problem: namely that tab indicators were not annotated inside the
intraline differences. Fixing that, positioning tricks are no-longer
needed to make the background look right.
To do this, we decouple the tab elements (which control tab width) from
the tab indicators (which optionally make tabs visible). This is done
using an annotation layer that inserts tab indicator elements wherever
a tab character is used in the source content, and it does so after
intraline differences have been applied.
Bug: Issue 4441
Change-Id: I4fea2a3a20a7039bfeb746bd1e1c1004e43c4801
2016-08-25 11:31:42 -07:00
|
|
|
_showTabs: Boolean,
|
2016-06-01 11:41:47 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
get diffElement() {
|
|
|
|
return this.queryEffectiveChildren('#diffTable');
|
|
|
|
},
|
|
|
|
|
2016-06-28 16:40:46 -07:00
|
|
|
observers: [
|
|
|
|
'_groupsChanged(_groups.splices)',
|
|
|
|
],
|
|
|
|
|
2016-07-14 12:31:09 -07:00
|
|
|
attached: function() {
|
|
|
|
// Setup annotation layers.
|
|
|
|
this._layers = [
|
2016-11-17 12:03:51 -08:00
|
|
|
this._createTrailingWhitespaceLayer(),
|
2016-06-22 17:18:06 -07:00
|
|
|
this.$.syntaxLayer,
|
2016-07-14 12:31:09 -07:00
|
|
|
this._createIntralineLayer(),
|
Improves visible tabs rendering
This change reverts visible tabs to use the » character. A few different
approaches have been used for rendering these tab indicators:
I: Before the Annotation Pipeline, tab indicators were configured by a
class that was optionally applied to tab elements by the diff
builder. The class was guarded by the show_tabs preference and a CSS
rule created a `::before` pseudo element to insert the character.
(Thus also preventing the » from being copyable text.)
II: When the Annotation Pipeline was implemented, the ordering of layers
called for intraline difference elements being rendered *inside* tab
indicators. As a result, the » indicator would sometimes have a
different background than the intraline difference, looking sloppy.
To solve this, the pseudo element was positioned using absolute,
allowing the pseudo element to consume no horizontal space and and
the intraline background to extend across the entire tab.
III:When performance tuning, it was discovered that the
absolute-positioned tab indicators were positioned incorrectly when
GPU acceleration was hinted for the diff, so the containing tab
elements were made relative.
IV: Continuing performance tuning, the tab indicators seemed to slow
scrolling on very large diffs with tabs. It was mistakenly assumed
(by me) that this was related to the pseudo-elements when it was
actually caused by the thousands of positioning contexts they
created using relative and absolute.
Instead they were modified to use strike-through instead of a pseudo
element, which was more-performant, but less-usable (it looked bad).
With this change, we roll-back the clock a little and solve a core
problem: namely that tab indicators were not annotated inside the
intraline differences. Fixing that, positioning tricks are no-longer
needed to make the background look right.
To do this, we decouple the tab elements (which control tab width) from
the tab indicators (which optionally make tabs visible). This is done
using an annotation layer that inserts tab indicator elements wherever
a tab character is used in the source content, and it does so after
intraline differences have been applied.
Bug: Issue 4441
Change-Id: I4fea2a3a20a7039bfeb746bd1e1c1004e43c4801
2016-08-25 11:31:42 -07:00
|
|
|
this._createTabIndicatorLayer(),
|
2016-07-14 12:31:09 -07:00
|
|
|
this.$.rangeLayer,
|
|
|
|
];
|
2016-08-08 16:35:01 -07:00
|
|
|
|
|
|
|
this.async(function() {
|
|
|
|
this._preRenderThread();
|
|
|
|
});
|
2016-07-14 12:31:09 -07:00
|
|
|
},
|
|
|
|
|
2016-07-21 22:19:25 -07:00
|
|
|
render: function(comments, prefs) {
|
2016-07-27 10:32:44 -07:00
|
|
|
this.$.syntaxLayer.enabled = prefs.syntax_highlighting;
|
Improves visible tabs rendering
This change reverts visible tabs to use the » character. A few different
approaches have been used for rendering these tab indicators:
I: Before the Annotation Pipeline, tab indicators were configured by a
class that was optionally applied to tab elements by the diff
builder. The class was guarded by the show_tabs preference and a CSS
rule created a `::before` pseudo element to insert the character.
(Thus also preventing the » from being copyable text.)
II: When the Annotation Pipeline was implemented, the ordering of layers
called for intraline difference elements being rendered *inside* tab
indicators. As a result, the » indicator would sometimes have a
different background than the intraline difference, looking sloppy.
To solve this, the pseudo element was positioned using absolute,
allowing the pseudo element to consume no horizontal space and and
the intraline background to extend across the entire tab.
III:When performance tuning, it was discovered that the
absolute-positioned tab indicators were positioned incorrectly when
GPU acceleration was hinted for the diff, so the containing tab
elements were made relative.
IV: Continuing performance tuning, the tab indicators seemed to slow
scrolling on very large diffs with tabs. It was mistakenly assumed
(by me) that this was related to the pseudo-elements when it was
actually caused by the thousands of positioning contexts they
created using relative and absolute.
Instead they were modified to use strike-through instead of a pseudo
element, which was more-performant, but less-usable (it looked bad).
With this change, we roll-back the clock a little and solve a core
problem: namely that tab indicators were not annotated inside the
intraline differences. Fixing that, positioning tricks are no-longer
needed to make the background look right.
To do this, we decouple the tab elements (which control tab width) from
the tab indicators (which optionally make tabs visible). This is done
using an annotation layer that inserts tab indicator elements wherever
a tab character is used in the source content, and it does so after
intraline differences have been applied.
Bug: Issue 4441
Change-Id: I4fea2a3a20a7039bfeb746bd1e1c1004e43c4801
2016-08-25 11:31:42 -07:00
|
|
|
this._showTabs = !!prefs.show_tabs;
|
2016-11-17 12:03:51 -08:00
|
|
|
this._showTrailingWhitespace = !!prefs.show_whitespace_errors;
|
2016-07-27 10:32:44 -07:00
|
|
|
|
2016-06-28 16:40:46 -07:00
|
|
|
// Stop the processor (if it's running).
|
|
|
|
this.$.processor.cancel();
|
2016-06-22 17:18:06 -07:00
|
|
|
this.$.syntaxLayer.cancel();
|
2016-06-28 16:40:46 -07:00
|
|
|
|
2016-07-21 22:19:25 -07:00
|
|
|
this._builder = this._getDiffBuilder(this.diff, comments, prefs);
|
2016-06-27 12:19:21 -07:00
|
|
|
|
|
|
|
this.$.processor.context = prefs.context;
|
|
|
|
this.$.processor.keyLocations = this._getCommentLocations(comments);
|
2016-06-28 16:40:46 -07:00
|
|
|
|
|
|
|
this._clearDiffContent();
|
2016-10-31 14:35:35 -07:00
|
|
|
this._builder.addColumns(this.diffElement, prefs.font_size);
|
2016-06-28 16:40:46 -07:00
|
|
|
|
2016-08-18 16:45:05 -07:00
|
|
|
var reporting = this.$.reporting;
|
|
|
|
|
|
|
|
reporting.time(TimingLabel.TOTAL);
|
|
|
|
reporting.time(TimingLabel.CONTENT);
|
2016-09-29 15:29:18 -07:00
|
|
|
this.fire('render-start');
|
2016-07-21 22:19:25 -07:00
|
|
|
return this.$.processor.process(this.diff.content).then(function() {
|
2016-06-28 16:40:46 -07:00
|
|
|
if (this.isImageDiff) {
|
|
|
|
this._builder.renderDiffImages();
|
|
|
|
}
|
2016-10-10 17:05:32 -07:00
|
|
|
|
|
|
|
if (this._anyLineTooLong()) {
|
|
|
|
this.$.syntaxLayer.enabled = false;
|
|
|
|
}
|
|
|
|
|
2016-08-18 16:45:05 -07:00
|
|
|
reporting.timeEnd(TimingLabel.CONTENT);
|
|
|
|
reporting.time(TimingLabel.SYNTAX);
|
2017-02-06 14:20:00 -08:00
|
|
|
return this.$.syntaxLayer.process().then(function() {
|
2016-08-18 16:45:05 -07:00
|
|
|
reporting.timeEnd(TimingLabel.SYNTAX);
|
|
|
|
reporting.timeEnd(TimingLabel.TOTAL);
|
2017-02-06 14:20:00 -08:00
|
|
|
this.fire('render');
|
|
|
|
}.bind(this));
|
2016-06-28 16:40:46 -07:00
|
|
|
}.bind(this));
|
2016-06-01 11:41:47 -07:00
|
|
|
},
|
|
|
|
|
2016-06-09 16:39:17 -07:00
|
|
|
getLineElByChild: function(node) {
|
|
|
|
while (node) {
|
|
|
|
if (node instanceof Element) {
|
|
|
|
if (node.classList.contains('lineNum')) {
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
if (node.classList.contains('section')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
node = node.previousSibling || node.parentElement;
|
2016-06-15 11:57:36 -07:00
|
|
|
}
|
2016-06-09 16:39:17 -07:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2016-06-06 12:20:31 -07:00
|
|
|
getLineNumberByChild: function(node) {
|
|
|
|
var lineEl = this.getLineElByChild(node);
|
|
|
|
return lineEl ?
|
|
|
|
parseInt(lineEl.getAttribute('data-value'), 10) : null;
|
|
|
|
},
|
|
|
|
|
2016-06-09 16:08:04 -07:00
|
|
|
getContentByLine: function(lineNumber, opt_side, opt_root) {
|
2016-07-15 17:08:22 -07:00
|
|
|
return this._builder.getContentByLine(lineNumber, opt_side, opt_root);
|
2016-06-09 16:08:04 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
getContentByLineEl: function(lineEl) {
|
|
|
|
var root = Polymer.dom(lineEl.parentElement);
|
|
|
|
var side = this.getSideByLineEl(lineEl);
|
|
|
|
var line = lineEl.getAttribute('data-value');
|
|
|
|
return this.getContentByLine(line, side, root);
|
|
|
|
},
|
|
|
|
|
|
|
|
getLineElByNumber: function(lineNumber, opt_side) {
|
|
|
|
var sideSelector = !!opt_side ? ('.' + opt_side) : '';
|
|
|
|
return this.diffElement.querySelector(
|
|
|
|
'.lineNum[data-value="' + lineNumber + '"]' + sideSelector);
|
|
|
|
},
|
|
|
|
|
|
|
|
getContentsByLineRange: function(startLine, endLine, opt_side) {
|
2016-07-15 17:08:22 -07:00
|
|
|
var result = [];
|
|
|
|
this._builder.findLinesByRange(startLine, endLine, opt_side, null,
|
|
|
|
result);
|
|
|
|
return result;
|
2016-06-09 16:08:04 -07:00
|
|
|
},
|
|
|
|
|
2016-06-09 16:39:17 -07:00
|
|
|
getSideByLineEl: function(lineEl) {
|
|
|
|
return lineEl.classList.contains(GrDiffBuilder.Side.RIGHT) ?
|
2016-06-09 16:08:04 -07:00
|
|
|
GrDiffBuilder.Side.RIGHT : GrDiffBuilder.Side.LEFT;
|
2016-06-09 16:39:17 -07:00
|
|
|
},
|
|
|
|
|
2017-01-27 15:33:08 -08:00
|
|
|
createCommentThreadGroup: function(changeNum, patchNum, path, side,
|
2017-01-30 12:03:13 -08:00
|
|
|
commentSide, projectConfig) {
|
2017-01-27 15:33:08 -08:00
|
|
|
return this._builder.createCommentThreadGroup(changeNum, patchNum,
|
2017-01-30 12:03:13 -08:00
|
|
|
path, side, commentSide, projectConfig);
|
2016-06-01 11:41:47 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
emitGroup: function(group, sectionEl) {
|
|
|
|
this._builder.emitGroup(group, sectionEl);
|
|
|
|
},
|
|
|
|
|
|
|
|
showContext: function(newGroups, sectionEl) {
|
2016-06-27 12:19:21 -07:00
|
|
|
var groups = this._builder.groups;
|
2016-06-01 11:41:47 -07:00
|
|
|
// TODO(viktard): Polyfill findIndex for IE10.
|
|
|
|
var contextIndex = groups.findIndex(function(group) {
|
|
|
|
return group.element == sectionEl;
|
|
|
|
});
|
|
|
|
groups.splice.apply(groups, [contextIndex, 1].concat(newGroups));
|
|
|
|
|
|
|
|
newGroups.forEach(function(newGroup) {
|
|
|
|
this._builder.emitGroup(newGroup, sectionEl);
|
2016-06-09 16:08:04 -07:00
|
|
|
}, this);
|
2016-06-01 11:41:47 -07:00
|
|
|
sectionEl.parentNode.removeChild(sectionEl);
|
|
|
|
|
|
|
|
this.async(function() {
|
|
|
|
this.fire('render');
|
2016-06-09 16:08:04 -07:00
|
|
|
}, 1);
|
2016-06-01 11:41:47 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_getDiffBuilder: function(diff, comments, prefs) {
|
|
|
|
if (this.isImageDiff) {
|
|
|
|
return new GrDiffBuilderImage(diff, comments, prefs,
|
|
|
|
this.diffElement, this.baseImage, this.revisionImage);
|
|
|
|
} else if (this.viewMode === DiffViewMode.SIDE_BY_SIDE) {
|
|
|
|
return new GrDiffBuilderSideBySide(
|
2016-07-14 12:31:09 -07:00
|
|
|
diff, comments, prefs, this.diffElement, this._layers);
|
2016-06-01 11:41:47 -07:00
|
|
|
} else if (this.viewMode === DiffViewMode.UNIFIED) {
|
|
|
|
return new GrDiffBuilderUnified(
|
2016-07-14 12:31:09 -07:00
|
|
|
diff, comments, prefs, this.diffElement, this._layers);
|
2016-06-01 11:41:47 -07:00
|
|
|
}
|
|
|
|
throw Error('Unsupported diff view mode: ' + this.viewMode);
|
|
|
|
},
|
|
|
|
|
|
|
|
_clearDiffContent: function() {
|
|
|
|
this.diffElement.innerHTML = null;
|
|
|
|
},
|
2016-06-27 12:19:21 -07:00
|
|
|
|
|
|
|
_getCommentLocations: function(comments) {
|
|
|
|
var result = {
|
|
|
|
left: {},
|
|
|
|
right: {},
|
|
|
|
};
|
|
|
|
for (var side in comments) {
|
|
|
|
if (side !== GrDiffBuilder.Side.LEFT &&
|
|
|
|
side !== GrDiffBuilder.Side.RIGHT) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
comments[side].forEach(function(c) {
|
|
|
|
result[side][c.line || GrDiffLine.FILE] = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
2016-06-28 16:40:46 -07:00
|
|
|
|
|
|
|
_groupsChanged: function(changeRecord) {
|
|
|
|
if (!changeRecord) { return; }
|
|
|
|
changeRecord.indexSplices.forEach(function(splice) {
|
|
|
|
var group;
|
|
|
|
for (var i = 0; i < splice.addedCount; i++) {
|
|
|
|
group = splice.object[splice.index + i];
|
|
|
|
this._builder.groups.push(group);
|
|
|
|
this._builder.emitGroup(group);
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
},
|
2016-07-19 10:59:31 -07:00
|
|
|
|
|
|
|
_createIntralineLayer: function() {
|
|
|
|
return {
|
|
|
|
// Take a DIV.contentText element and a line object with intraline
|
|
|
|
// differences to highlight and apply them to the element as
|
|
|
|
// annotations.
|
2016-07-25 22:46:20 -07:00
|
|
|
annotate: function(el, line) {
|
2016-06-22 17:18:06 -07:00
|
|
|
var HL_CLASS = 'style-scope gr-diff intraline';
|
2016-07-19 10:59:31 -07:00
|
|
|
line.highlights.forEach(function(highlight) {
|
|
|
|
// The start and end indices could be the same if a highlight is
|
|
|
|
// meant to start at the end of a line and continue onto the
|
|
|
|
// next one. Ignore it.
|
|
|
|
if (highlight.startIndex === highlight.endIndex) { return; }
|
|
|
|
|
|
|
|
// If endIndex isn't present, continue to the end of the line.
|
|
|
|
var endIndex = highlight.endIndex === undefined ?
|
|
|
|
line.text.length : highlight.endIndex;
|
|
|
|
|
|
|
|
GrAnnotation.annotateElement(
|
|
|
|
el,
|
|
|
|
highlight.startIndex,
|
|
|
|
endIndex - highlight.startIndex,
|
|
|
|
HL_CLASS);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2016-08-08 16:35:01 -07:00
|
|
|
|
Improves visible tabs rendering
This change reverts visible tabs to use the » character. A few different
approaches have been used for rendering these tab indicators:
I: Before the Annotation Pipeline, tab indicators were configured by a
class that was optionally applied to tab elements by the diff
builder. The class was guarded by the show_tabs preference and a CSS
rule created a `::before` pseudo element to insert the character.
(Thus also preventing the » from being copyable text.)
II: When the Annotation Pipeline was implemented, the ordering of layers
called for intraline difference elements being rendered *inside* tab
indicators. As a result, the » indicator would sometimes have a
different background than the intraline difference, looking sloppy.
To solve this, the pseudo element was positioned using absolute,
allowing the pseudo element to consume no horizontal space and and
the intraline background to extend across the entire tab.
III:When performance tuning, it was discovered that the
absolute-positioned tab indicators were positioned incorrectly when
GPU acceleration was hinted for the diff, so the containing tab
elements were made relative.
IV: Continuing performance tuning, the tab indicators seemed to slow
scrolling on very large diffs with tabs. It was mistakenly assumed
(by me) that this was related to the pseudo-elements when it was
actually caused by the thousands of positioning contexts they
created using relative and absolute.
Instead they were modified to use strike-through instead of a pseudo
element, which was more-performant, but less-usable (it looked bad).
With this change, we roll-back the clock a little and solve a core
problem: namely that tab indicators were not annotated inside the
intraline differences. Fixing that, positioning tricks are no-longer
needed to make the background look right.
To do this, we decouple the tab elements (which control tab width) from
the tab indicators (which optionally make tabs visible). This is done
using an annotation layer that inserts tab indicator elements wherever
a tab character is used in the source content, and it does so after
intraline differences have been applied.
Bug: Issue 4441
Change-Id: I4fea2a3a20a7039bfeb746bd1e1c1004e43c4801
2016-08-25 11:31:42 -07:00
|
|
|
_createTabIndicatorLayer: function() {
|
2016-11-17 12:03:51 -08:00
|
|
|
var show = function() { return this._showTabs; }.bind(this);
|
Improves visible tabs rendering
This change reverts visible tabs to use the » character. A few different
approaches have been used for rendering these tab indicators:
I: Before the Annotation Pipeline, tab indicators were configured by a
class that was optionally applied to tab elements by the diff
builder. The class was guarded by the show_tabs preference and a CSS
rule created a `::before` pseudo element to insert the character.
(Thus also preventing the » from being copyable text.)
II: When the Annotation Pipeline was implemented, the ordering of layers
called for intraline difference elements being rendered *inside* tab
indicators. As a result, the » indicator would sometimes have a
different background than the intraline difference, looking sloppy.
To solve this, the pseudo element was positioned using absolute,
allowing the pseudo element to consume no horizontal space and and
the intraline background to extend across the entire tab.
III:When performance tuning, it was discovered that the
absolute-positioned tab indicators were positioned incorrectly when
GPU acceleration was hinted for the diff, so the containing tab
elements were made relative.
IV: Continuing performance tuning, the tab indicators seemed to slow
scrolling on very large diffs with tabs. It was mistakenly assumed
(by me) that this was related to the pseudo-elements when it was
actually caused by the thousands of positioning contexts they
created using relative and absolute.
Instead they were modified to use strike-through instead of a pseudo
element, which was more-performant, but less-usable (it looked bad).
With this change, we roll-back the clock a little and solve a core
problem: namely that tab indicators were not annotated inside the
intraline differences. Fixing that, positioning tricks are no-longer
needed to make the background look right.
To do this, we decouple the tab elements (which control tab width) from
the tab indicators (which optionally make tabs visible). This is done
using an annotation layer that inserts tab indicator elements wherever
a tab character is used in the source content, and it does so after
intraline differences have been applied.
Bug: Issue 4441
Change-Id: I4fea2a3a20a7039bfeb746bd1e1c1004e43c4801
2016-08-25 11:31:42 -07:00
|
|
|
return {
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2016-11-17 12:03:51 -08:00
|
|
|
_createTrailingWhitespaceLayer: function() {
|
|
|
|
var show = function() {
|
|
|
|
return this._showTrailingWhitespace;
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
return {
|
|
|
|
annotate: function(el, line) {
|
|
|
|
if (!show()) { return; }
|
|
|
|
|
|
|
|
var match = line.text.match(TRAILING_WHITESPACE_PATTERN);
|
|
|
|
if (match) {
|
|
|
|
// Normalize string positions in case there is unicode before or
|
|
|
|
// within the match.
|
|
|
|
var index = GrAnnotation.getStringLength(
|
|
|
|
line.text.substr(0, match.index));
|
|
|
|
var length = GrAnnotation.getStringLength(match[0]);
|
|
|
|
GrAnnotation.annotateElement(el, index, length,
|
|
|
|
'style-scope gr-diff trailing-whitespace');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2016-08-08 16:35:01 -07:00
|
|
|
/**
|
|
|
|
* In pages with large diffs, creating the first comment thread can be
|
|
|
|
* slow because nested Polymer elements (particularly
|
|
|
|
* iron-autogrow-textarea) add style elements to the document head,
|
|
|
|
* which, in turn, triggers a reflow on the page. Create a hidden
|
|
|
|
* thread, attach it to the page, and remove it so the stylesheet will
|
|
|
|
* already exist and the user's comment will be quick to load.
|
|
|
|
* @see https://gerrit-review.googlesource.com/c/82213/
|
|
|
|
*/
|
|
|
|
_preRenderThread: function() {
|
|
|
|
var thread = document.createElement('gr-diff-comment-thread');
|
|
|
|
thread.setAttribute('hidden', true);
|
|
|
|
thread.addDraft();
|
|
|
|
var parent = Polymer.dom(this.root);
|
|
|
|
parent.appendChild(thread);
|
|
|
|
Polymer.dom.flush();
|
|
|
|
parent.removeChild(thread);
|
|
|
|
},
|
2016-10-10 17:05:32 -07:00
|
|
|
|
|
|
|
/**
|
2016-10-13 17:54:38 -07:00
|
|
|
* @return {Boolean} whether any of the lines in _groups are longer
|
2016-10-10 17:05:32 -07:00
|
|
|
* than SYNTAX_MAX_LINE_LENGTH.
|
|
|
|
*/
|
|
|
|
_anyLineTooLong: function() {
|
|
|
|
return this._groups.reduce(function(acc, group) {
|
|
|
|
return acc || group.lines.reduce(function(acc, line) {
|
|
|
|
return acc || line.text.length >= SYNTAX_MAX_LINE_LENGTH;
|
|
|
|
}, false);
|
|
|
|
}, false);
|
|
|
|
},
|
2016-06-01 11:41:47 -07:00
|
|
|
});
|
|
|
|
})();
|
|
|
|
</script>
|
|
|
|
</dom-module>
|