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

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

Issue 2361273002: DevTools: Move "enter" logic from ConsoleView to ConsolePrompt (Closed)
Patch Set: 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 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 770
771 /** 771 /**
772 * @param {!Event} event 772 * @param {!Event} event
773 */ 773 */
774 _promptKeyDown: function(event) 774 _promptKeyDown: function(event)
775 { 775 {
776 var keyboardEvent = /** @type {!KeyboardEvent} */ (event); 776 var keyboardEvent = /** @type {!KeyboardEvent} */ (event);
777 if (keyboardEvent.key === "PageUp") { 777 if (keyboardEvent.key === "PageUp") {
778 this._updateStickToBottomOnWheel(); 778 this._updateStickToBottomOnWheel();
779 return; 779 return;
780 } else if (isEnterKey(keyboardEvent)) {
781 this._enterKeyPressed(keyboardEvent);
782 return;
783 } 780 }
784 781
785 var shortcut = WebInspector.KeyboardShortcut.makeKeyFromEvent(keyboardEv ent); 782 var shortcut = WebInspector.KeyboardShortcut.makeKeyFromEvent(keyboardEv ent);
786 var handler = this._shortcuts[shortcut]; 783 var handler = this._shortcuts[shortcut];
787 if (handler) { 784 if (handler) {
788 handler(); 785 handler();
789 keyboardEvent.preventDefault(); 786 keyboardEvent.preventDefault();
790 } 787 }
791 }, 788 },
792 789
793 _enterKeyPressed: function(event)
794 {
795 if (event.altKey || event.ctrlKey || event.shiftKey)
796 return;
797
798 event.consume(true);
799
800 this._prompt.clearAutocomplete();
801
802 var str = this._prompt.text();
803 if (!str.length)
804 return;
805
806 var target = WebInspector.targetManager.mainTarget();
807 var currentExecutionContext = WebInspector.context.flavor(WebInspector.E xecutionContext);
808 if (!this._prompt.isCaretAtEndOfPrompt() || !target || !currentExecution Context) {
809 this._appendCommand(str, true);
810 return;
811 }
812 target.runtimeModel.compileScript(str, "", false, currentExecutionContex t.id, compileCallback.bind(this));
813
814 /**
815 * @param {!RuntimeAgent.ScriptId=} scriptId
816 * @param {?RuntimeAgent.ExceptionDetails=} exceptionDetails
817 * @this {WebInspector.ConsoleView}
818 */
819 function compileCallback(scriptId, exceptionDetails)
820 {
821 if (str !== this._prompt.text())
822 return;
823 if (exceptionDetails && (exceptionDetails.exception.description === "SyntaxError: Unexpected end of input"
824 || exceptionDetails.exception.description === "SyntaxError: Unte rminated template literal")) {
825 this._prompt.newlineAndIndent();
826 return;
827 }
828 this._appendCommand(str, true);
829 }
830 },
831
832 /** 790 /**
833 * @param {?WebInspector.RemoteObject} result 791 * @param {?WebInspector.RemoteObject} result
834 * @param {!WebInspector.ConsoleMessage} originatingConsoleMessage 792 * @param {!WebInspector.ConsoleMessage} originatingConsoleMessage
835 * @param {!RuntimeAgent.ExceptionDetails=} exceptionDetails 793 * @param {!RuntimeAgent.ExceptionDetails=} exceptionDetails
836 */ 794 */
837 _printResult: function(result, originatingConsoleMessage, exceptionDetails) 795 _printResult: function(result, originatingConsoleMessage, exceptionDetails)
838 { 796 {
839 if (!result) 797 if (!result)
840 return; 798 return;
841 799
842 var level = !!exceptionDetails ? WebInspector.ConsoleMessage.MessageLeve l.Error : WebInspector.ConsoleMessage.MessageLevel.Log; 800 var level = !!exceptionDetails ? WebInspector.ConsoleMessage.MessageLeve l.Error : WebInspector.ConsoleMessage.MessageLevel.Log;
843 var message; 801 var message;
844 if (!exceptionDetails) 802 if (!exceptionDetails)
845 message = new WebInspector.ConsoleMessage(result.target(), WebInspec tor.ConsoleMessage.MessageSource.JS, level, "", WebInspector.ConsoleMessage.Mess ageType.Result, undefined, undefined, undefined, undefined, [result]); 803 message = new WebInspector.ConsoleMessage(result.target(), WebInspec tor.ConsoleMessage.MessageSource.JS, level, "", WebInspector.ConsoleMessage.Mess ageType.Result, undefined, undefined, undefined, undefined, [result]);
846 else 804 else
847 message = WebInspector.ConsoleMessage.fromException(result.target(), exceptionDetails, WebInspector.ConsoleMessage.MessageType.Result, undefined, un defined); 805 message = WebInspector.ConsoleMessage.fromException(result.target(), exceptionDetails, WebInspector.ConsoleMessage.MessageType.Result, undefined, un defined);
848 message.setOriginatingMessage(originatingConsoleMessage); 806 message.setOriginatingMessage(originatingConsoleMessage);
849 result.target().consoleModel.addMessage(message); 807 result.target().consoleModel.addMessage(message);
850 }, 808 },
851 809
852 /** 810 /**
853 * @param {string} text
854 * @param {boolean} useCommandLineAPI
855 */
856 _appendCommand: function(text, useCommandLineAPI)
857 {
858 this._prompt.setText("");
859 var currentExecutionContext = WebInspector.context.flavor(WebInspector.E xecutionContext);
860 if (currentExecutionContext) {
861 WebInspector.ConsoleModel.evaluateCommandInConsole(currentExecutionC ontext, text, useCommandLineAPI);
862 if (WebInspector.inspectorView.currentPanel() && WebInspector.inspec torView.currentPanel().name === "console")
863 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Ac tion.CommandEvaluatedInConsolePanel);
864 }
865 },
866
867 /**
868 * @param {!WebInspector.Event} event 811 * @param {!WebInspector.Event} event
869 */ 812 */
870 _commandEvaluated: function(event) 813 _commandEvaluated: function(event)
871 { 814 {
872 var data = /** @type {{result: ?WebInspector.RemoteObject, text: string, commandMessage: !WebInspector.ConsoleMessage, exceptionDetails: (!RuntimeAgent. ExceptionDetails|undefined)}} */ (event.data); 815 var data = /** @type {{result: ?WebInspector.RemoteObject, text: string, commandMessage: !WebInspector.ConsoleMessage, exceptionDetails: (!RuntimeAgent. ExceptionDetails|undefined)}} */ (event.data);
873 this._prompt.history().pushHistoryItem(data.text); 816 this._prompt.history().pushHistoryItem(data.text);
874 this._consoleHistorySetting.set(this._prompt.history().historyData().sli ce(-WebInspector.ConsoleView.persistedHistorySize)); 817 this._consoleHistorySetting.set(this._prompt.history().historyData().sli ce(-WebInspector.ConsoleView.persistedHistorySize));
875 this._printResult(data.result, data.commandMessage, data.exceptionDetail s); 818 this._printResult(data.result, data.commandMessage, data.exceptionDetail s);
876 }, 819 },
877 820
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 return true; 1384 return true;
1442 } 1385 }
1443 return false; 1386 return false;
1444 } 1387 }
1445 } 1388 }
1446 1389
1447 /** 1390 /**
1448 * @typedef {{messageIndex: number, matchIndex: number}} 1391 * @typedef {{messageIndex: number, matchIndex: number}}
1449 */ 1392 */
1450 WebInspector.ConsoleView.RegexMatchRange; 1393 WebInspector.ConsoleView.RegexMatchRange;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698