Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 this.dispatchEventToListeners(Workspace.UISourceCode.Events.WorkingCopyChang ed); | 440 this.dispatchEventToListeners(Workspace.UISourceCode.Events.WorkingCopyChang ed); |
| 441 } | 441 } |
| 442 | 442 |
| 443 _innerResetWorkingCopy() { | 443 _innerResetWorkingCopy() { |
| 444 delete this._workingCopy; | 444 delete this._workingCopy; |
| 445 delete this._workingCopyGetter; | 445 delete this._workingCopyGetter; |
| 446 } | 446 } |
| 447 | 447 |
| 448 /** | 448 /** |
| 449 * @param {string} newWorkingCopy | 449 * @param {string} newWorkingCopy |
| 450 * @param {!Workspace.UISourceCode.SourceMapping=} sourceMapping | |
| 450 */ | 451 */ |
| 451 setWorkingCopy(newWorkingCopy) { | 452 setWorkingCopy(newWorkingCopy, sourceMapping) { |
| 452 this._workingCopy = newWorkingCopy; | 453 this._workingCopy = newWorkingCopy; |
| 453 delete this._workingCopyGetter; | 454 delete this._workingCopyGetter; |
| 454 this.dispatchEventToListeners(Workspace.UISourceCode.Events.WorkingCopyChang ed); | 455 this.dispatchEventToListeners(Workspace.UISourceCode.Events.WorkingCopyChang ed, {sourceMapping: sourceMapping}); |
| 455 this._project.workspace().dispatchEventToListeners( | 456 this._project.workspace().dispatchEventToListeners( |
| 456 Workspace.Workspace.Events.WorkingCopyChanged, {uiSourceCode: this}); | 457 Workspace.Workspace.Events.WorkingCopyChanged, {uiSourceCode: this}); |
| 457 } | 458 } |
| 458 | 459 |
| 459 setWorkingCopyGetter(workingCopyGetter) { | 460 setWorkingCopyGetter(workingCopyGetter) { |
| 460 this._workingCopyGetter = workingCopyGetter; | 461 this._workingCopyGetter = workingCopyGetter; |
| 461 this.dispatchEventToListeners(Workspace.UISourceCode.Events.WorkingCopyChang ed); | 462 this.dispatchEventToListeners(Workspace.UISourceCode.Events.WorkingCopyChang ed); |
| 462 this._project.workspace().dispatchEventToListeners( | 463 this._project.workspace().dispatchEventToListeners( |
| 463 Workspace.Workspace.Events.WorkingCopyChanged, {uiSourceCode: this}); | 464 Workspace.Workspace.Events.WorkingCopyChanged, {uiSourceCode: this}); |
| 464 } | 465 } |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 942 Workspace.UISourceCodeMetadata = class { | 943 Workspace.UISourceCodeMetadata = class { |
| 943 /** | 944 /** |
| 944 * @param {?Date} modificationTime | 945 * @param {?Date} modificationTime |
| 945 * @param {?number} contentSize | 946 * @param {?number} contentSize |
| 946 */ | 947 */ |
| 947 constructor(modificationTime, contentSize) { | 948 constructor(modificationTime, contentSize) { |
| 948 this.modificationTime = modificationTime; | 949 this.modificationTime = modificationTime; |
| 949 this.contentSize = contentSize; | 950 this.contentSize = contentSize; |
| 950 } | 951 } |
| 951 }; | 952 }; |
| 953 | |
| 954 /** | |
| 955 * @typedef {{original: !Array.<number>, formatted: !Array.<number>}} | |
| 956 */ | |
| 957 Workspace.FormatterMappingPayload; | |
|
lushnikov
2016/11/14 22:38:52
This doesn't belong here as well
| |
| 958 | |
| 959 Workspace.Formatter = function() {}; | |
|
lushnikov
2016/11/14 22:38:51
There should be no world "Formatter" in UISourceCo
| |
| 960 | |
| 961 /** | |
| 962 * @param {!Array.<number>} lineEndings | |
| 963 * @param {number} lineNumber | |
| 964 * @param {number} columnNumber | |
| 965 * @return {number} | |
| 966 */ | |
| 967 Workspace.Formatter.locationToPosition = function(lineEndings, lineNumber, colum nNumber) { | |
|
lushnikov
2016/11/14 22:38:51
this should not be here as well
| |
| 968 var position = lineNumber ? lineEndings[lineNumber - 1] + 1 : 0; | |
| 969 return position + columnNumber; | |
| 970 }; | |
| 971 | |
| 972 /** | |
| 973 * @param {!Array.<number>} lineEndings | |
| 974 * @param {number} position | |
| 975 * @return {!Array.<number>} | |
| 976 */ | |
| 977 Workspace.Formatter.positionToLocation = function(lineEndings, position) { | |
|
lushnikov
2016/11/14 22:38:52
you don't use these methods
| |
| 978 var lineNumber = lineEndings.upperBound(position - 1); | |
| 979 if (!lineNumber) | |
| 980 var columnNumber = position; | |
| 981 else | |
| 982 var columnNumber = position - lineEndings[lineNumber - 1] - 1; | |
| 983 return [lineNumber, columnNumber]; | |
| 984 }; | |
| 985 | |
| 986 Workspace.UISourceCode.SourceMapping = class { | |
| 987 /** | |
| 988 * @param {!Array.<number>} originalLineEndings | |
| 989 * @param {!Array.<number>} formattedLineEndings | |
| 990 * @param {!Workspace.FormatterMappingPayload} mapping | |
| 991 */ | |
| 992 constructor(originalLineEndings, formattedLineEndings, mapping) { | |
|
lushnikov
2016/11/14 22:38:52
@param {!Array<{originalOffset: number, newOffset:
| |
| 993 this._originalLineEndings = originalLineEndings; | |
| 994 this._formattedLineEndings = formattedLineEndings; | |
| 995 this._mapping = mapping; | |
| 996 } | |
| 997 | |
| 998 /** | |
| 999 * @param {number} lineNumber | |
| 1000 * @param {number=} columnNumber | |
| 1001 * @return {!Array.<number>} | |
| 1002 */ | |
| 1003 originalToFormatted(lineNumber, columnNumber) { | |
|
lushnikov
2016/11/14 22:38:52
drop word "formatted" everywhere!
| |
| 1004 var originalPosition = | |
| 1005 Sources.Formatter.locationToPosition(this._originalLineEndings, lineNumb er, columnNumber || 0); | |
|
lushnikov
2016/11/14 22:38:52
how does it compile? It shouldn't!! You cannot use
| |
| 1006 var formattedPosition = | |
| 1007 this._convertPosition(this._mapping.original, this._mapping.formatted, o riginalPosition || 0); | |
| 1008 return Sources.Formatter.positionToLocation(this._formattedLineEndings, form attedPosition); | |
| 1009 } | |
| 1010 | |
| 1011 /** | |
| 1012 * @param {number} lineNumber | |
| 1013 * @param {number=} columnNumber | |
| 1014 * @return {!Array.<number>} | |
| 1015 */ | |
| 1016 formattedToOriginal(lineNumber, columnNumber) { | |
| 1017 var formattedPosition = | |
| 1018 Sources.Formatter.locationToPosition(this._formattedLineEndings, lineNum ber, columnNumber || 0); | |
| 1019 var originalPosition = this._convertPosition(this._mapping.formatted, this._ mapping.original, formattedPosition); | |
| 1020 return Sources.Formatter.positionToLocation(this._originalLineEndings, origi nalPosition || 0); | |
| 1021 } | |
| 1022 | |
| 1023 /** | |
| 1024 * @param {!Array.<number>} positions1 | |
| 1025 * @param {!Array.<number>} positions2 | |
| 1026 * @param {number} position | |
| 1027 * @return {number} | |
| 1028 */ | |
| 1029 _convertPosition(positions1, positions2, position) { | |
| 1030 var index = positions1.upperBound(position) - 1; | |
|
lushnikov
2016/11/14 22:38:52
you probably can remove the majority of this code;
| |
| 1031 var convertedPosition = positions2[index] + position - positions1[index]; | |
| 1032 if (index < positions2.length - 1 && convertedPosition > positions2[index + 1]) | |
| 1033 convertedPosition = positions2[index + 1]; | |
| 1034 return convertedPosition; | |
| 1035 } | |
| 1036 | |
| 1037 /** | |
| 1038 * @param {!Array.<number>} originalLineEndings | |
| 1039 * @param {!Array.<number>} formattedLineEndings | |
| 1040 * @param {!Workspace.FormatterMappingPayload} mapping | |
| 1041 */ | |
| 1042 static create(originalLineEndings, formattedLineEndings, mapping) { | |
| 1043 return new Workspace.UISourceCode.SourceMapping(originalLineEndings, formatt edLineEndings, mapping); | |
| 1044 } | |
| 1045 }; | |
| 1046 | |
| OLD | NEW |