From da94ffd2ed74eddc218e225a35c886fb7b4a453a Mon Sep 17 00:00:00 2001 From: Bisola Omisore Date: Mon, 11 Mar 2019 08:57:27 +0000 Subject: [PATCH] Bug 1519313 - Do not clear the console input when evaluating and 'devtools.webconsole.input.editor' is true. r=nchevobbe Create an `editorMode` prop that is initialized with the preference value, and passed to the JSTerm component. The prop is then used to check if the input should be cleared when an evaluation is done. A test is added to ensure this works as expected. Differential Revision: https://phabricator.services.mozilla.com/D22171 --HG-- extra : moz-landing-system : lando --- devtools/client/webconsole/components/App.js | 7 +++++ .../client/webconsole/components/JSTerm.js | 8 ++++- devtools/client/webconsole/constants.js | 2 ++ devtools/client/webconsole/reducers/ui.js | 1 + devtools/client/webconsole/store.js | 1 + .../webconsole/test/mochitest/browser.ini | 1 + .../browser_jsterm_editor_execute.js | 30 +++++++++++++++++++ 7 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 devtools/client/webconsole/test/mochitest/browser_jsterm_editor_execute.js diff --git a/devtools/client/webconsole/components/App.js b/devtools/client/webconsole/components/App.js index 17f876570202..cb11e4971df6 100644 --- a/devtools/client/webconsole/components/App.js +++ b/devtools/client/webconsole/components/App.js @@ -50,6 +50,7 @@ class App extends Component { currentReverseSearchEntry: PropTypes.string, reverseSearchInputVisible: PropTypes.bool, reverseSearchInitialValue: PropTypes.string, + editorMode: PropTypes.bool, }; } @@ -200,12 +201,16 @@ class App extends Component { closeSplitConsole, jstermCodeMirror, reverseSearchInitialValue, + editorMode, } = this.props; const classNames = ["webconsole-app"]; if (jstermCodeMirror) { classNames.push("jsterm-cm"); } + if (editorMode) { + classNames.push("jsterm-editor"); + } // Render the entire Console panel. The panel consists // from the following parts: @@ -242,6 +247,7 @@ class App extends Component { serviceContainer, onPaste: this.onPaste, codeMirrorEnabled: jstermCodeMirror, + editorMode, }), ReverseSearchInput({ setInputValue: serviceContainer.setInputValue, @@ -267,6 +273,7 @@ const mapStateToProps = state => ({ notifications: getAllNotifications(state), reverseSearchInputVisible: state.ui.reverseSearchInputVisible, reverseSearchInitialValue: state.ui.reverseSearchInitialValue, + editorMode: state.ui.editor, }); const mapDispatchToProps = dispatch => ({ diff --git a/devtools/client/webconsole/components/JSTerm.js b/devtools/client/webconsole/components/JSTerm.js index c56716ad0aa2..8a67a4cfa4e7 100644 --- a/devtools/client/webconsole/components/JSTerm.js +++ b/devtools/client/webconsole/components/JSTerm.js @@ -79,6 +79,8 @@ class JSTerm extends Component { autocompleteUpdate: PropTypes.func.isRequired, // Data to be displayed in the autocomplete popup. autocompleteData: PropTypes.object.isRequired, + // Is the input in editor mode. + editorMode: PropTypes.bool, }; } @@ -592,7 +594,11 @@ class JSTerm extends Component { this.props.appendToHistory(executeString); WebConsoleUtils.usageCount++; - this._setValue(""); + + if (!this.props.editorMode) { + this._setValue(""); + } + this.clearCompletion(); let selectedNodeActor = null; diff --git a/devtools/client/webconsole/constants.js b/devtools/client/webconsole/constants.js index 4994713d106b..6ddf5f27c189 100644 --- a/devtools/client/webconsole/constants.js +++ b/devtools/client/webconsole/constants.js @@ -65,6 +65,8 @@ const prefs = { PERSIST: "devtools.webconsole.persistlog", // Max number of entries in history list. INPUT_HISTORY_COUNT: "devtools.webconsole.inputHistoryCount", + // Is editor mode enabled. + EDITOR: "devtools.webconsole.input.editor", }, FEATURES: { // We use the same pref to enable the sidebar on webconsole and browser console. diff --git a/devtools/client/webconsole/reducers/ui.js b/devtools/client/webconsole/reducers/ui.js index 1b4055edec4a..bbe33d46ddd6 100644 --- a/devtools/client/webconsole/reducers/ui.js +++ b/devtools/client/webconsole/reducers/ui.js @@ -31,6 +31,7 @@ const UiState = (overrides) => Object.freeze(Object.assign({ closeButtonVisible: false, reverseSearchInputVisible: false, reverseSearchInitialValue: "", + editor: false, }, overrides)); function ui(state = UiState(), action) { diff --git a/devtools/client/webconsole/store.js b/devtools/client/webconsole/store.js index c643c36c7096..f5360424b65c 100644 --- a/devtools/client/webconsole/store.js +++ b/devtools/client/webconsole/store.js @@ -71,6 +71,7 @@ function configureStore(webConsoleUI, options = {}) { ui: UiState({ networkMessageActiveTabId: "headers", persistLogs: getBoolPref(PREFS.UI.PERSIST), + editor: getBoolPref(PREFS.UI.EDITOR), }), }; diff --git a/devtools/client/webconsole/test/mochitest/browser.ini b/devtools/client/webconsole/test/mochitest/browser.ini index 33a21d051cfe..7ce285788fb9 100644 --- a/devtools/client/webconsole/test/mochitest/browser.ini +++ b/devtools/client/webconsole/test/mochitest/browser.ini @@ -197,6 +197,7 @@ skip-if = verify [browser_jsterm_ctrl_key_nav.js] skip-if = os != 'mac' # The tested ctrl+key shortcuts are OSX only [browser_jsterm_document_no_xray.js] +[browser_jsterm_editor_execute.js] [browser_jsterm_error_docs.js] [browser_jsterm_error_outside_valid_range.js] [browser_jsterm_focus_reload.js] diff --git a/devtools/client/webconsole/test/mochitest/browser_jsterm_editor_execute.js b/devtools/client/webconsole/test/mochitest/browser_jsterm_editor_execute.js new file mode 100644 index 000000000000..3068892d9a16 --- /dev/null +++ b/devtools/client/webconsole/test/mochitest/browser_jsterm_editor_execute.js @@ -0,0 +1,30 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that user input is not cleared when 'devtools.webconsole.input.editor' +// is set to true. +// See https://bugzilla.mozilla.org/show_bug.cgi?id=1519313 + +"use strict"; + +const TEST_URI = "data:text/html;charset=utf-8,Web Console test for bug 1519313"; + +add_task(async function() { + await pushPref("devtools.webconsole.input.editor", true); + // Run test with legacy JsTerm + await pushPref("devtools.webconsole.jsterm.codeMirror", false); + await performTests(); + // And then run it with the CodeMirror-powered one. + await pushPref("devtools.webconsole.jsterm.codeMirror", true); + await performTests(); +}); + +async function performTests() { + const hud = await openNewTabAndConsole(TEST_URI); + const {jsterm} = hud; + + const expression = `x = 10`; + setInputValue(hud, expression); + await jsterm.execute(); + is(getInputValue(hud), expression, "input line is not cleared after submit"); +}