OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 23 matching lines...) Expand all Loading... |
34 * @param {number} startColumn | 34 * @param {number} startColumn |
35 * @param {number} endLine | 35 * @param {number} endLine |
36 * @param {number} endColumn | 36 * @param {number} endColumn |
37 */ | 37 */ |
38 WebInspector.TextRange = function(startLine, startColumn, endLine, endColumn) | 38 WebInspector.TextRange = function(startLine, startColumn, endLine, endColumn) |
39 { | 39 { |
40 this.startLine = startLine; | 40 this.startLine = startLine; |
41 this.startColumn = startColumn; | 41 this.startColumn = startColumn; |
42 this.endLine = endLine; | 42 this.endLine = endLine; |
43 this.endColumn = endColumn; | 43 this.endColumn = endColumn; |
44 } | 44 }; |
45 | 45 |
46 /** | 46 /** |
47 * @param {number} line | 47 * @param {number} line |
48 * @param {number} column | 48 * @param {number} column |
49 * @return {!WebInspector.TextRange} | 49 * @return {!WebInspector.TextRange} |
50 */ | 50 */ |
51 WebInspector.TextRange.createFromLocation = function(line, column) | 51 WebInspector.TextRange.createFromLocation = function(line, column) |
52 { | 52 { |
53 return new WebInspector.TextRange(line, column, line, column); | 53 return new WebInspector.TextRange(line, column, line, column); |
54 } | 54 }; |
55 | 55 |
56 /** | 56 /** |
57 * @param {!Object} serializedTextRange | 57 * @param {!Object} serializedTextRange |
58 * @return {!WebInspector.TextRange} | 58 * @return {!WebInspector.TextRange} |
59 */ | 59 */ |
60 WebInspector.TextRange.fromObject = function(serializedTextRange) | 60 WebInspector.TextRange.fromObject = function(serializedTextRange) |
61 { | 61 { |
62 return new WebInspector.TextRange(serializedTextRange.startLine, serializedT
extRange.startColumn, serializedTextRange.endLine, serializedTextRange.endColumn
); | 62 return new WebInspector.TextRange(serializedTextRange.startLine, serializedT
extRange.startColumn, serializedTextRange.endLine, serializedTextRange.endColumn
); |
63 } | 63 }; |
64 | 64 |
65 /** | 65 /** |
66 * @param {!WebInspector.TextRange} range1 | 66 * @param {!WebInspector.TextRange} range1 |
67 * @param {!WebInspector.TextRange} range2 | 67 * @param {!WebInspector.TextRange} range2 |
68 * @return {number} | 68 * @return {number} |
69 */ | 69 */ |
70 WebInspector.TextRange.comparator = function(range1, range2) | 70 WebInspector.TextRange.comparator = function(range1, range2) |
71 { | 71 { |
72 return range1.compareTo(range2); | 72 return range1.compareTo(range2); |
73 } | 73 }; |
74 | 74 |
75 WebInspector.TextRange.prototype = { | 75 WebInspector.TextRange.prototype = { |
76 /** | 76 /** |
77 * @return {boolean} | 77 * @return {boolean} |
78 */ | 78 */ |
79 isEmpty: function() | 79 isEmpty: function() |
80 { | 80 { |
81 return this.startLine === this.endLine && this.startColumn === this.endC
olumn; | 81 return this.startLine === this.endLine && this.startColumn === this.endC
olumn; |
82 }, | 82 }, |
83 | 83 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 containsLocation: function(lineNumber, columnNumber) | 269 containsLocation: function(lineNumber, columnNumber) |
270 { | 270 { |
271 if (this.startLine === this.endLine) | 271 if (this.startLine === this.endLine) |
272 return this.startLine === lineNumber && this.startColumn <= columnNu
mber && columnNumber <= this.endColumn; | 272 return this.startLine === lineNumber && this.startColumn <= columnNu
mber && columnNumber <= this.endColumn; |
273 if (this.startLine === lineNumber) | 273 if (this.startLine === lineNumber) |
274 return this.startColumn <= columnNumber; | 274 return this.startColumn <= columnNumber; |
275 if (this.endLine === lineNumber) | 275 if (this.endLine === lineNumber) |
276 return columnNumber <= this.endColumn; | 276 return columnNumber <= this.endColumn; |
277 return this.startLine < lineNumber && lineNumber < this.endLine; | 277 return this.startLine < lineNumber && lineNumber < this.endLine; |
278 } | 278 } |
279 } | 279 }; |
280 | 280 |
281 /** | 281 /** |
282 * @param {!WebInspector.TextRange} oldRange | 282 * @param {!WebInspector.TextRange} oldRange |
283 * @param {string} newText | 283 * @param {string} newText |
284 * @return {!WebInspector.TextRange} | 284 * @return {!WebInspector.TextRange} |
285 */ | 285 */ |
286 WebInspector.TextRange.fromEdit = function(oldRange, newText) | 286 WebInspector.TextRange.fromEdit = function(oldRange, newText) |
287 { | 287 { |
288 var endLine = oldRange.startLine; | 288 var endLine = oldRange.startLine; |
289 var endColumn = oldRange.startColumn + newText.length; | 289 var endColumn = oldRange.startColumn + newText.length; |
290 var lineEndings = newText.computeLineEndings(); | 290 var lineEndings = newText.computeLineEndings(); |
291 if (lineEndings.length > 1) { | 291 if (lineEndings.length > 1) { |
292 endLine = oldRange.startLine + lineEndings.length - 1; | 292 endLine = oldRange.startLine + lineEndings.length - 1; |
293 var len = lineEndings.length; | 293 var len = lineEndings.length; |
294 endColumn = lineEndings[len - 1] - lineEndings[len - 2] - 1; | 294 endColumn = lineEndings[len - 1] - lineEndings[len - 2] - 1; |
295 } | 295 } |
296 return new WebInspector.TextRange( | 296 return new WebInspector.TextRange( |
297 oldRange.startLine, | 297 oldRange.startLine, |
298 oldRange.startColumn, | 298 oldRange.startColumn, |
299 endLine, | 299 endLine, |
300 endColumn); | 300 endColumn); |
301 } | 301 }; |
302 | 302 |
303 /** | 303 /** |
304 * @constructor | 304 * @constructor |
305 * @param {number} offset | 305 * @param {number} offset |
306 * @param {number} length | 306 * @param {number} length |
307 */ | 307 */ |
308 WebInspector.SourceRange = function(offset, length) | 308 WebInspector.SourceRange = function(offset, length) |
309 { | 309 { |
310 this.offset = offset; | 310 this.offset = offset; |
311 this.length = length; | 311 this.length = length; |
312 } | 312 }; |
313 | 313 |
314 /** | 314 /** |
315 * @constructor | 315 * @constructor |
316 * @param {string} sourceURL | 316 * @param {string} sourceURL |
317 * @param {!WebInspector.TextRange} oldRange | 317 * @param {!WebInspector.TextRange} oldRange |
318 * @param {string} newText | 318 * @param {string} newText |
319 */ | 319 */ |
320 WebInspector.SourceEdit = function(sourceURL, oldRange, newText) | 320 WebInspector.SourceEdit = function(sourceURL, oldRange, newText) |
321 { | 321 { |
322 this.sourceURL = sourceURL; | 322 this.sourceURL = sourceURL; |
323 this.oldRange = oldRange; | 323 this.oldRange = oldRange; |
324 this.newText = newText; | 324 this.newText = newText; |
325 } | 325 }; |
326 | 326 |
327 WebInspector.SourceEdit.prototype = { | 327 WebInspector.SourceEdit.prototype = { |
328 /** | 328 /** |
329 * @return {!WebInspector.TextRange} | 329 * @return {!WebInspector.TextRange} |
330 */ | 330 */ |
331 newRange: function() | 331 newRange: function() |
332 { | 332 { |
333 return WebInspector.TextRange.fromEdit(this.oldRange, this.newText); | 333 return WebInspector.TextRange.fromEdit(this.oldRange, this.newText); |
334 }, | 334 }, |
335 } | 335 }; |
336 | 336 |
337 /** | 337 /** |
338 * @param {!WebInspector.SourceEdit} edit1 | 338 * @param {!WebInspector.SourceEdit} edit1 |
339 * @param {!WebInspector.SourceEdit} edit2 | 339 * @param {!WebInspector.SourceEdit} edit2 |
340 * @return {number} | 340 * @return {number} |
341 */ | 341 */ |
342 WebInspector.SourceEdit.comparator = function(edit1, edit2) | 342 WebInspector.SourceEdit.comparator = function(edit1, edit2) |
343 { | 343 { |
344 return WebInspector.TextRange.comparator(edit1.oldRange, edit2.oldRange); | 344 return WebInspector.TextRange.comparator(edit1.oldRange, edit2.oldRange); |
345 } | 345 }; |
OLD | NEW |