Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/workspace/UISourceCode.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/workspace/UISourceCode.js b/third_party/WebKit/Source/devtools/front_end/workspace/UISourceCode.js |
| index fff83b1dbd5d7b5996a6295f93f7bbae49450319..46b7fe1e91912cd01393614d5824184864974ee9 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/workspace/UISourceCode.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/workspace/UISourceCode.js |
| @@ -447,11 +447,12 @@ Workspace.UISourceCode = class extends Common.Object { |
| /** |
| * @param {string} newWorkingCopy |
| + * @param {!Workspace.UISourceCode.SourceMapping=} sourceMapping |
| */ |
| - setWorkingCopy(newWorkingCopy) { |
| + setWorkingCopy(newWorkingCopy, sourceMapping) { |
| this._workingCopy = newWorkingCopy; |
| delete this._workingCopyGetter; |
| - this.dispatchEventToListeners(Workspace.UISourceCode.Events.WorkingCopyChanged); |
| + this.dispatchEventToListeners(Workspace.UISourceCode.Events.WorkingCopyChanged, {sourceMapping: sourceMapping}); |
| this._project.workspace().dispatchEventToListeners( |
| Workspace.Workspace.Events.WorkingCopyChanged, {uiSourceCode: this}); |
| } |
| @@ -949,3 +950,97 @@ Workspace.UISourceCodeMetadata = class { |
| this.contentSize = contentSize; |
| } |
| }; |
| + |
| +/** |
| + * @typedef {{original: !Array.<number>, formatted: !Array.<number>}} |
| + */ |
| +Workspace.FormatterMappingPayload; |
|
lushnikov
2016/11/14 22:38:52
This doesn't belong here as well
|
| + |
| +Workspace.Formatter = function() {}; |
|
lushnikov
2016/11/14 22:38:51
There should be no world "Formatter" in UISourceCo
|
| + |
| +/** |
| + * @param {!Array.<number>} lineEndings |
| + * @param {number} lineNumber |
| + * @param {number} columnNumber |
| + * @return {number} |
| + */ |
| +Workspace.Formatter.locationToPosition = function(lineEndings, lineNumber, columnNumber) { |
|
lushnikov
2016/11/14 22:38:51
this should not be here as well
|
| + var position = lineNumber ? lineEndings[lineNumber - 1] + 1 : 0; |
| + return position + columnNumber; |
| +}; |
| + |
| +/** |
| + * @param {!Array.<number>} lineEndings |
| + * @param {number} position |
| + * @return {!Array.<number>} |
| + */ |
| +Workspace.Formatter.positionToLocation = function(lineEndings, position) { |
|
lushnikov
2016/11/14 22:38:52
you don't use these methods
|
| + var lineNumber = lineEndings.upperBound(position - 1); |
| + if (!lineNumber) |
| + var columnNumber = position; |
| + else |
| + var columnNumber = position - lineEndings[lineNumber - 1] - 1; |
| + return [lineNumber, columnNumber]; |
| +}; |
| + |
| +Workspace.UISourceCode.SourceMapping = class { |
| + /** |
| + * @param {!Array.<number>} originalLineEndings |
| + * @param {!Array.<number>} formattedLineEndings |
| + * @param {!Workspace.FormatterMappingPayload} mapping |
| + */ |
| + constructor(originalLineEndings, formattedLineEndings, mapping) { |
|
lushnikov
2016/11/14 22:38:52
@param {!Array<{originalOffset: number, newOffset:
|
| + this._originalLineEndings = originalLineEndings; |
| + this._formattedLineEndings = formattedLineEndings; |
| + this._mapping = mapping; |
| + } |
| + |
| + /** |
| + * @param {number} lineNumber |
| + * @param {number=} columnNumber |
| + * @return {!Array.<number>} |
| + */ |
| + originalToFormatted(lineNumber, columnNumber) { |
|
lushnikov
2016/11/14 22:38:52
drop word "formatted" everywhere!
|
| + var originalPosition = |
| + Sources.Formatter.locationToPosition(this._originalLineEndings, lineNumber, columnNumber || 0); |
|
lushnikov
2016/11/14 22:38:52
how does it compile? It shouldn't!! You cannot use
|
| + var formattedPosition = |
| + this._convertPosition(this._mapping.original, this._mapping.formatted, originalPosition || 0); |
| + return Sources.Formatter.positionToLocation(this._formattedLineEndings, formattedPosition); |
| + } |
| + |
| + /** |
| + * @param {number} lineNumber |
| + * @param {number=} columnNumber |
| + * @return {!Array.<number>} |
| + */ |
| + formattedToOriginal(lineNumber, columnNumber) { |
| + var formattedPosition = |
| + Sources.Formatter.locationToPosition(this._formattedLineEndings, lineNumber, columnNumber || 0); |
| + var originalPosition = this._convertPosition(this._mapping.formatted, this._mapping.original, formattedPosition); |
| + return Sources.Formatter.positionToLocation(this._originalLineEndings, originalPosition || 0); |
| + } |
| + |
| + /** |
| + * @param {!Array.<number>} positions1 |
| + * @param {!Array.<number>} positions2 |
| + * @param {number} position |
| + * @return {number} |
| + */ |
| + _convertPosition(positions1, positions2, position) { |
| + var index = positions1.upperBound(position) - 1; |
|
lushnikov
2016/11/14 22:38:52
you probably can remove the majority of this code;
|
| + var convertedPosition = positions2[index] + position - positions1[index]; |
| + if (index < positions2.length - 1 && convertedPosition > positions2[index + 1]) |
| + convertedPosition = positions2[index + 1]; |
| + return convertedPosition; |
| + } |
| + |
| + /** |
| + * @param {!Array.<number>} originalLineEndings |
| + * @param {!Array.<number>} formattedLineEndings |
| + * @param {!Workspace.FormatterMappingPayload} mapping |
| + */ |
| + static create(originalLineEndings, formattedLineEndings, mapping) { |
| + return new Workspace.UISourceCode.SourceMapping(originalLineEndings, formattedLineEndings, mapping); |
| + } |
| +}; |
| + |