| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @param {string} value | 7 * @param {string} value |
| 8 */ | 8 */ |
| 9 WebInspector.Text = function(value) | 9 WebInspector.Text = function(value) |
| 10 { | 10 { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 * @return {!WebInspector.SourceRange} | 68 * @return {!WebInspector.SourceRange} |
| 69 */ | 69 */ |
| 70 toSourceRange: function(range) | 70 toSourceRange: function(range) |
| 71 { | 71 { |
| 72 var start = this.offsetFromPosition(range.startLine, range.startColumn); | 72 var start = this.offsetFromPosition(range.startLine, range.startColumn); |
| 73 var end = this.offsetFromPosition(range.endLine, range.endColumn); | 73 var end = this.offsetFromPosition(range.endLine, range.endColumn); |
| 74 return new WebInspector.SourceRange(start, end - start); | 74 return new WebInspector.SourceRange(start, end - start); |
| 75 }, | 75 }, |
| 76 | 76 |
| 77 /** | 77 /** |
| 78 * @param {!WebInspector.SourceRange} sourceRange |
| 79 * @return {!WebInspector.TextRange} |
| 80 */ |
| 81 toTextRange: function(sourceRange) |
| 82 { |
| 83 var cursor = new WebInspector.TextCursor(this.lineEndings()); |
| 84 var result = WebInspector.TextRange.createFromLocation(0, 0); |
| 85 |
| 86 cursor.resetTo(sourceRange.offset); |
| 87 result.startLine = cursor.lineNumber(); |
| 88 result.startColumn = cursor.columnNumber(); |
| 89 |
| 90 cursor.advance(sourceRange.offset + sourceRange.length); |
| 91 result.endLine = cursor.lineNumber(); |
| 92 result.endColumn = cursor.columnNumber(); |
| 93 return result; |
| 94 }, |
| 95 |
| 96 /** |
| 78 * @param {!WebInspector.TextRange} range | 97 * @param {!WebInspector.TextRange} range |
| 79 * @param {string} replacement | 98 * @param {string} replacement |
| 80 * @return {string} | 99 * @return {string} |
| 81 */ | 100 */ |
| 82 replaceRange: function(range, replacement) | 101 replaceRange: function(range, replacement) |
| 83 { | 102 { |
| 84 var sourceRange = this.toSourceRange(range); | 103 var sourceRange = this.toSourceRange(range); |
| 85 return this._value.substring(0, sourceRange.offset) + replacement + this
._value.substring(sourceRange.offset + sourceRange.length); | 104 return this._value.substring(0, sourceRange.offset) + replacement + this
._value.substring(sourceRange.offset + sourceRange.length); |
| 86 }, | 105 }, |
| 87 | 106 |
| 88 /** | 107 /** |
| 89 * @param {!WebInspector.TextRange} range | 108 * @param {!WebInspector.TextRange} range |
| 90 * @return {string} | 109 * @return {string} |
| 91 */ | 110 */ |
| 92 extract: function(range) | 111 extract: function(range) |
| 93 { | 112 { |
| 94 var sourceRange = this.toSourceRange(range); | 113 var sourceRange = this.toSourceRange(range); |
| 95 return this._value.substr(sourceRange.offset, sourceRange.length); | 114 return this._value.substr(sourceRange.offset, sourceRange.length); |
| 96 }, | 115 } |
| 97 } | 116 } |
| 98 | 117 |
| 99 /** | 118 /** |
| 100 * @constructor | 119 * @constructor |
| 101 * @param {!Array<number>} lineEndings | 120 * @param {!Array<number>} lineEndings |
| 102 */ | 121 */ |
| 103 WebInspector.TextCursor = function(lineEndings) | 122 WebInspector.TextCursor = function(lineEndings) |
| 104 { | 123 { |
| 105 this._lineEndings = lineEndings; | 124 this._lineEndings = lineEndings; |
| 106 this._offset = 0; | 125 this._offset = 0; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 }, | 166 }, |
| 148 | 167 |
| 149 /** | 168 /** |
| 150 * @return {number} | 169 * @return {number} |
| 151 */ | 170 */ |
| 152 columnNumber: function() | 171 columnNumber: function() |
| 153 { | 172 { |
| 154 return this._columnNumber; | 173 return this._columnNumber; |
| 155 } | 174 } |
| 156 } | 175 } |
| OLD | NEW |