зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1576949 - Clicking the Editor Run button when input has text selection only evaluate selected text. r=Honza.
This is done by modifying the evaluateExpression action, where we retrieve the selection of the full input. Differential Revision: https://phabricator.services.mozilla.com/D43750 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
081ae7cb3f
Коммит
abba330463
|
@ -39,7 +39,7 @@ const HELP_URL = "https://developer.mozilla.org/docs/Tools/Web_Console/Helpers";
|
|||
function evaluateExpression(expression) {
|
||||
return async ({ dispatch, services }) => {
|
||||
if (!expression) {
|
||||
expression = services.getInputValue();
|
||||
expression = services.getInputSelection() || services.getInputValue();
|
||||
}
|
||||
if (!expression) {
|
||||
return null;
|
||||
|
|
|
@ -22,7 +22,7 @@ add_task(async function() {
|
|||
setInputValue(hud, expression);
|
||||
|
||||
let onResultMessage = waitForMessage(hud, "20", ".result");
|
||||
synthesizeEvaluation();
|
||||
synthesizeKeyboardEvaluation();
|
||||
await onResultMessage;
|
||||
ok(true, "The whole expression is evaluated when there's no selection");
|
||||
|
||||
|
@ -32,10 +32,21 @@ add_task(async function() {
|
|||
{ line: 0, ch: expression.split("\n")[0].length }
|
||||
);
|
||||
onResultMessage = waitForMessage(hud, "10", ".result");
|
||||
synthesizeEvaluation();
|
||||
synthesizeKeyboardEvaluation();
|
||||
await onResultMessage;
|
||||
ok(true, "Only the expression on the first line was evaluated");
|
||||
|
||||
info("Check that it also works when clicking on the Run button");
|
||||
onResultMessage = waitForMessage(hud, "10", ".result");
|
||||
hud.ui.outputNode
|
||||
.querySelector(".webconsole-editor-toolbar-executeButton")
|
||||
.click();
|
||||
await onResultMessage;
|
||||
ok(
|
||||
true,
|
||||
"Only the expression on the first line was evaluated when clicking the Run button"
|
||||
);
|
||||
|
||||
info("Check that this works in inline mode as well");
|
||||
await toggleLayout(hud);
|
||||
hud.ui.jsterm.editor.setSelection(
|
||||
|
@ -43,7 +54,7 @@ add_task(async function() {
|
|||
{ line: 0, ch: expression.split("\n")[0].length }
|
||||
);
|
||||
onResultMessage = waitForMessage(hud, "10", ".result");
|
||||
synthesizeEvaluation();
|
||||
synthesizeKeyboardEvaluation();
|
||||
await onResultMessage;
|
||||
ok(
|
||||
true,
|
||||
|
@ -51,7 +62,7 @@ add_task(async function() {
|
|||
);
|
||||
});
|
||||
|
||||
function synthesizeEvaluation() {
|
||||
function synthesizeKeyboardEvaluation() {
|
||||
EventUtils.synthesizeKey("KEY_Enter", {
|
||||
[Services.appinfo.OS === "Darwin" ? "metaKey" : "ctrlKey"]: true,
|
||||
});
|
||||
|
|
|
@ -206,6 +206,13 @@ class WebConsoleWrapper {
|
|||
return this.hud.getInputValue();
|
||||
},
|
||||
|
||||
getInputSelection: () => {
|
||||
if (!webConsoleUI.jsterm || !webConsoleUI.jsterm.editor) {
|
||||
return null;
|
||||
}
|
||||
return webConsoleUI.jsterm.editor.getSelection();
|
||||
},
|
||||
|
||||
setInputValue: value => {
|
||||
this.hud.setInputValue(value);
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче