| 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 15 matching lines...) Expand all Loading... |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @constructor | 32 * @constructor |
| 33 * @extends {WebInspector.SimpleView} | 33 * @extends {WebInspector.SimpleView} |
| 34 * @implements {WebInspector.Searchable} | 34 * @implements {WebInspector.Searchable} |
| 35 * @implements {WebInspector.Replaceable} | 35 * @implements {WebInspector.Replaceable} |
| 36 * @implements {WebInspector.TextEditorDelegate} |
| 36 * @param {string} url | 37 * @param {string} url |
| 37 * @param {function(): !Promise<?string>} lazyContent | 38 * @param {function(): !Promise<?string>} lazyContent |
| 38 */ | 39 */ |
| 39 WebInspector.SourceFrame = function(url, lazyContent) | 40 WebInspector.SourceFrame = function(url, lazyContent) |
| 40 { | 41 { |
| 41 WebInspector.SimpleView.call(this, WebInspector.UIString("Source")); | 42 WebInspector.SimpleView.call(this, WebInspector.UIString("Source")); |
| 42 | 43 |
| 43 this._url = url; | 44 this._url = url; |
| 44 this._lazyContent = lazyContent; | 45 this._lazyContent = lazyContent; |
| 45 | 46 |
| 46 var textEditorDelegate = new WebInspector.TextEditorDelegateForSourceFrame(t
his); | 47 this._textEditor = new WebInspector.CodeMirrorTextEditor(this); |
| 47 | |
| 48 this._textEditor = new WebInspector.CodeMirrorTextEditor(this._url, textEdit
orDelegate); | |
| 49 | 48 |
| 50 this._currentSearchResultIndex = -1; | 49 this._currentSearchResultIndex = -1; |
| 51 this._searchResults = []; | 50 this._searchResults = []; |
| 52 | 51 |
| 53 this._textEditor.setReadOnly(!this.canEditSource()); | 52 this._textEditor.setReadOnly(!this.canEditSource()); |
| 54 | 53 |
| 55 this._shortcuts = {}; | 54 this._shortcuts = {}; |
| 56 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), fal
se); | 55 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), fal
se); |
| 57 | 56 |
| 58 this._sourcePosition = new WebInspector.ToolbarText(); | 57 this._sourcePosition = new WebInspector.ToolbarText(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 73 WebInspector.SourceFrame.prototype = { | 72 WebInspector.SourceFrame.prototype = { |
| 74 /** | 73 /** |
| 75 * @param {number} key | 74 * @param {number} key |
| 76 * @param {function():boolean} handler | 75 * @param {function():boolean} handler |
| 77 */ | 76 */ |
| 78 addShortcut: function(key, handler) | 77 addShortcut: function(key, handler) |
| 79 { | 78 { |
| 80 this._shortcuts[key] = handler; | 79 this._shortcuts[key] = handler; |
| 81 }, | 80 }, |
| 82 | 81 |
| 82 /** |
| 83 * @override |
| 84 */ |
| 83 wasShown: function() | 85 wasShown: function() |
| 84 { | 86 { |
| 85 this._ensureContentLoaded(); | 87 this._ensureContentLoaded(); |
| 86 this._textEditor.show(this.element); | 88 this._textEditor.show(this.element); |
| 87 this._editorAttached = true; | 89 this._editorAttached = true; |
| 88 this._wasShownOrLoaded(); | 90 this._wasShownOrLoaded(); |
| 89 }, | 91 }, |
| 90 | 92 |
| 91 /** | 93 /** |
| 92 * @return {boolean} | 94 * @return {boolean} |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 }, | 219 }, |
| 218 | 220 |
| 219 _wasShownOrLoaded: function() | 221 _wasShownOrLoaded: function() |
| 220 { | 222 { |
| 221 this._innerRevealPositionIfNeeded(); | 223 this._innerRevealPositionIfNeeded(); |
| 222 this._innerSetSelectionIfNeeded(); | 224 this._innerSetSelectionIfNeeded(); |
| 223 this._innerScrollToLineIfNeeded(); | 225 this._innerScrollToLineIfNeeded(); |
| 224 }, | 226 }, |
| 225 | 227 |
| 226 /** | 228 /** |
| 229 * @override |
| 227 * @param {!WebInspector.TextRange} oldRange | 230 * @param {!WebInspector.TextRange} oldRange |
| 228 * @param {!WebInspector.TextRange} newRange | 231 * @param {!WebInspector.TextRange} newRange |
| 229 */ | 232 */ |
| 230 onTextChanged: function(oldRange, newRange) | 233 onTextChanged: function(oldRange, newRange) |
| 231 { | 234 { |
| 232 if (this._searchConfig && this._searchableView) | 235 if (this._searchConfig && this._searchableView) |
| 233 this.performSearch(this._searchConfig, false, false); | 236 this.performSearch(this._searchConfig, false, false); |
| 234 }, | 237 }, |
| 235 | 238 |
| 236 /** | 239 /** |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 this._resetSearch(); | 350 this._resetSearch(); |
| 348 this._searchConfig = searchConfig; | 351 this._searchConfig = searchConfig; |
| 349 if (this.loaded) | 352 if (this.loaded) |
| 350 this._doFindSearchMatches(searchConfig, shouldJump, !!jumpBackwards) | 353 this._doFindSearchMatches(searchConfig, shouldJump, !!jumpBackwards) |
| 351 else | 354 else |
| 352 this._delayedFindSearchMatches = this._doFindSearchMatches.bind(this
, searchConfig, shouldJump, !!jumpBackwards); | 355 this._delayedFindSearchMatches = this._doFindSearchMatches.bind(this
, searchConfig, shouldJump, !!jumpBackwards); |
| 353 | 356 |
| 354 this._ensureContentLoaded(); | 357 this._ensureContentLoaded(); |
| 355 }, | 358 }, |
| 356 | 359 |
| 357 _editorFocused: function() | 360 /** |
| 361 * @override |
| 362 */ |
| 363 editorFocused: function() |
| 358 { | 364 { |
| 359 this._resetCurrentSearchResultIndex(); | 365 this._resetCurrentSearchResultIndex(); |
| 360 }, | 366 }, |
| 361 | 367 |
| 362 _resetCurrentSearchResultIndex: function() | 368 _resetCurrentSearchResultIndex: function() |
| 363 { | 369 { |
| 364 if (!this._searchResults.length) | 370 if (!this._searchResults.length) |
| 365 return; | 371 return; |
| 366 this._currentSearchResultIndex = -1; | 372 this._currentSearchResultIndex = -1; |
| 367 if (this._searchableView) | 373 if (this._searchableView) |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 ranges.push(new WebInspector.TextRange(i, offset + match
.index, i, offset + matchEndIndex)); | 552 ranges.push(new WebInspector.TextRange(i, offset + match
.index, i, offset + matchEndIndex)); |
| 547 offset += matchEndIndex; | 553 offset += matchEndIndex; |
| 548 line = line.substring(matchEndIndex); | 554 line = line.substring(matchEndIndex); |
| 549 } | 555 } |
| 550 } while (match && line); | 556 } while (match && line); |
| 551 } | 557 } |
| 552 return ranges; | 558 return ranges; |
| 553 }, | 559 }, |
| 554 | 560 |
| 555 /** | 561 /** |
| 562 * @override |
| 556 * @return {!Promise} | 563 * @return {!Promise} |
| 557 */ | 564 */ |
| 558 populateLineGutterContextMenu: function(contextMenu, lineNumber) | 565 populateLineGutterContextMenu: function(contextMenu, lineNumber) |
| 559 { | 566 { |
| 560 return Promise.resolve(); | 567 return Promise.resolve(); |
| 561 }, | 568 }, |
| 562 | 569 |
| 563 /** | 570 /** |
| 571 * @override |
| 564 * @return {!Promise} | 572 * @return {!Promise} |
| 565 */ | 573 */ |
| 566 populateTextAreaContextMenu: function(contextMenu, lineNumber, columnNumber) | 574 populateTextAreaContextMenu: function(contextMenu, lineNumber, columnNumber) |
| 567 { | 575 { |
| 568 return Promise.resolve(); | 576 return Promise.resolve(); |
| 569 }, | 577 }, |
| 570 | 578 |
| 571 /** | 579 /** |
| 580 * @override |
| 572 * @param {?WebInspector.TextRange} from | 581 * @param {?WebInspector.TextRange} from |
| 573 * @param {?WebInspector.TextRange} to | 582 * @param {?WebInspector.TextRange} to |
| 574 */ | 583 */ |
| 575 onJumpToPosition: function(from, to) | 584 onJumpToPosition: function(from, to) |
| 576 { | 585 { |
| 577 this.dispatchEventToListeners(WebInspector.SourceFrame.Events.JumpHappen
ed, { | 586 this.dispatchEventToListeners(WebInspector.SourceFrame.Events.JumpHappen
ed, { |
| 578 from: from, | 587 from: from, |
| 579 to: to | 588 to: to |
| 580 }); | 589 }); |
| 581 }, | 590 }, |
| 582 | 591 |
| 583 /** | 592 /** |
| 584 * @return {boolean} | 593 * @return {boolean} |
| 585 */ | 594 */ |
| 586 canEditSource: function() | 595 canEditSource: function() |
| 587 { | 596 { |
| 588 return false; | 597 return false; |
| 589 }, | 598 }, |
| 590 | 599 |
| 591 /** | 600 /** |
| 601 * @override |
| 592 * @param {!WebInspector.TextRange} textRange | 602 * @param {!WebInspector.TextRange} textRange |
| 593 */ | 603 */ |
| 594 selectionChanged: function(textRange) | 604 selectionChanged: function(textRange) |
| 595 { | 605 { |
| 596 this._updateSourcePosition(); | 606 this._updateSourcePosition(); |
| 597 this.dispatchEventToListeners(WebInspector.SourceFrame.Events.SelectionC
hanged, textRange); | 607 this.dispatchEventToListeners(WebInspector.SourceFrame.Events.SelectionC
hanged, textRange); |
| 598 }, | 608 }, |
| 599 | 609 |
| 600 _updateSourcePosition: function() | 610 _updateSourcePosition: function() |
| 601 { | 611 { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 614 textRange = textRange.normalize(); | 624 textRange = textRange.normalize(); |
| 615 | 625 |
| 616 var selectedText = this._textEditor.copyRange(textRange); | 626 var selectedText = this._textEditor.copyRange(textRange); |
| 617 if (textRange.startLine === textRange.endLine) | 627 if (textRange.startLine === textRange.endLine) |
| 618 this._sourcePosition.setText(WebInspector.UIString("%d characters se
lected", selectedText.length)); | 628 this._sourcePosition.setText(WebInspector.UIString("%d characters se
lected", selectedText.length)); |
| 619 else | 629 else |
| 620 this._sourcePosition.setText(WebInspector.UIString("%d lines, %d cha
racters selected", textRange.endLine - textRange.startLine + 1, selectedText.len
gth)); | 630 this._sourcePosition.setText(WebInspector.UIString("%d lines, %d cha
racters selected", textRange.endLine - textRange.startLine + 1, selectedText.len
gth)); |
| 621 }, | 631 }, |
| 622 | 632 |
| 623 /** | 633 /** |
| 634 * @override |
| 624 * @param {number} lineNumber | 635 * @param {number} lineNumber |
| 625 */ | 636 */ |
| 626 scrollChanged: function(lineNumber) | 637 scrollChanged: function(lineNumber) |
| 627 { | 638 { |
| 628 if (this._scrollTimer) | 639 if (this._scrollTimer) |
| 629 clearTimeout(this._scrollTimer); | 640 clearTimeout(this._scrollTimer); |
| 630 this._scrollTimer = setTimeout(this.dispatchEventToListeners.bind(this,
WebInspector.SourceFrame.Events.ScrollChanged, lineNumber), 100); | 641 this._scrollTimer = setTimeout(this.dispatchEventToListeners.bind(this,
WebInspector.SourceFrame.Events.ScrollChanged, lineNumber), 100); |
| 631 }, | 642 }, |
| 632 | 643 |
| 633 _handleKeyDown: function(e) | 644 _handleKeyDown: function(e) |
| 634 { | 645 { |
| 635 var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(e); | 646 var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(e); |
| 636 var handler = this._shortcuts[shortcutKey]; | 647 var handler = this._shortcuts[shortcutKey]; |
| 637 if (handler && handler()) | 648 if (handler && handler()) |
| 638 e.consume(true); | 649 e.consume(true); |
| 639 }, | 650 }, |
| 640 | 651 |
| 641 __proto__: WebInspector.SimpleView.prototype | 652 __proto__: WebInspector.SimpleView.prototype |
| 642 } | 653 } |
| 643 | |
| 644 /** | |
| 645 * @implements {WebInspector.TextEditorDelegate} | |
| 646 * @constructor | |
| 647 */ | |
| 648 WebInspector.TextEditorDelegateForSourceFrame = function(sourceFrame) | |
| 649 { | |
| 650 this._sourceFrame = sourceFrame; | |
| 651 } | |
| 652 | |
| 653 WebInspector.TextEditorDelegateForSourceFrame.prototype = { | |
| 654 /** | |
| 655 * @override | |
| 656 * @param {!WebInspector.TextRange} oldRange | |
| 657 * @param {!WebInspector.TextRange} newRange | |
| 658 */ | |
| 659 onTextChanged: function(oldRange, newRange) | |
| 660 { | |
| 661 this._sourceFrame.onTextChanged(oldRange, newRange); | |
| 662 }, | |
| 663 | |
| 664 /** | |
| 665 * @override | |
| 666 * @param {!WebInspector.TextRange} textRange | |
| 667 */ | |
| 668 selectionChanged: function(textRange) | |
| 669 { | |
| 670 this._sourceFrame.selectionChanged(textRange); | |
| 671 }, | |
| 672 | |
| 673 /** | |
| 674 * @override | |
| 675 * @param {number} lineNumber | |
| 676 */ | |
| 677 scrollChanged: function(lineNumber) | |
| 678 { | |
| 679 this._sourceFrame.scrollChanged(lineNumber); | |
| 680 }, | |
| 681 | |
| 682 /** | |
| 683 * @override | |
| 684 */ | |
| 685 editorFocused: function() | |
| 686 { | |
| 687 this._sourceFrame._editorFocused(); | |
| 688 }, | |
| 689 | |
| 690 /** | |
| 691 * @override | |
| 692 * @param {!WebInspector.ContextMenu} contextMenu | |
| 693 * @param {number} lineNumber | |
| 694 * @return {!Promise} | |
| 695 */ | |
| 696 populateLineGutterContextMenu: function(contextMenu, lineNumber) | |
| 697 { | |
| 698 return this._sourceFrame.populateLineGutterContextMenu(contextMenu, line
Number); | |
| 699 }, | |
| 700 | |
| 701 /** | |
| 702 * @override | |
| 703 * @param {!WebInspector.ContextMenu} contextMenu | |
| 704 * @param {number} lineNumber | |
| 705 * @param {number} columnNumber | |
| 706 * @return {!Promise} | |
| 707 */ | |
| 708 populateTextAreaContextMenu: function(contextMenu, lineNumber, columnNumber) | |
| 709 { | |
| 710 return this._sourceFrame.populateTextAreaContextMenu(contextMenu, lineNu
mber, columnNumber); | |
| 711 }, | |
| 712 | |
| 713 /** | |
| 714 * @override | |
| 715 * @param {?WebInspector.TextRange} from | |
| 716 * @param {?WebInspector.TextRange} to | |
| 717 */ | |
| 718 onJumpToPosition: function(from, to) | |
| 719 { | |
| 720 this._sourceFrame.onJumpToPosition(from, to); | |
| 721 } | |
| 722 } | |
| OLD | NEW |