OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 delete this._lineToScrollTo; | 182 delete this._lineToScrollTo; |
183 } | 183 } |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 _clearLineToScrollTo() { | 187 _clearLineToScrollTo() { |
188 delete this._lineToScrollTo; | 188 delete this._lineToScrollTo; |
189 } | 189 } |
190 | 190 |
191 /** | 191 /** |
192 * @return {!Common.TextRange} | 192 * @return {!TextUtils.TextRange} |
193 */ | 193 */ |
194 selection() { | 194 selection() { |
195 return this.textEditor.selection(); | 195 return this.textEditor.selection(); |
196 } | 196 } |
197 | 197 |
198 /** | 198 /** |
199 * @param {!Common.TextRange} textRange | 199 * @param {!TextUtils.TextRange} textRange |
200 */ | 200 */ |
201 setSelection(textRange) { | 201 setSelection(textRange) { |
202 this._selectionToSet = textRange; | 202 this._selectionToSet = textRange; |
203 this._innerSetSelectionIfNeeded(); | 203 this._innerSetSelectionIfNeeded(); |
204 } | 204 } |
205 | 205 |
206 _innerSetSelectionIfNeeded() { | 206 _innerSetSelectionIfNeeded() { |
207 if (this._selectionToSet && this.loaded && this.isEditorShowing()) { | 207 if (this._selectionToSet && this.loaded && this.isEditorShowing()) { |
208 this._textEditor.setSelection(this._selectionToSet); | 208 this._textEditor.setSelection(this._selectionToSet); |
209 delete this._selectionToSet; | 209 delete this._selectionToSet; |
210 } | 210 } |
211 } | 211 } |
212 | 212 |
213 _clearSelectionToSet() { | 213 _clearSelectionToSet() { |
214 delete this._selectionToSet; | 214 delete this._selectionToSet; |
215 } | 215 } |
216 | 216 |
217 _wasShownOrLoaded() { | 217 _wasShownOrLoaded() { |
218 this._innerRevealPositionIfNeeded(); | 218 this._innerRevealPositionIfNeeded(); |
219 this._innerSetSelectionIfNeeded(); | 219 this._innerSetSelectionIfNeeded(); |
220 this._innerScrollToLineIfNeeded(); | 220 this._innerScrollToLineIfNeeded(); |
221 } | 221 } |
222 | 222 |
223 /** | 223 /** |
224 * @param {!Common.TextRange} oldRange | 224 * @param {!TextUtils.TextRange} oldRange |
225 * @param {!Common.TextRange} newRange | 225 * @param {!TextUtils.TextRange} newRange |
226 */ | 226 */ |
227 onTextChanged(oldRange, newRange) { | 227 onTextChanged(oldRange, newRange) { |
228 if (this._searchConfig && this._searchableView) | 228 if (this._searchConfig && this._searchableView) |
229 this.performSearch(this._searchConfig, false, false); | 229 this.performSearch(this._searchConfig, false, false); |
230 } | 230 } |
231 | 231 |
232 /** | 232 /** |
233 * @param {string} content | 233 * @param {string} content |
234 * @param {string} mimeType | 234 * @param {string} mimeType |
235 * @return {string} | 235 * @return {string} |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 } | 385 } |
386 | 386 |
387 jumpToLastSearchResult() { | 387 jumpToLastSearchResult() { |
388 this.jumpToSearchResult(this._searchResults.length - 1); | 388 this.jumpToSearchResult(this._searchResults.length - 1); |
389 } | 389 } |
390 | 390 |
391 /** | 391 /** |
392 * @return {number} | 392 * @return {number} |
393 */ | 393 */ |
394 _searchResultIndexForCurrentSelection() { | 394 _searchResultIndexForCurrentSelection() { |
395 return this._searchResults.lowerBound(this._textEditor.selection().collapseT
oEnd(), Common.TextRange.comparator); | 395 return this._searchResults.lowerBound(this._textEditor.selection().collapseT
oEnd(), TextUtils.TextRange.comparator); |
396 } | 396 } |
397 | 397 |
398 /** | 398 /** |
399 * @override | 399 * @override |
400 */ | 400 */ |
401 jumpToNextSearchResult() { | 401 jumpToNextSearchResult() { |
402 var currentIndex = this._searchResultIndexForCurrentSelection(); | 402 var currentIndex = this._searchResultIndexForCurrentSelection(); |
403 var nextIndex = this._currentSearchResultIndex === -1 ? currentIndex : curre
ntIndex + 1; | 403 var nextIndex = this._currentSearchResultIndex === -1 ? currentIndex : curre
ntIndex + 1; |
404 this.jumpToSearchResult(nextIndex); | 404 this.jumpToSearchResult(nextIndex); |
405 } | 405 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 text = text.replace(regex, function() { | 485 text = text.replace(regex, function() { |
486 return replacement; | 486 return replacement; |
487 }); | 487 }); |
488 } | 488 } |
489 | 489 |
490 var ranges = this._collectRegexMatches(regex); | 490 var ranges = this._collectRegexMatches(regex); |
491 if (!ranges.length) | 491 if (!ranges.length) |
492 return; | 492 return; |
493 | 493 |
494 // Calculate the position of the end of the last range to be edited. | 494 // Calculate the position of the end of the last range to be edited. |
495 var currentRangeIndex = ranges.lowerBound(this._textEditor.selection(), Comm
on.TextRange.comparator); | 495 var currentRangeIndex = ranges.lowerBound(this._textEditor.selection(), Text
Utils.TextRange.comparator); |
496 var lastRangeIndex = mod(currentRangeIndex - 1, ranges.length); | 496 var lastRangeIndex = mod(currentRangeIndex - 1, ranges.length); |
497 var lastRange = ranges[lastRangeIndex]; | 497 var lastRange = ranges[lastRangeIndex]; |
498 var replacementLineEndings = replacement.computeLineEndings(); | 498 var replacementLineEndings = replacement.computeLineEndings(); |
499 var replacementLineCount = replacementLineEndings.length; | 499 var replacementLineCount = replacementLineEndings.length; |
500 var lastLineNumber = lastRange.startLine + replacementLineEndings.length - 1
; | 500 var lastLineNumber = lastRange.startLine + replacementLineEndings.length - 1
; |
501 var lastColumnNumber = lastRange.startColumn; | 501 var lastColumnNumber = lastRange.startColumn; |
502 if (replacementLineEndings.length > 1) { | 502 if (replacementLineEndings.length > 1) { |
503 lastColumnNumber = | 503 lastColumnNumber = |
504 replacementLineEndings[replacementLineCount - 1] - replacementLineEndi
ngs[replacementLineCount - 2] - 1; | 504 replacementLineEndings[replacementLineCount - 1] - replacementLineEndi
ngs[replacementLineCount - 2] - 1; |
505 } | 505 } |
506 | 506 |
507 this._textEditor.editRange(range, text); | 507 this._textEditor.editRange(range, text); |
508 this._textEditor.revealPosition(lastLineNumber, lastColumnNumber); | 508 this._textEditor.revealPosition(lastLineNumber, lastColumnNumber); |
509 this._textEditor.setSelection(Common.TextRange.createFromLocation(lastLineNu
mber, lastColumnNumber)); | 509 this._textEditor.setSelection(TextUtils.TextRange.createFromLocation(lastLin
eNumber, lastColumnNumber)); |
510 } | 510 } |
511 | 511 |
512 _collectRegexMatches(regexObject) { | 512 _collectRegexMatches(regexObject) { |
513 var ranges = []; | 513 var ranges = []; |
514 for (var i = 0; i < this._textEditor.linesCount; ++i) { | 514 for (var i = 0; i < this._textEditor.linesCount; ++i) { |
515 var line = this._textEditor.line(i); | 515 var line = this._textEditor.line(i); |
516 var offset = 0; | 516 var offset = 0; |
517 do { | 517 do { |
518 var match = regexObject.exec(line); | 518 var match = regexObject.exec(line); |
519 if (match) { | 519 if (match) { |
520 var matchEndIndex = match.index + Math.max(match[0].length, 1); | 520 var matchEndIndex = match.index + Math.max(match[0].length, 1); |
521 if (match[0].length) | 521 if (match[0].length) |
522 ranges.push(new Common.TextRange(i, offset + match.index, i, offset
+ matchEndIndex)); | 522 ranges.push(new TextUtils.TextRange(i, offset + match.index, i, offs
et + matchEndIndex)); |
523 offset += matchEndIndex; | 523 offset += matchEndIndex; |
524 line = line.substring(matchEndIndex); | 524 line = line.substring(matchEndIndex); |
525 } | 525 } |
526 } while (match && line); | 526 } while (match && line); |
527 } | 527 } |
528 return ranges; | 528 return ranges; |
529 } | 529 } |
530 | 530 |
531 /** | 531 /** |
532 * @override | 532 * @override |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 } | 576 } |
577 } | 577 } |
578 | 578 |
579 _handleKeyDown(e) { | 579 _handleKeyDown(e) { |
580 var shortcutKey = UI.KeyboardShortcut.makeKeyFromEvent(e); | 580 var shortcutKey = UI.KeyboardShortcut.makeKeyFromEvent(e); |
581 var handler = this._shortcuts[shortcutKey]; | 581 var handler = this._shortcuts[shortcutKey]; |
582 if (handler && handler()) | 582 if (handler && handler()) |
583 e.consume(true); | 583 e.consume(true); |
584 } | 584 } |
585 }; | 585 }; |
OLD | NEW |