
The gr-diff element was already capable of rendering diffs in either side-by-side or unified style, but was configured by default to use side-by-side. The GWT diff UI included an icon button toggle to switch between these two styles above and to the right of the diff near the "Diff View Preferences" button. This change introduces a selector in the PolyGerrit UI to allow similar switching behavior. Previously, the diff mode was encoded as a private property of the gr-diff element. Now that the switcher is introduced at the same level as the "Diff View Preferences" button (one level up from the gr-diff element) it is changed to be a public property of the element so that it can be changed through the parent view (in this case the gr-diff-view element). A dropdown is added to the gr-diff-view based in style on the gr-patch-range-select element (which plays a similar role). This dropdown has options for either of the two diff modes and controls the diff display through a property on the view. The view gets a new, computed property called _diffMode which encodes which diff state should be displayed based on the changeViewState and the user's preferences. The user's choice of diff view is persisted across diff views, but is reverted to the preference when the change view is visited. A test is added to the gr-diff-view element. Bug: Issue 3909 Change-Id: I00d93500f8d210394acc9c8f3398c9406ae74276
149 lines
4.6 KiB
HTML
149 lines
4.6 KiB
HTML
<!--
|
|
Copyright (C) 2015 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">
|
|
<link rel="import" href="../../shared/gr-button/gr-button.html">
|
|
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
|
|
<link rel="import" href="../gr-diff-comment-thread/gr-diff-comment-thread.html">
|
|
|
|
<dom-module id="gr-diff">
|
|
<template>
|
|
<style>
|
|
:host {
|
|
--light-remove-highlight-color: #fee;
|
|
--dark-remove-highlight-color: #ffd4d4;
|
|
--light-add-highlight-color: #efe;
|
|
--dark-add-highlight-color: #d4ffd4;
|
|
}
|
|
.diffContainer {
|
|
border-bottom: 1px solid #eee;
|
|
border-top: 1px solid #eee;
|
|
display: flex;
|
|
font: 12px var(--monospace-font-family);
|
|
overflow-x: auto;
|
|
will-change: transform;
|
|
}
|
|
table {
|
|
border-collapse: collapse;
|
|
border-right: 1px solid #ddd;
|
|
}
|
|
.section {
|
|
background-color: #eee;
|
|
}
|
|
.blank,
|
|
.content {
|
|
background-color: #fff;
|
|
}
|
|
.lineNum,
|
|
.content {
|
|
vertical-align: top;
|
|
white-space: pre;
|
|
}
|
|
.contextLineNum:before,
|
|
.lineNum:before {
|
|
display: inline-block;
|
|
color: #666;
|
|
content: attr(data-value);
|
|
padding: 0 .75em;
|
|
text-align: right;
|
|
width: 100%;
|
|
}
|
|
.canComment .lineNum[data-value] {
|
|
cursor: pointer;
|
|
}
|
|
.canComment .lineNum[data-value]:before {
|
|
text-decoration: underline;
|
|
}
|
|
.canComment .lineNum[data-value]:hover:before {
|
|
background-color: #ccc;
|
|
}
|
|
.canComment .lineNum[data-value="FILE"]:before {
|
|
content: 'File';
|
|
}
|
|
.content {
|
|
overflow: hidden;
|
|
/* Set max and min width since setting width on table cells still
|
|
allows them to shrink. */
|
|
max-width: var(--content-width, 80ch);
|
|
min-width: var(--content-width, 80ch);
|
|
}
|
|
.content.left {
|
|
-webkit-user-select: var(--left-user-select, text);
|
|
-moz-user-select: var(--left-user-select, text);
|
|
-ms-user-select: var(--left-user-select, text);
|
|
user-select: var(--left-user-select, text);
|
|
}
|
|
.content.right {
|
|
-webkit-user-select: var(--right-user-select, text);
|
|
-moz-user-select: var(--right-user-select, text);
|
|
-ms-user-select: var(--right-user-select, text);
|
|
user-select: var(--right-user-select, text);
|
|
}
|
|
.content.add hl,
|
|
.content.add.darkHighlight {
|
|
background-color: var(--dark-add-highlight-color);
|
|
}
|
|
.content.add.lightHighlight {
|
|
background-color: var(--light-add-highlight-color);
|
|
}
|
|
.content.remove hl,
|
|
.content.remove.darkHighlight {
|
|
background-color: var(--dark-remove-highlight-color);
|
|
}
|
|
.content.remove.lightHighlight {
|
|
background-color: var(--light-remove-highlight-color);
|
|
}
|
|
.contextControl {
|
|
color: #849;
|
|
background-color: #fef;
|
|
}
|
|
.contextControl gr-button {
|
|
display: block;
|
|
font-family: var(--monospace-font-family);
|
|
text-decoration: none;
|
|
}
|
|
.contextControl td:not(.lineNum) {
|
|
text-align: center;
|
|
}
|
|
.br:after {
|
|
/* Line feed */
|
|
content: '\A';
|
|
}
|
|
.tab {
|
|
display: inline-block;
|
|
}
|
|
.tab.withIndicator:before {
|
|
color: #C62828;
|
|
/* >> character */
|
|
content: '\00BB';
|
|
}
|
|
</style>
|
|
<div class$="[[_computeContainerClass(_loggedIn, viewMode)]]"
|
|
on-tap="_handleTap"
|
|
on-mousedown="_handleMouseDown"
|
|
on-copy="_handleCopy">
|
|
<table id="diffTable"></table>
|
|
</div>
|
|
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
|
</template>
|
|
<script src="gr-diff-line.js"></script>
|
|
<script src="gr-diff-group.js"></script>
|
|
<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.js"></script>
|
|
</dom-module>
|