Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @implements {Sources.SourcesView.EditorAction} | 5 * @implements {Sources.SourcesView.EditorAction} |
| 6 * @unrestricted | 6 * @unrestricted |
| 7 */ | 7 */ |
| 8 Sources.InplaceFormatterEditorAction = class { | 8 Sources.InplaceFormatterEditorAction = class { |
| 9 /** | 9 /** |
| 10 * @param {!Common.Event} event | 10 * @param {!Common.Event} event |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 function innerCallback(formattedContent, formatterMapping) { | 92 function innerCallback(formattedContent, formatterMapping) { |
| 93 if (uiSourceCode.workingCopy() === formattedContent) | 93 if (uiSourceCode.workingCopy() === formattedContent) |
| 94 return; | 94 return; |
| 95 var sourceFrame = this._sourcesView.viewForFile(uiSourceCode); | 95 var sourceFrame = this._sourcesView.viewForFile(uiSourceCode); |
| 96 var start = [0, 0]; | 96 var start = [0, 0]; |
| 97 if (sourceFrame) { | 97 if (sourceFrame) { |
| 98 var selection = sourceFrame.selection(); | 98 var selection = sourceFrame.selection(); |
| 99 start = formatterMapping.originalToFormatted(selection.startLine, select ion.startColumn); | 99 start = formatterMapping.originalToFormatted(selection.startLine, select ion.startColumn); |
| 100 } | 100 } |
| 101 uiSourceCode.setWorkingCopy(formattedContent); | 101 uiSourceCode.setWorkingCopy(formattedContent); |
| 102 this._formatDecorations(uiSourceCode, formatterMapping); | |
| 103 | |
| 102 this._sourcesView.showSourceLocation(uiSourceCode, start[0], start[1]); | 104 this._sourcesView.showSourceLocation(uiSourceCode, start[0], start[1]); |
| 103 } | 105 } |
| 104 } | 106 } |
| 107 | |
| 108 /** | |
| 109 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 110 * @param {!Sources.FormatterSourceMapping} sourceMapping | |
| 111 */ | |
| 112 _formatDecorations(uiSourceCode, sourceMapping) { | |
| 113 if (!uiSourceCode.allDecorations()) | |
| 114 return; | |
| 115 | |
| 116 /** @type {!Array<!Workspace.UISourceCode.LineMarker>} */ | |
| 117 var decorationList = []; | |
| 118 | |
| 119 uiSourceCode.allDecorations().forEach(decoration => decorationList.push(deco ration)); | |
|
lushnikov
2016/11/17 17:55:52
let's do the following:
_formatDecorations(uiSour
| |
| 120 | |
| 121 uiSourceCode.removeAllDecorations(); | |
| 122 | |
| 123 for (var decoration of decorationList) { | |
| 124 var formattedStartLine = sourceMapping.originalToFormatted(decoration.rang e().startLine, | |
| 125 decoration.r ange().startColumn)[0]; | |
| 126 var formattedStartColumn = sourceMapping.originalToFormatted(decoration.ra nge().startLine, | |
| 127 decoration.r ange().startColumn)[1]; | |
| 128 | |
| 129 var formattedEndLine = sourceMapping.originalToFormatted(decoration.range( ).endLine, | |
| 130 decoration.range ().endColumn)[0]; | |
| 131 var formattedEndColumn = sourceMapping.originalToFormatted(decoration.rang e().endLine, | |
| 132 decoration.ran ge().endColumn)[1]; | |
| 133 | |
| 134 uiSourceCode.addDecoration(new Common.TextRange(formattedStartLine, format tedStartColumn, | |
| 135 formattedEndLine, formattedEnd Column), | |
| 136 /** @type {string} */ (decoration.type()), | |
| 137 decoration.data()); | |
| 138 } | |
| 139 } | |
| 105 }; | 140 }; |
| OLD | NEW |