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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 * @param {number} line 47 * @param {number} line
48 * @param {number} column 48 * @param {number} column
49 * @return {!WebInspector.TextRange} 49 * @return {!WebInspector.TextRange}
50 */ 50 */
51 WebInspector.TextRange.createFromLocation = function(line, column) 51 WebInspector.TextRange.createFromLocation = function(line, column)
52 { 52 {
53 return new WebInspector.TextRange(line, column, line, column); 53 return new WebInspector.TextRange(line, column, line, column);
54 } 54 }
55 55
56 /** 56 /**
57 * @param {string} text
58 * @param {!WebInspector.SourceRange} range
59 * @return {!WebInspector.TextRange}
60 */
61 WebInspector.TextRange.createFromSourceRange = function(text, range)
62 {
63 var start = p(text, range.offset);
64 var end = p(text, range.offset + range.length);
65 return new WebInspector.TextRange(start.startLine, start.startColumn, end.en dLine, end.endColumn);
66
67 /**
68 * @param {string} text
69 * @param {number} offset
70 */
71 function p(text, offset)
72 {
73 var lineEndings = text.lineEndings();
74 var lineIndex = lineEndings.lowerBound(offset);
75 var lineStartOffset = lineIndex > 0 ? lineEndings[lineIndex - 1] + 1 : 0 ;
76 return WebInspector.TextRange.createFromLocation(lineIndex, offset - lin eStartOffset);
77 }
78 }
79
80 /**
57 * @param {!Object} serializedTextRange 81 * @param {!Object} serializedTextRange
58 * @return {!WebInspector.TextRange} 82 * @return {!WebInspector.TextRange}
59 */ 83 */
60 WebInspector.TextRange.fromObject = function(serializedTextRange) 84 WebInspector.TextRange.fromObject = function(serializedTextRange)
61 { 85 {
62 return new WebInspector.TextRange(serializedTextRange.startLine, serializedT extRange.startColumn, serializedTextRange.endLine, serializedTextRange.endColumn ); 86 return new WebInspector.TextRange(serializedTextRange.startLine, serializedT extRange.startColumn, serializedTextRange.endLine, serializedTextRange.endColumn );
63 } 87 }
64 88
65 /** 89 /**
66 * @param {!WebInspector.TextRange} range1 90 * @param {!WebInspector.TextRange} range1
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 293
270 /** 294 /**
271 * @param {string} text 295 * @param {string} text
272 * @param {string} replacement 296 * @param {string} replacement
273 * @return {string} 297 * @return {string}
274 */ 298 */
275 replaceInText: function(text, replacement) 299 replaceInText: function(text, replacement)
276 { 300 {
277 var sourceRange = this.toSourceRange(text); 301 var sourceRange = this.toSourceRange(text);
278 return text.substring(0, sourceRange.offset) + replacement + text.substr ing(sourceRange.offset + sourceRange.length); 302 return text.substring(0, sourceRange.offset) + replacement + text.substr ing(sourceRange.offset + sourceRange.length);
279 } 303 },
304
305 extract: function(text)
306 {
307 var sourceRange = this.toSourceRange(text);
308 return text.substr(sourceRange.offset, sourceRange.length);
309 },
310
311 /**
312 * @param {number} lineNumber
313 * @param {number} columnNumber
314 * @return {boolean}
315 */
316 containsLocation: function(lineNumber, columnNumber)
317 {
318 if (this.startLine > lineNumber)
319 return false;
320 if (this.endLine < lineNumber)
321 return false;
322 if (this.startLine < lineNumber && lineNumber < this.endLine)
323 return true;
324 if (this.startLine === this.endLine && this.startLine === lineNumber)
325 return this.startColumn < columnNumber && columnNumber < this.endCol umn;
326 if (this.startLine === lineNumber)
327 return this.startColumn < columnNumber;
328 if (this.endLine === lineNumber)
329 return this.endColumn > columnNumber;
330 return false;
331 },
280 } 332 }
281 333
282 /** 334 /**
283 * @constructor 335 * @constructor
284 * @param {number} offset 336 * @param {number} offset
285 * @param {number} length 337 * @param {number} length
286 */ 338 */
287 WebInspector.SourceRange = function(offset, length) 339 WebInspector.SourceRange = function(offset, length)
288 { 340 {
289 this.offset = offset; 341 this.offset = offset;
290 this.length = length; 342 this.length = length;
291 } 343 }
OLDNEW
« 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