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
This commit is contained in:
Bisola Omisore 2019-03-11 08:57:27 +00:00
Родитель 22e0450261
Коммит da94ffd2ed
7 изменённых файлов: 49 добавлений и 1 удалений

Просмотреть файл

@ -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 => ({

Просмотреть файл

@ -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;

Просмотреть файл

@ -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.

Просмотреть файл

@ -31,6 +31,7 @@ const UiState = (overrides) => Object.freeze(Object.assign({
closeButtonVisible: false,
reverseSearchInputVisible: false,
reverseSearchInitialValue: "",
editor: false,
}, overrides));
function ui(state = UiState(), action) {

Просмотреть файл

@ -71,6 +71,7 @@ function configureStore(webConsoleUI, options = {}) {
ui: UiState({
networkMessageActiveTabId: "headers",
persistLogs: getBoolPref(PREFS.UI.PERSIST),
editor: getBoolPref(PREFS.UI.EDITOR),
}),
};

Просмотреть файл

@ -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]

Просмотреть файл

@ -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");
}