Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Unified Diff: Source/devtools/front_end/common/TextRange.js

Issue 1307063005: DevTools: edit SASS through SourceMaps. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: improvements Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
+ },
}
/**
« no previous file with comments | « Source/devtools/front_end/common/Color.js ('k') | Source/devtools/front_end/script_formatter_worker/ScriptFormatterWorker.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698