OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2009 Joseph Pecoraro | 3 * Copyright (C) 2009 Joseph Pecoraro |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 this._filterStatusMessageElement.createTextChild(" "); | 96 this._filterStatusMessageElement.createTextChild(" "); |
97 var resetFiltersLink = this._filterStatusMessageElement.createChild("span", "console-info link"); | 97 var resetFiltersLink = this._filterStatusMessageElement.createChild("span", "console-info link"); |
98 resetFiltersLink.textContent = WebInspector.UIString("Show all messages."); | 98 resetFiltersLink.textContent = WebInspector.UIString("Show all messages."); |
99 resetFiltersLink.addEventListener("click", this._filter.reset.bind(this._fil ter), true); | 99 resetFiltersLink.addEventListener("click", this._filter.reset.bind(this._fil ter), true); |
100 | 100 |
101 this._topGroup = WebInspector.ConsoleGroup.createTopGroup(); | 101 this._topGroup = WebInspector.ConsoleGroup.createTopGroup(); |
102 this._currentGroup = this._topGroup; | 102 this._currentGroup = this._topGroup; |
103 | 103 |
104 this._promptElement = this._messagesElement.createChild("div", "source-code" ); | 104 this._promptElement = this._messagesElement.createChild("div", "source-code" ); |
105 this._promptElement.id = "console-prompt"; | 105 this._promptElement.id = "console-prompt"; |
106 this._promptElement.spellcheck = false; | 106 this._promptElement.addEventListener("input", this._promptInput.bind(this), false); |
107 | |
108 this._searchableView.setDefaultFocusedElement(this._promptElement); | |
109 | 107 |
110 // FIXME: This is a workaround for the selection machinery bug. See crbug.co m/410899 | 108 // FIXME: This is a workaround for the selection machinery bug. See crbug.co m/410899 |
111 var selectAllFixer = this._messagesElement.createChild("div", "console-view- fix-select-all"); | 109 var selectAllFixer = this._messagesElement.createChild("div", "console-view- fix-select-all"); |
112 selectAllFixer.textContent = "."; | 110 selectAllFixer.textContent = "."; |
113 | 111 |
114 this._showAllMessagesCheckbox = new WebInspector.ToolbarCheckbox(WebInspecto r.UIString("Show all messages")); | 112 this._showAllMessagesCheckbox = new WebInspector.ToolbarCheckbox(WebInspecto r.UIString("Show all messages")); |
115 this._showAllMessagesCheckbox.inputElement.checked = true; | 113 this._showAllMessagesCheckbox.inputElement.checked = true; |
116 this._showAllMessagesCheckbox.inputElement.addEventListener("change", this._ updateMessageList.bind(this), false); | 114 this._showAllMessagesCheckbox.inputElement.addEventListener("change", this._ updateMessageList.bind(this), false); |
117 | 115 |
118 this._showAllMessagesCheckbox.element.classList.add("hidden"); | 116 this._showAllMessagesCheckbox.element.classList.add("hidden"); |
119 | 117 |
120 toolbar.appendToolbarItem(this._showAllMessagesCheckbox); | 118 toolbar.appendToolbarItem(this._showAllMessagesCheckbox); |
121 | 119 |
122 this._registerShortcuts(); | 120 this._registerShortcuts(); |
123 | 121 |
124 this._messagesElement.addEventListener("contextmenu", this._handleContextMen uEvent.bind(this), false); | 122 this._messagesElement.addEventListener("contextmenu", this._handleContextMen uEvent.bind(this), false); |
125 WebInspector.moduleSetting("monitoringXHREnabled").addChangeListener(this._m onitoringXHREnabledSettingChanged, this); | 123 WebInspector.moduleSetting("monitoringXHREnabled").addChangeListener(this._m onitoringXHREnabledSettingChanged, this); |
126 | 124 |
127 this._linkifier = new WebInspector.Linkifier(); | 125 this._linkifier = new WebInspector.Linkifier(); |
128 | 126 |
129 /** @type {!Array.<!WebInspector.ConsoleViewMessage>} */ | 127 /** @type {!Array.<!WebInspector.ConsoleViewMessage>} */ |
130 this._consoleMessages = []; | 128 this._consoleMessages = []; |
131 this._viewMessageSymbol = Symbol("viewMessage"); | 129 this._viewMessageSymbol = Symbol("viewMessage"); |
132 | 130 |
133 this._prompt = new WebInspector.TextPromptWithHistory(WebInspector.Execution ContextSelector.completionsForTextPromptInCurrentContext); | |
134 this._prompt.setSuggestBoxEnabled(true); | |
135 this._prompt.setAutocompletionTimeout(0); | |
136 this._prompt.renderAsBlock(); | |
137 var proxyElement = this._prompt.attach(this._promptElement); | |
138 proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this), fal se); | |
139 proxyElement.addEventListener("input", this._promptInput.bind(this), false); | |
140 | 131 |
141 this._consoleHistorySetting = WebInspector.settings.createLocalSetting("cons oleHistory", []); | 132 this._consoleHistorySetting = WebInspector.settings.createLocalSetting("cons oleHistory", []); |
142 var historyData = this._consoleHistorySetting.get(); | 133 |
143 this._prompt.history().setHistoryData(historyData); | 134 this._prompt = new WebInspector.ConsolePrompt(); |
135 this._prompt.show(this._promptElement); | |
136 this._prompt.element.addEventListener("keydown", this._promptKeyDown.bind(th is), true); | |
137 // this._searchableView.setDefaultFocusedElement(this._prompt.element); | |
dgozman
2016/09/14 04:26:18
Commented code.
einbinder
2016/09/14 20:21:06
Done.
| |
138 | |
144 | 139 |
145 this._consoleHistoryAutocompleteSetting = WebInspector.moduleSetting("consol eHistoryAutocomplete"); | 140 this._consoleHistoryAutocompleteSetting = WebInspector.moduleSetting("consol eHistoryAutocomplete"); |
146 this._consoleHistoryAutocompleteSetting.addChangeListener(this._consoleHisto ryAutocompleteChanged, this); | 141 this._consoleHistoryAutocompleteSetting.addChangeListener(this._consoleHisto ryAutocompleteChanged, this); |
142 | |
143 var historyData = this._consoleHistorySetting.get(); | |
144 this._prompt.history().setHistoryData(historyData); | |
147 this._consoleHistoryAutocompleteChanged(); | 145 this._consoleHistoryAutocompleteChanged(); |
148 | 146 |
149 this._updateFilterStatus(); | 147 this._updateFilterStatus(); |
150 WebInspector.moduleSetting("consoleTimestampsEnabled").addChangeListener(thi s._consoleTimestampsSettingChanged, this); | 148 WebInspector.moduleSetting("consoleTimestampsEnabled").addChangeListener(thi s._consoleTimestampsSettingChanged, this); |
151 | 149 |
152 this._registerWithMessageSink(); | 150 this._registerWithMessageSink(); |
153 WebInspector.targetManager.observeTargets(this); | 151 WebInspector.targetManager.observeTargets(this); |
154 | 152 |
155 this._initConsoleMessages(); | 153 this._initConsoleMessages(); |
156 | 154 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 this._fetchMultitargetMessages(); | 206 this._fetchMultitargetMessages(); |
209 }, | 207 }, |
210 | 208 |
211 _fetchMultitargetMessages: function() | 209 _fetchMultitargetMessages: function() |
212 { | 210 { |
213 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso leModel.Events.ConsoleCleared, this._consoleCleared, this); | 211 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso leModel.Events.ConsoleCleared, this._consoleCleared, this); |
214 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso leModel.Events.MessageAdded, this._onConsoleMessageAdded, this); | 212 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso leModel.Events.MessageAdded, this._onConsoleMessageAdded, this); |
215 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso leModel.Events.MessageUpdated, this._onConsoleMessageUpdated, this); | 213 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso leModel.Events.MessageUpdated, this._onConsoleMessageUpdated, this); |
216 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso leModel.Events.CommandEvaluated, this._commandEvaluated, this); | 214 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso leModel.Events.CommandEvaluated, this._commandEvaluated, this); |
217 WebInspector.multitargetConsoleModel.messages().forEach(this._addConsole Message, this); | 215 WebInspector.multitargetConsoleModel.messages().forEach(this._addConsole Message, this); |
216 this._viewport.invalidate(); | |
218 }, | 217 }, |
219 | 218 |
220 /** | 219 /** |
221 * @override | 220 * @override |
222 * @return {number} | 221 * @return {number} |
223 */ | 222 */ |
224 itemCount: function() | 223 itemCount: function() |
225 { | 224 { |
226 return this._visibleViewMessages.length; | 225 return this._visibleViewMessages.length; |
227 }, | 226 }, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 }, | 328 }, |
330 | 329 |
331 willHide: function() | 330 willHide: function() |
332 { | 331 { |
333 this._hidePromptSuggestBox(); | 332 this._hidePromptSuggestBox(); |
334 }, | 333 }, |
335 | 334 |
336 wasShown: function() | 335 wasShown: function() |
337 { | 336 { |
338 this._viewport.refresh(); | 337 this._viewport.refresh(); |
339 if (!this._prompt.isCaretInsidePrompt()) | 338 this.focus(); |
dgozman
2016/09/14 04:26:18
Why this? I think the code which shows ConsoleView
einbinder
2016/09/14 20:21:06
The old code focused the prompt. I agree that its
| |
340 this._prompt.moveCaretToEndOfPrompt(); | |
341 }, | 339 }, |
342 | 340 |
343 focus: function() | 341 focus: function() |
344 { | 342 { |
345 if (this._promptElement === WebInspector.currentFocusElement()) | 343 if (this._prompt.hasFocus()) |
346 return; | 344 return; |
347 // Set caret position before setting focus in order to avoid scrolling | 345 // Set caret position before setting focus in order to avoid scrolling |
348 // by focus(). | 346 // by focus(). |
349 this._prompt.moveCaretToEndOfPrompt(); | 347 this._prompt.moveCaretToEndOfPrompt(); |
350 WebInspector.setCurrentFocusElement(this._promptElement); | 348 this._prompt.focus(); |
351 }, | 349 }, |
352 | 350 |
353 restoreScrollPositions: function() | 351 restoreScrollPositions: function() |
354 { | 352 { |
355 if (this._viewport.stickToBottom()) | 353 if (this._viewport.stickToBottom()) |
356 this._immediatelyScrollToBottom(); | 354 this._immediatelyScrollToBottom(); |
357 else | 355 else |
358 WebInspector.Widget.prototype.restoreScrollPositions.call(this); | 356 WebInspector.Widget.prototype.restoreScrollPositions.call(this); |
359 }, | 357 }, |
360 | 358 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
550 return new WebInspector.ConsoleViewMessage(message, this._linkifier, nestingLevel); | 548 return new WebInspector.ConsoleViewMessage(message, this._linkifier, nestingLevel); |
551 } | 549 } |
552 }, | 550 }, |
553 | 551 |
554 _consoleCleared: function() | 552 _consoleCleared: function() |
555 { | 553 { |
556 this._currentMatchRangeIndex = -1; | 554 this._currentMatchRangeIndex = -1; |
557 this._consoleMessages = []; | 555 this._consoleMessages = []; |
558 this._updateMessageList(); | 556 this._updateMessageList(); |
559 this._hidePromptSuggestBox(); | 557 this._hidePromptSuggestBox(); |
558 this._viewport.setStickToBottom(true); | |
560 this._linkifier.reset(); | 559 this._linkifier.reset(); |
561 }, | 560 }, |
562 | 561 |
563 _handleContextMenuEvent: function(event) | 562 _handleContextMenuEvent: function(event) |
564 { | 563 { |
565 if (event.target.enclosingNodeOrSelfWithNodeName("a")) | 564 if (event.target.enclosingNodeOrSelfWithNodeName("a")) |
566 return; | 565 return; |
567 | 566 |
568 var contextMenu = new WebInspector.ContextMenu(event); | 567 var contextMenu = new WebInspector.ContextMenu(event); |
569 if (event.target.isSelfOrDescendant(this._promptElement)) { | 568 if (event.target.isSelfOrDescendant(this._promptElement)) { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
709 var enabled = /** @type {boolean} */ (event.data); | 708 var enabled = /** @type {boolean} */ (event.data); |
710 WebInspector.targetManager.targets().forEach(function(target) {target.ne tworkAgent().setMonitoringXHREnabled(enabled);}); | 709 WebInspector.targetManager.targets().forEach(function(target) {target.ne tworkAgent().setMonitoringXHREnabled(enabled);}); |
711 }, | 710 }, |
712 | 711 |
713 /** | 712 /** |
714 * @param {!Event} event | 713 * @param {!Event} event |
715 */ | 714 */ |
716 _messagesClicked: function(event) | 715 _messagesClicked: function(event) |
717 { | 716 { |
718 var targetElement = event.deepElementFromPoint(); | 717 var targetElement = event.deepElementFromPoint(); |
719 if (!this._prompt.isCaretInsidePrompt() && (!targetElement || targetElem ent.isComponentSelectionCollapsed())) | 718 if (!targetElement || targetElement.isComponentSelectionCollapsed()) |
720 this._prompt.moveCaretToEndOfPrompt(); | 719 this.focus(); |
721 var groupMessage = event.target.enclosingNodeOrSelfWithClass("console-gr oup-title"); | 720 var groupMessage = event.target.enclosingNodeOrSelfWithClass("console-gr oup-title"); |
722 if (!groupMessage) | 721 if (!groupMessage) |
723 return; | 722 return; |
724 var consoleGroupViewMessage = groupMessage.parentElement.message; | 723 var consoleGroupViewMessage = groupMessage.parentElement.message; |
725 consoleGroupViewMessage.setCollapsed(!consoleGroupViewMessage.collapsed( )); | 724 consoleGroupViewMessage.setCollapsed(!consoleGroupViewMessage.collapsed( )); |
726 this._updateMessageList(); | 725 this._updateMessageList(); |
727 }, | 726 }, |
728 | 727 |
729 _registerShortcuts: function() | 728 _registerShortcuts: function() |
730 { | 729 { |
(...skipping 29 matching lines...) Expand all Loading... | |
760 shortcut.makeDescriptor("P", shortcut.Modifiers.Alt) | 759 shortcut.makeDescriptor("P", shortcut.Modifiers.Alt) |
761 ]; | 760 ]; |
762 section.addRelatedKeys(keys, WebInspector.UIString("Next/previous co mmand")); | 761 section.addRelatedKeys(keys, WebInspector.UIString("Next/previous co mmand")); |
763 } | 762 } |
764 | 763 |
765 section.addKey(shortcut.makeDescriptor(shortcut.Keys.Enter), WebInspecto r.UIString("Execute command")); | 764 section.addKey(shortcut.makeDescriptor(shortcut.Keys.Enter), WebInspecto r.UIString("Execute command")); |
766 }, | 765 }, |
767 | 766 |
768 _clearPromptBackwards: function() | 767 _clearPromptBackwards: function() |
769 { | 768 { |
770 this._prompt.setText(""); | 769 if (this._prompt) |
lushnikov
2016/09/14 01:11:21
how could there be no prompt?
einbinder
2016/09/14 20:21:06
Got lost in a merge.
| |
770 this._prompt.setText(""); | |
771 }, | 771 }, |
772 | 772 |
773 /** | |
774 * @param {!Event} event | |
775 */ | |
773 _promptKeyDown: function(event) | 776 _promptKeyDown: function(event) |
774 { | 777 { |
775 if (event.key === "PageUp") { | 778 var keyboardEvent = /** @type {!KeyboardEvent} */ (event); |
779 if (keyboardEvent.key === "PageUp") { | |
776 this._updateStickToBottomOnWheel(); | 780 this._updateStickToBottomOnWheel(); |
777 return; | 781 return; |
778 } else if (isEnterKey(event)) { | 782 } else if (isEnterKey(keyboardEvent)) { |
779 this._enterKeyPressed(event); | 783 this._enterKeyPressed(keyboardEvent); |
780 return; | 784 return; |
781 } | 785 } |
782 | 786 |
783 var shortcut = WebInspector.KeyboardShortcut.makeKeyFromEvent(event); | 787 var shortcut = WebInspector.KeyboardShortcut.makeKeyFromEvent(keyboardEv ent); |
784 var handler = this._shortcuts[shortcut]; | 788 var handler = this._shortcuts[shortcut]; |
785 if (handler) { | 789 if (handler) { |
786 handler(); | 790 handler(); |
787 event.preventDefault(); | 791 keyboardEvent.preventDefault(); |
788 } | 792 } |
789 }, | 793 }, |
790 | 794 |
791 _enterKeyPressed: function(event) | 795 _enterKeyPressed: function(event) |
792 { | 796 { |
793 if (event.altKey || event.ctrlKey || event.shiftKey) | 797 if (!this._prompt || event.altKey || event.ctrlKey || event.shiftKey || !this._prompt.hasFocus()) |
dgozman
2016/09/14 04:26:18
prompt is always there.
einbinder
2016/09/14 20:21:06
Done.
| |
794 return; | 798 return; |
795 | 799 |
796 event.consume(true); | 800 event.consume(true); |
797 | 801 |
798 this._prompt.clearAutocomplete(); | 802 this._prompt.clearAutocomplete(); |
799 | 803 |
800 var str = this._prompt.text(); | 804 var str = this._prompt.text(); |
801 if (!str.length) | 805 if (!str.length) |
802 return; | 806 return; |
803 this._appendCommand(str, true); | 807 this._appendCommand(str, true); |
(...skipping 18 matching lines...) Expand all Loading... | |
822 message.setOriginatingMessage(originatingConsoleMessage); | 826 message.setOriginatingMessage(originatingConsoleMessage); |
823 result.target().consoleModel.addMessage(message); | 827 result.target().consoleModel.addMessage(message); |
824 }, | 828 }, |
825 | 829 |
826 /** | 830 /** |
827 * @param {string} text | 831 * @param {string} text |
828 * @param {boolean} useCommandLineAPI | 832 * @param {boolean} useCommandLineAPI |
829 */ | 833 */ |
830 _appendCommand: function(text, useCommandLineAPI) | 834 _appendCommand: function(text, useCommandLineAPI) |
831 { | 835 { |
832 this._prompt.setText(""); | 836 if (this._prompt) |
dgozman
2016/09/14 04:26:18
ditto
einbinder
2016/09/14 20:21:06
Done.
| |
837 this._prompt.setText(""); | |
833 var currentExecutionContext = WebInspector.context.flavor(WebInspector.E xecutionContext); | 838 var currentExecutionContext = WebInspector.context.flavor(WebInspector.E xecutionContext); |
834 if (currentExecutionContext) { | 839 if (currentExecutionContext) { |
835 WebInspector.ConsoleModel.evaluateCommandInConsole(currentExecutionC ontext, text, useCommandLineAPI); | 840 WebInspector.ConsoleModel.evaluateCommandInConsole(currentExecutionC ontext, text, useCommandLineAPI); |
836 if (WebInspector.inspectorView.currentPanel() && WebInspector.inspec torView.currentPanel().name === "console") | 841 if (WebInspector.inspectorView.currentPanel() && WebInspector.inspec torView.currentPanel().name === "console") |
837 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Ac tion.CommandEvaluatedInConsolePanel); | 842 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Ac tion.CommandEvaluatedInConsolePanel); |
838 } | 843 } |
839 }, | 844 }, |
840 | 845 |
841 /** | 846 /** |
842 * @param {!WebInspector.Event} event | 847 * @param {!WebInspector.Event} event |
843 */ | 848 */ |
844 _commandEvaluated: function(event) | 849 _commandEvaluated: function(event) |
845 { | 850 { |
851 if (!this._prompt) | |
dgozman
2016/09/14 04:26:18
ditto
einbinder
2016/09/14 20:21:06
Done.
| |
852 return; | |
846 var data = /** @type {{result: ?WebInspector.RemoteObject, text: string, commandMessage: !WebInspector.ConsoleMessage, exceptionDetails: (!RuntimeAgent. ExceptionDetails|undefined)}} */ (event.data); | 853 var data = /** @type {{result: ?WebInspector.RemoteObject, text: string, commandMessage: !WebInspector.ConsoleMessage, exceptionDetails: (!RuntimeAgent. ExceptionDetails|undefined)}} */ (event.data); |
847 this._prompt.history().pushHistoryItem(data.text); | 854 this._prompt.history().pushHistoryItem(data.text); |
848 this._consoleHistorySetting.set(this._prompt.history().historyData().sli ce(-WebInspector.ConsoleView.persistedHistorySize)); | 855 this._consoleHistorySetting.set(this._prompt.history().historyData().sli ce(-WebInspector.ConsoleView.persistedHistorySize)); |
849 this._printResult(data.result, data.commandMessage, data.exceptionDetail s); | 856 this._printResult(data.result, data.commandMessage, data.exceptionDetail s); |
850 }, | 857 }, |
851 | 858 |
852 /** | 859 /** |
853 * @override | 860 * @override |
854 * @return {!Array.<!Element>} | 861 * @return {!Array.<!Element>} |
855 */ | 862 */ |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1415 return true; | 1422 return true; |
1416 } | 1423 } |
1417 return false; | 1424 return false; |
1418 } | 1425 } |
1419 } | 1426 } |
1420 | 1427 |
1421 /** | 1428 /** |
1422 * @typedef {{messageIndex: number, matchIndex: number}} | 1429 * @typedef {{messageIndex: number, matchIndex: number}} |
1423 */ | 1430 */ |
1424 WebInspector.ConsoleView.RegexMatchRange; | 1431 WebInspector.ConsoleView.RegexMatchRange; |
OLD | NEW |