Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 Changes.ChangesView = class extends UI.VBox { | 5 Changes.ChangesView = class extends UI.VBox { |
| 6 constructor() { | 6 constructor() { |
| 7 super(true); | 7 super(true); |
| 8 this.registerRequiredCSS('changes/changesView.css'); | 8 this.registerRequiredCSS('changes/changesView.css'); |
| 9 var splitWidget = new UI.SplitWidget(true /* vertical */, false /* sidebar o n left */); | 9 var splitWidget = new UI.SplitWidget(true /* vertical */, false /* sidebar o n left */); |
| 10 var mainWidget = new UI.Widget(); | 10 var mainWidget = new UI.Widget(); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 this._editor.hideWidget(); | 125 this._editor.hideWidget(); |
| 126 this._emptyWidget.showWidget(); | 126 this._emptyWidget.showWidget(); |
| 127 return; | 127 return; |
| 128 } | 128 } |
| 129 | 129 |
| 130 var insertions = 0; | 130 var insertions = 0; |
| 131 var deletions = 0; | 131 var deletions = 0; |
| 132 var currentLineNumber = 0; | 132 var currentLineNumber = 0; |
| 133 var baselineLineNumber = 0; | 133 var baselineLineNumber = 0; |
| 134 var paddingLines = 3; | 134 var paddingLines = 3; |
| 135 var originalLines = []; | |
| 136 var currentLines = []; | |
| 135 | 137 |
| 136 for (var i = 0; i < diff.length; ++i) { | 138 for (var i = 0; i < diff.length; ++i) { |
| 137 var token = diff[i]; | 139 var token = diff[i]; |
| 138 switch (token[0]) { | 140 switch (token[0]) { |
| 139 case Diff.Diff.Operation.Equal: | 141 case Diff.Diff.Operation.Equal: |
| 140 this._diffRows.pushAll(createEqualRows(token[1], i === 0, i === diff.l ength - 1)); | 142 this._diffRows.pushAll(createEqualRows(token[1], i === 0, i === diff.l ength - 1)); |
| 143 originalLines.pushAll(token[1]); | |
| 144 currentLines.pushAll(token[1]); | |
| 141 break; | 145 break; |
| 142 case Diff.Diff.Operation.Insert: | 146 case Diff.Diff.Operation.Insert: |
| 143 for (var line of token[1]) | 147 for (var line of token[1]) |
| 144 this._diffRows.push(createRow(line, Changes.ChangesView.RowType.Addi tion)); | 148 this._diffRows.push(createRow(line, Changes.ChangesView.RowType.Addi tion)); |
| 145 insertions += token[1].length; | 149 insertions += token[1].length; |
| 150 currentLines.pushAll(token[1]); | |
| 146 break; | 151 break; |
| 147 case Diff.Diff.Operation.Delete: | 152 case Diff.Diff.Operation.Delete: |
| 148 deletions += token[1].length; | 153 deletions += token[1].length; |
| 154 originalLines.pushAll(token[1]); | |
| 149 if (diff[i + 1] && diff[i + 1][0] === Diff.Diff.Operation.Insert) { | 155 if (diff[i + 1] && diff[i + 1][0] === Diff.Diff.Operation.Insert) { |
| 150 i++; | 156 i++; |
| 151 this._diffRows.pushAll(createModifyRows(token[1].join('\n'), diff[i] [1].join('\n'))); | 157 this._diffRows.pushAll(createModifyRows(token[1].join('\n'), diff[i] [1].join('\n'))); |
| 152 insertions += diff[i][1].length; | 158 insertions += diff[i][1].length; |
| 159 currentLines.pushAll(diff[i][1]); | |
| 153 } else { | 160 } else { |
| 154 for (var line of token[1]) | 161 for (var line of token[1]) |
| 155 this._diffRows.push(createRow(line, Changes.ChangesView.RowType.De letion)); | 162 this._diffRows.push(createRow(line, Changes.ChangesView.RowType.De letion)); |
| 156 } | 163 } |
| 157 break; | 164 break; |
| 158 } | 165 } |
| 159 } | 166 } |
| 160 | 167 |
| 161 this._maxLineDigits = Math.ceil(Math.log10(Math.max(currentLineNumber, basel ineLineNumber))); | 168 this._maxLineDigits = Math.ceil(Math.log10(Math.max(currentLineNumber, basel ineLineNumber))); |
| 162 | 169 |
| 163 this._diffStats.setText(Common.UIString( | 170 this._diffStats.setText(Common.UIString( |
| 164 '%d insertion%s (+), %d deletion%s (-)', insertions, insertions !== 1 ? 's' : '', deletions, | 171 '%d insertion%s (+), %d deletion%s (-)', insertions, insertions !== 1 ? 's' : '', deletions, |
| 165 deletions !== 1 ? 's' : '')); | 172 deletions !== 1 ? 's' : '')); |
| 166 this._toolbar.setEnabled(true); | 173 this._toolbar.setEnabled(true); |
| 167 this._emptyWidget.hideWidget(); | 174 this._emptyWidget.hideWidget(); |
| 168 | 175 |
| 169 this._editor.operation(() => { | 176 this._editor.operation(() => { |
| 170 this._editor.showWidget(); | 177 this._editor.showWidget(); |
| 171 this._editor.setHighlightMode({name: 'devtools-diff', rows: this._diffRows }); | 178 this._editor.setHighlightMode({ |
| 179 name: 'devtools-diff', | |
| 180 rows: this._diffRows, | |
|
lushnikov
2017/04/03 23:11:19
diffRows
| |
| 181 mimeType: Bindings.NetworkProject.uiSourceCodeMimeType( | |
| 182 /** @type {!Workspace.UISourceCode} */ (this._selectedUISourceCode)) , | |
| 183 baselineLines: originalLines, | |
| 184 currentLines: currentLines | |
| 185 }); | |
| 172 this._editor.setText(this._diffRows.map(row => row.content.map(t => t.text ).join('')).join('\n')); | 186 this._editor.setText(this._diffRows.map(row => row.content.map(t => t.text ).join('')).join('\n')); |
| 173 this._editor.setLineNumberFormatter(this._lineFormatter.bind(this)); | 187 this._editor.setLineNumberFormatter(this._lineFormatter.bind(this)); |
| 174 }); | 188 }); |
| 175 | 189 |
| 176 /** | 190 /** |
| 177 * @param {!Array<string>} lines | 191 * @param {!Array<string>} lines |
| 178 * @param {boolean} atStart | 192 * @param {boolean} atStart |
| 179 * @param {boolean} atEnd | 193 * @param {boolean} atEnd |
| 180 * @return {!Array<!Changes.ChangesView.Row>}} | 194 * @return {!Array<!Changes.ChangesView.Row>}} |
| 181 */ | 195 */ |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 */ | 301 */ |
| 288 Changes.ChangesView.Row; | 302 Changes.ChangesView.Row; |
| 289 | 303 |
| 290 /** @enum {string} */ | 304 /** @enum {string} */ |
| 291 Changes.ChangesView.RowType = { | 305 Changes.ChangesView.RowType = { |
| 292 Deletion: 'deletion', | 306 Deletion: 'deletion', |
| 293 Addition: 'addition', | 307 Addition: 'addition', |
| 294 Equal: 'equal', | 308 Equal: 'equal', |
| 295 Spacer: 'spacer' | 309 Spacer: 'spacer' |
| 296 }; | 310 }; |
| OLD | NEW |