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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 | 150 |
| 151 /** | 151 /** |
| 152 * @return {!WebInspector.TextRange} | 152 * @return {!WebInspector.TextRange} |
| 153 */ | 153 */ |
| 154 clone: function() | 154 clone: function() |
| 155 { | 155 { |
| 156 return new WebInspector.TextRange(this.startLine, this.startColumn, this .endLine, this.endColumn); | 156 return new WebInspector.TextRange(this.startLine, this.startColumn, this .endLine, this.endColumn); |
| 157 }, | 157 }, |
| 158 | 158 |
| 159 /** | 159 /** |
| 160 * @return {!Object} | 160 * @return {!{startLine: number, startColumn: number, endLine: number, endCo lumn: number}} |
| 161 */ | 161 */ |
| 162 serializeToObject: function() | 162 serializeToObject: function() |
| 163 { | 163 { |
| 164 var serializedTextRange = {}; | 164 var serializedTextRange = {}; |
| 165 serializedTextRange.startLine = this.startLine; | 165 serializedTextRange.startLine = this.startLine; |
| 166 serializedTextRange.startColumn = this.startColumn; | 166 serializedTextRange.startColumn = this.startColumn; |
| 167 serializedTextRange.endLine = this.endLine; | 167 serializedTextRange.endLine = this.endLine; |
| 168 serializedTextRange.endColumn = this.endColumn; | 168 serializedTextRange.endColumn = this.endColumn; |
| 169 return serializedTextRange; | 169 return serializedTextRange; |
| 170 }, | 170 }, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 199 /** | 199 /** |
| 200 * @param {number} lineOffset | 200 * @param {number} lineOffset |
| 201 * @return {!WebInspector.TextRange} | 201 * @return {!WebInspector.TextRange} |
| 202 */ | 202 */ |
| 203 shift: function(lineOffset) | 203 shift: function(lineOffset) |
| 204 { | 204 { |
| 205 return new WebInspector.TextRange(this.startLine + lineOffset, this.star tColumn, this.endLine + lineOffset, this.endColumn); | 205 return new WebInspector.TextRange(this.startLine + lineOffset, this.star tColumn, this.endLine + lineOffset, this.endColumn); |
| 206 }, | 206 }, |
| 207 | 207 |
| 208 /** | 208 /** |
| 209 * @param {number} line | |
| 210 * @param {number} column | |
| 211 * @return {!WebInspector.TextRange} | |
| 212 */ | |
| 213 relativeTo: function(line, column) | |
| 214 { | |
| 215 var relative = this.clone(); | |
| 216 | |
| 217 if (this.startLine == line) | |
| 218 relative.startColumn -= column; | |
| 219 if (this.endLine == line) | |
| 220 relative.endColumn -= column; | |
| 221 | |
| 222 relative.startLine -= line; | |
| 223 relative.endLine -= line; | |
| 224 return relative; | |
| 225 }, | |
| 226 | |
| 227 /** | |
| 228 * @param {string} text | |
| 229 * @return {!WebInspector.SourceRange} | |
| 230 */ | |
| 231 toSourceRange: function(text) | |
| 232 { | |
| 233 var start = (this.startLine ? text.lineEndings()[this.startLine - 1] + 1 : 0) + this.startColumn; | |
| 234 var end = (this.endLine ? text.lineEndings()[this.endLine - 1] + 1 : 0) + this.endColumn; | |
| 235 return new WebInspector.SourceRange(start, end - start); | |
| 236 }, | |
| 237 | |
| 238 /** | |
| 209 * @param {!WebInspector.TextRange} originalRange | 239 * @param {!WebInspector.TextRange} originalRange |
| 210 * @param {!WebInspector.TextRange} editedRange | 240 * @param {!WebInspector.TextRange} editedRange |
| 211 * @return {!WebInspector.TextRange} | 241 * @return {!WebInspector.TextRange} |
| 212 */ | 242 */ |
| 213 rebaseAfterTextEdit: function(originalRange, editedRange) | 243 rebaseAfterTextEdit: function(originalRange, editedRange) |
| 214 { | 244 { |
| 215 console.assert(originalRange.startLine === editedRange.startLine); | 245 console.assert(originalRange.startLine === editedRange.startLine); |
| 216 console.assert(originalRange.startColumn === editedRange.startColumn); | 246 console.assert(originalRange.startColumn === editedRange.startColumn); |
| 217 var rebase = this.clone(); | 247 var rebase = this.clone(); |
| 218 if (!this.follows(originalRange)) | 248 if (!this.follows(originalRange)) |
| 219 return rebase; | 249 return rebase; |
| 220 var lineDelta = editedRange.endLine - originalRange.endLine; | 250 var lineDelta = editedRange.endLine - originalRange.endLine; |
| 221 var columnDelta = editedRange.endColumn - originalRange.endColumn; | 251 var columnDelta = editedRange.endColumn - originalRange.endColumn; |
| 222 rebase.startLine += lineDelta; | 252 rebase.startLine += lineDelta; |
| 223 rebase.endLine += lineDelta; | 253 rebase.endLine += lineDelta; |
| 224 if (rebase.startLine === editedRange.endLine) | 254 if (rebase.startLine === editedRange.endLine) |
| 225 rebase.startColumn += columnDelta; | 255 rebase.startColumn += columnDelta; |
| 226 if (rebase.endLine === editedRange.endLine) | 256 if (rebase.endLine === editedRange.endLine) |
| 227 rebase.endColumn += columnDelta; | 257 rebase.endColumn += columnDelta; |
| 228 return rebase; | 258 return rebase; |
| 229 }, | 259 }, |
| 230 | 260 |
| 231 /** | 261 /** |
| 232 * @override | 262 * @override |
| 233 * @return {string} | 263 * @return {string} |
| 234 */ | 264 */ |
| 235 toString: function() | 265 toString: function() |
| 236 { | 266 { |
| 237 return JSON.stringify(this); | 267 return JSON.stringify(this); |
| 268 }, | |
| 269 | |
| 270 /** | |
| 271 * @param {string} text | |
| 272 * @param {string} replacement | |
| 273 * @return {string} | |
| 274 */ | |
| 275 replaceInText: function(text, replacement) | |
|
lushnikov
2015/06/19 15:34:21
=(
| |
| 276 { | |
| 277 var sourceRange = this.toSourceRange(text); | |
| 278 return text.substring(0, sourceRange.offset) + replacement + text.substr ing(sourceRange.offset + sourceRange.length); | |
| 238 } | 279 } |
| 239 } | 280 } |
| 240 | 281 |
| 241 /** | 282 /** |
| 242 * @constructor | 283 * @constructor |
| 243 * @param {number} offset | 284 * @param {number} offset |
| 244 * @param {number} length | 285 * @param {number} length |
| 245 */ | 286 */ |
| 246 WebInspector.SourceRange = function(offset, length) | 287 WebInspector.SourceRange = function(offset, length) |
| 247 { | 288 { |
| 248 this.offset = offset; | 289 this.offset = offset; |
| 249 this.length = length; | 290 this.length = length; |
| 250 } | 291 } |
| OLD | NEW |