Chromium Code Reviews| 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 relative.startColumn -= column; | 218 relative.startColumn -= column; |
| 219 if (this.endLine == line) | 219 if (this.endLine == line) |
| 220 relative.endColumn -= column; | 220 relative.endColumn -= column; |
| 221 | 221 |
| 222 relative.startLine -= line; | 222 relative.startLine -= line; |
| 223 relative.endLine -= line; | 223 relative.endLine -= line; |
| 224 return relative; | 224 return relative; |
| 225 }, | 225 }, |
| 226 | 226 |
| 227 /** | 227 /** |
| 228 * @param {string} text | |
| 229 * @return {!WebInspector.SourceRange} | |
| 230 */ | |
| 231 toSourceRange: function(text) | |
| 232 { | |
| 233 var start = text.offsetFromPosition(this.startLine, this.startColumn); | |
| 234 var end = text.offsetFromPosition(this.endLine, this.endColumn); | |
| 235 return new WebInspector.SourceRange(start, end - start); | |
| 236 }, | |
| 237 | |
| 238 /** | |
| 239 * @param {!WebInspector.TextRange} originalRange | 228 * @param {!WebInspector.TextRange} originalRange |
| 240 * @param {!WebInspector.TextRange} editedRange | 229 * @param {!WebInspector.TextRange} editedRange |
| 241 * @return {!WebInspector.TextRange} | 230 * @return {!WebInspector.TextRange} |
| 242 */ | 231 */ |
| 243 rebaseAfterTextEdit: function(originalRange, editedRange) | 232 rebaseAfterTextEdit: function(originalRange, editedRange) |
| 244 { | 233 { |
| 245 console.assert(originalRange.startLine === editedRange.startLine); | 234 console.assert(originalRange.startLine === editedRange.startLine); |
| 246 console.assert(originalRange.startColumn === editedRange.startColumn); | 235 console.assert(originalRange.startColumn === editedRange.startColumn); |
| 247 var rebase = this.clone(); | 236 var rebase = this.clone(); |
| 248 if (!this.follows(originalRange)) | 237 if (!this.follows(originalRange)) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 261 /** | 250 /** |
| 262 * @override | 251 * @override |
| 263 * @return {string} | 252 * @return {string} |
| 264 */ | 253 */ |
| 265 toString: function() | 254 toString: function() |
| 266 { | 255 { |
| 267 return JSON.stringify(this); | 256 return JSON.stringify(this); |
| 268 }, | 257 }, |
| 269 | 258 |
| 270 /** | 259 /** |
| 271 * @param {string} text | |
| 272 * @param {string} replacement | |
| 273 * @return {string} | |
| 274 */ | |
| 275 replaceInText: function(text, replacement) | |
| 276 { | |
| 277 var sourceRange = this.toSourceRange(text); | |
| 278 return text.substring(0, sourceRange.offset) + replacement + text.substr ing(sourceRange.offset + sourceRange.length); | |
| 279 }, | |
| 280 | |
| 281 /** | |
| 282 * @param {string} text | |
| 283 * @return {string} | |
| 284 */ | |
| 285 extract: function(text) | |
| 286 { | |
| 287 var sourceRange = this.toSourceRange(text); | |
| 288 return text.substr(sourceRange.offset, sourceRange.length); | |
| 289 }, | |
| 290 | |
| 291 /** | |
| 292 * @param {number} lineNumber | 260 * @param {number} lineNumber |
| 293 * @param {number} columnNumber | 261 * @param {number} columnNumber |
| 294 * @return {boolean} | 262 * @return {boolean} |
| 295 */ | 263 */ |
| 296 containsLocation: function(lineNumber, columnNumber) | 264 containsLocation: function(lineNumber, columnNumber) |
| 297 { | 265 { |
| 298 if (this.startLine === this.endLine) | 266 if (this.startLine === this.endLine) |
| 299 return this.startLine === lineNumber && this.startColumn <= columnNu mber && columnNumber <= this.endColumn; | 267 return this.startLine === lineNumber && this.startColumn <= columnNu mber && columnNumber <= this.endColumn; |
| 300 if (this.startLine === lineNumber) | 268 if (this.startLine === lineNumber) |
| 301 return this.startColumn <= columnNumber; | 269 return this.startColumn <= columnNumber; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 * @param {number} length | 301 * @param {number} length |
| 334 */ | 302 */ |
| 335 WebInspector.SourceRange = function(offset, length) | 303 WebInspector.SourceRange = function(offset, length) |
| 336 { | 304 { |
| 337 this.offset = offset; | 305 this.offset = offset; |
| 338 this.length = length; | 306 this.length = length; |
| 339 } | 307 } |
| 340 | 308 |
| 341 WebInspector.SourceRange.prototype = { | 309 WebInspector.SourceRange.prototype = { |
| 342 /** | 310 /** |
| 343 * @param {string} text | 311 * @param {!WebInspector.Text} text |
| 344 * @return {!WebInspector.TextRange} | 312 * @return {!WebInspector.TextRange} |
| 345 */ | 313 */ |
| 346 toTextRange: function(text) | 314 toTextRange: function(text) |
| 347 { | 315 { |
| 348 var p1 = fromOffset(text, this.offset); | 316 var p1 = fromOffset(text, this.offset); |
| 349 var p2 = fromOffset(text, this.offset + this.length); | 317 var p2 = fromOffset(text, this.offset + this.length); |
| 350 return new WebInspector.TextRange(p1.lineNumber, p1.columnNumber, p2.lin eNumber, p2.columnNumber); | 318 return new WebInspector.TextRange(p1.lineNumber, p1.columnNumber, p2.lin eNumber, p2.columnNumber); |
| 351 | 319 |
| 352 /** | 320 /** |
| 353 * @param {string} text | 321 * @param {!WebInspector.Text} text |
| 354 * @param {number} offset | 322 * @param {number} offset |
| 355 * @return {!{lineNumber: number, columnNumber: number}} | 323 * @return {!{lineNumber: number, columnNumber: number}} |
| 356 */ | 324 */ |
| 357 function fromOffset(text, offset) | 325 function fromOffset(text, offset) |
| 358 { | 326 { |
| 359 var lineEndings = text.lineEndings(); | 327 var lineEndings = text.lineEndings(); |
| 360 var lineNumber = lineEndings.lowerBound(offset); | 328 var lineNumber = lineEndings.lowerBound(offset); |
| 361 var columnNumber = lineNumber === 0 ? offset : offset - lineEndings[ lineNumber - 1] - 1; | 329 var columnNumber = lineNumber === 0 ? offset : offset - lineEndings[ lineNumber - 1] - 1; |
| 362 return {lineNumber: lineNumber, columnNumber: columnNumber}; | 330 return {lineNumber: lineNumber, columnNumber: columnNumber}; |
| 363 } | 331 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 380 WebInspector.SourceEdit.prototype = { | 348 WebInspector.SourceEdit.prototype = { |
| 381 /** | 349 /** |
| 382 * @return {!WebInspector.TextRange} | 350 * @return {!WebInspector.TextRange} |
| 383 */ | 351 */ |
| 384 newRange: function() | 352 newRange: function() |
| 385 { | 353 { |
| 386 return WebInspector.TextRange.fromEdit(this.oldRange, this.newText); | 354 return WebInspector.TextRange.fromEdit(this.oldRange, this.newText); |
| 387 }, | 355 }, |
| 388 | 356 |
| 389 /** | 357 /** |
| 390 * @param {string} text | 358 * @param {!WebInspector.Text} text |
| 391 * @return {string} | 359 * @return {!WebInspector.Text} |
| 392 */ | 360 */ |
| 393 applyToText: function(text) | 361 applyToText: function(text) |
|
dgozman
2016/03/16 20:36:48
Is this one used?
lushnikov
2016/03/16 21:04:01
There was a single client; i inlined it and remove
| |
| 394 { | 362 { |
| 395 return this.oldRange.replaceInText(text, this.newText); | 363 return new WebInspector.Text(text.replaceRange(this.oldRange, this.newTe xt)); |
| 396 }, | 364 }, |
| 397 } | 365 } |
| OLD | NEW |