| Index: Source/devtools/front_end/common/TextRange.js
|
| diff --git a/Source/devtools/front_end/common/TextRange.js b/Source/devtools/front_end/common/TextRange.js
|
| index 9c1bcd987e2a5935218523d15168961bda1724a1..083dc49631c61bee67ae6dc9befa3c483d75b464 100644
|
| --- a/Source/devtools/front_end/common/TextRange.js
|
| +++ b/Source/devtools/front_end/common/TextRange.js
|
| @@ -54,6 +54,30 @@ WebInspector.TextRange.createFromLocation = function(line, column)
|
| }
|
|
|
| /**
|
| + * @param {string} text
|
| + * @param {!WebInspector.SourceRange} range
|
| + * @return {!WebInspector.TextRange}
|
| + */
|
| +WebInspector.TextRange.createFromSourceRange = function(text, range)
|
| +{
|
| + var start = p(text, range.offset);
|
| + var end = p(text, range.offset + range.length);
|
| + return new WebInspector.TextRange(start.startLine, start.startColumn, end.endLine, end.endColumn);
|
| +
|
| + /**
|
| + * @param {string} text
|
| + * @param {number} offset
|
| + */
|
| + function p(text, offset)
|
| + {
|
| + var lineEndings = text.lineEndings();
|
| + var lineIndex = lineEndings.lowerBound(offset);
|
| + var lineStartOffset = lineIndex > 0 ? lineEndings[lineIndex - 1] + 1 : 0;
|
| + return WebInspector.TextRange.createFromLocation(lineIndex, offset - lineStartOffset);
|
| + }
|
| +}
|
| +
|
| +/**
|
| * @param {!Object} serializedTextRange
|
| * @return {!WebInspector.TextRange}
|
| */
|
| @@ -276,7 +300,35 @@ WebInspector.TextRange.prototype = {
|
| {
|
| var sourceRange = this.toSourceRange(text);
|
| return text.substring(0, sourceRange.offset) + replacement + text.substring(sourceRange.offset + sourceRange.length);
|
| - }
|
| + },
|
| +
|
| + extract: function(text)
|
| + {
|
| + var sourceRange = this.toSourceRange(text);
|
| + return text.substr(sourceRange.offset, sourceRange.length);
|
| + },
|
| +
|
| + /**
|
| + * @param {number} lineNumber
|
| + * @param {number} columnNumber
|
| + * @return {boolean}
|
| + */
|
| + containsLocation: function(lineNumber, columnNumber)
|
| + {
|
| + if (this.startLine > lineNumber)
|
| + return false;
|
| + if (this.endLine < lineNumber)
|
| + return false;
|
| + if (this.startLine < lineNumber && lineNumber < this.endLine)
|
| + return true;
|
| + if (this.startLine === this.endLine && this.startLine === lineNumber)
|
| + return this.startColumn < columnNumber && columnNumber < this.endColumn;
|
| + if (this.startLine === lineNumber)
|
| + return this.startColumn < columnNumber;
|
| + if (this.endLine === lineNumber)
|
| + return this.endColumn > columnNumber;
|
| + return false;
|
| + },
|
| }
|
|
|
| /**
|
|
|