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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/console/ConsoleView.js

Issue 2331053002: DevTools: Implement the console prompt with CodeMirror (Closed)
Patch Set: Fix browser tests Created 4 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
OLDNEW
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
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); 131 this._consoleHistorySetting = WebInspector.settings.createLocalSetting("cons oleHistory", []);
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 132
141 this._consoleHistorySetting = WebInspector.settings.createLocalSetting("cons oleHistory", []); 133 this._prompt = new WebInspector.ConsolePrompt();
142 var historyData = this._consoleHistorySetting.get(); 134 this._prompt.show(this._promptElement);
143 this._prompt.history().setHistoryData(historyData); 135 this._prompt.element.addEventListener("keydown", this._promptKeyDown.bind(th is), true);
144 136
145 this._consoleHistoryAutocompleteSetting = WebInspector.moduleSetting("consol eHistoryAutocomplete"); 137 this._consoleHistoryAutocompleteSetting = WebInspector.moduleSetting("consol eHistoryAutocomplete");
146 this._consoleHistoryAutocompleteSetting.addChangeListener(this._consoleHisto ryAutocompleteChanged, this); 138 this._consoleHistoryAutocompleteSetting.addChangeListener(this._consoleHisto ryAutocompleteChanged, this);
139
140 var historyData = this._consoleHistorySetting.get();
141 this._prompt.history().setHistoryData(historyData);
147 this._consoleHistoryAutocompleteChanged(); 142 this._consoleHistoryAutocompleteChanged();
148 143
149 this._updateFilterStatus(); 144 this._updateFilterStatus();
150 WebInspector.moduleSetting("consoleTimestampsEnabled").addChangeListener(thi s._consoleTimestampsSettingChanged, this); 145 WebInspector.moduleSetting("consoleTimestampsEnabled").addChangeListener(thi s._consoleTimestampsSettingChanged, this);
151 146
152 this._registerWithMessageSink(); 147 this._registerWithMessageSink();
153 WebInspector.targetManager.observeTargets(this); 148 WebInspector.targetManager.observeTargets(this);
154 149
155 this._initConsoleMessages(); 150 this._initConsoleMessages();
156 151
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 this._fetchMultitargetMessages(); 203 this._fetchMultitargetMessages();
209 }, 204 },
210 205
211 _fetchMultitargetMessages: function() 206 _fetchMultitargetMessages: function()
212 { 207 {
213 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso leModel.Events.ConsoleCleared, this._consoleCleared, this); 208 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso leModel.Events.ConsoleCleared, this._consoleCleared, this);
214 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso leModel.Events.MessageAdded, this._onConsoleMessageAdded, this); 209 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso leModel.Events.MessageAdded, this._onConsoleMessageAdded, this);
215 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso leModel.Events.MessageUpdated, this._onConsoleMessageUpdated, this); 210 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso leModel.Events.MessageUpdated, this._onConsoleMessageUpdated, this);
216 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso leModel.Events.CommandEvaluated, this._commandEvaluated, this); 211 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso leModel.Events.CommandEvaluated, this._commandEvaluated, this);
217 WebInspector.multitargetConsoleModel.messages().forEach(this._addConsole Message, this); 212 WebInspector.multitargetConsoleModel.messages().forEach(this._addConsole Message, this);
213 this._viewport.invalidate();
218 }, 214 },
219 215
220 /** 216 /**
221 * @override 217 * @override
222 * @return {number} 218 * @return {number}
223 */ 219 */
224 itemCount: function() 220 itemCount: function()
225 { 221 {
226 return this._visibleViewMessages.length; 222 return this._visibleViewMessages.length;
227 }, 223 },
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 }, 325 },
330 326
331 willHide: function() 327 willHide: function()
332 { 328 {
333 this._hidePromptSuggestBox(); 329 this._hidePromptSuggestBox();
334 }, 330 },
335 331
336 wasShown: function() 332 wasShown: function()
337 { 333 {
338 this._viewport.refresh(); 334 this._viewport.refresh();
339 if (!this._prompt.isCaretInsidePrompt()) 335 this.focus();
340 this._prompt.moveCaretToEndOfPrompt();
341 }, 336 },
342 337
343 focus: function() 338 focus: function()
344 { 339 {
345 if (this._promptElement === WebInspector.currentFocusElement()) 340 if (this._prompt.hasFocus())
346 return; 341 return;
347 // Set caret position before setting focus in order to avoid scrolling 342 // Set caret position before setting focus in order to avoid scrolling
348 // by focus(). 343 // by focus().
349 this._prompt.moveCaretToEndOfPrompt(); 344 this._prompt.moveCaretToEndOfPrompt();
350 WebInspector.setCurrentFocusElement(this._promptElement); 345 this._prompt.focus();
351 }, 346 },
352 347
353 restoreScrollPositions: function() 348 restoreScrollPositions: function()
354 { 349 {
355 if (this._viewport.stickToBottom()) 350 if (this._viewport.stickToBottom())
356 this._immediatelyScrollToBottom(); 351 this._immediatelyScrollToBottom();
357 else 352 else
358 WebInspector.Widget.prototype.restoreScrollPositions.call(this); 353 WebInspector.Widget.prototype.restoreScrollPositions.call(this);
359 }, 354 },
360 355
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 return new WebInspector.ConsoleViewMessage(message, this._linkifier, nestingLevel); 545 return new WebInspector.ConsoleViewMessage(message, this._linkifier, nestingLevel);
551 } 546 }
552 }, 547 },
553 548
554 _consoleCleared: function() 549 _consoleCleared: function()
555 { 550 {
556 this._currentMatchRangeIndex = -1; 551 this._currentMatchRangeIndex = -1;
557 this._consoleMessages = []; 552 this._consoleMessages = [];
558 this._updateMessageList(); 553 this._updateMessageList();
559 this._hidePromptSuggestBox(); 554 this._hidePromptSuggestBox();
555 this._viewport.setStickToBottom(true);
560 this._linkifier.reset(); 556 this._linkifier.reset();
561 }, 557 },
562 558
563 _handleContextMenuEvent: function(event) 559 _handleContextMenuEvent: function(event)
564 { 560 {
565 if (event.target.enclosingNodeOrSelfWithNodeName("a")) 561 if (event.target.enclosingNodeOrSelfWithNodeName("a"))
566 return; 562 return;
567 563
568 var contextMenu = new WebInspector.ContextMenu(event); 564 var contextMenu = new WebInspector.ContextMenu(event);
569 if (event.target.isSelfOrDescendant(this._promptElement)) { 565 if (event.target.isSelfOrDescendant(this._promptElement)) {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 var enabled = /** @type {boolean} */ (event.data); 705 var enabled = /** @type {boolean} */ (event.data);
710 WebInspector.targetManager.targets().forEach(function(target) {target.ne tworkAgent().setMonitoringXHREnabled(enabled);}); 706 WebInspector.targetManager.targets().forEach(function(target) {target.ne tworkAgent().setMonitoringXHREnabled(enabled);});
711 }, 707 },
712 708
713 /** 709 /**
714 * @param {!Event} event 710 * @param {!Event} event
715 */ 711 */
716 _messagesClicked: function(event) 712 _messagesClicked: function(event)
717 { 713 {
718 var targetElement = event.deepElementFromPoint(); 714 var targetElement = event.deepElementFromPoint();
719 if (!this._prompt.isCaretInsidePrompt() && (!targetElement || targetElem ent.isComponentSelectionCollapsed())) 715 if (!targetElement || targetElement.isComponentSelectionCollapsed())
720 this._prompt.moveCaretToEndOfPrompt(); 716 this.focus();
721 var groupMessage = event.target.enclosingNodeOrSelfWithClass("console-gr oup-title"); 717 var groupMessage = event.target.enclosingNodeOrSelfWithClass("console-gr oup-title");
722 if (!groupMessage) 718 if (!groupMessage)
723 return; 719 return;
724 var consoleGroupViewMessage = groupMessage.parentElement.message; 720 var consoleGroupViewMessage = groupMessage.parentElement.message;
725 consoleGroupViewMessage.setCollapsed(!consoleGroupViewMessage.collapsed( )); 721 consoleGroupViewMessage.setCollapsed(!consoleGroupViewMessage.collapsed( ));
726 this._updateMessageList(); 722 this._updateMessageList();
727 }, 723 },
728 724
729 _registerShortcuts: function() 725 _registerShortcuts: function()
730 { 726 {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 } 759 }
764 760
765 section.addKey(shortcut.makeDescriptor(shortcut.Keys.Enter), WebInspecto r.UIString("Execute command")); 761 section.addKey(shortcut.makeDescriptor(shortcut.Keys.Enter), WebInspecto r.UIString("Execute command"));
766 }, 762 },
767 763
768 _clearPromptBackwards: function() 764 _clearPromptBackwards: function()
769 { 765 {
770 this._prompt.setText(""); 766 this._prompt.setText("");
771 }, 767 },
772 768
769 /**
770 * @param {!Event} event
771 */
773 _promptKeyDown: function(event) 772 _promptKeyDown: function(event)
774 { 773 {
775 if (event.key === "PageUp") { 774 var keyboardEvent = /** @type {!KeyboardEvent} */ (event);
775 if (keyboardEvent.key === "PageUp") {
776 this._updateStickToBottomOnWheel(); 776 this._updateStickToBottomOnWheel();
777 return; 777 return;
778 } else if (isEnterKey(event)) { 778 } else if (isEnterKey(keyboardEvent)) {
779 this._enterKeyPressed(event); 779 this._enterKeyPressed(keyboardEvent);
780 return; 780 return;
781 } 781 }
782 782
783 var shortcut = WebInspector.KeyboardShortcut.makeKeyFromEvent(event); 783 var shortcut = WebInspector.KeyboardShortcut.makeKeyFromEvent(keyboardEv ent);
784 var handler = this._shortcuts[shortcut]; 784 var handler = this._shortcuts[shortcut];
785 if (handler) { 785 if (handler) {
786 handler(); 786 handler();
787 event.preventDefault(); 787 keyboardEvent.preventDefault();
788 } 788 }
789 }, 789 },
790 790
791 _enterKeyPressed: function(event) 791 _enterKeyPressed: function(event)
792 { 792 {
793 if (event.altKey || event.ctrlKey || event.shiftKey) 793 if (event.altKey || event.ctrlKey || event.shiftKey)
794 return; 794 return;
795 795
796 event.consume(true); 796 event.consume(true);
797 797
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 return true; 1415 return true;
1416 } 1416 }
1417 return false; 1417 return false;
1418 } 1418 }
1419 } 1419 }
1420 1420
1421 /** 1421 /**
1422 * @typedef {{messageIndex: number, matchIndex: number}} 1422 * @typedef {{messageIndex: number, matchIndex: number}}
1423 */ 1423 */
1424 WebInspector.ConsoleView.RegexMatchRange; 1424 WebInspector.ConsoleView.RegexMatchRange;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698