* Ignore compilation warnings in the Evaluator tests

* Make Cmd + Enter evaluate cell even in navigation mode

* Fix homepage responsiveness

* Improve setting insert mode with mouse
This commit is contained in:
Jonatan Kłosko 2021-02-26 20:39:32 +01:00 committed by GitHub
parent 9fed524ed5
commit d2cd541ce1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 22 deletions

View file

@ -53,7 +53,7 @@ const Session = {
this.pushEvent("delete_focused_cell", {});
} else if (
this.props.focusedCellType === "elixir" &&
keyBuffer.tryMatch(["e", "e"])
(keyBuffer.tryMatch(["e", "e"]) || (cmd && key === "Enter"))
) {
this.pushEvent("queue_focused_cell_evaluation", {});
} else if (keyBuffer.tryMatch(["e", "s"])) {
@ -85,7 +85,11 @@ const Session = {
document.addEventListener("keydown", this.handleDocumentKeydown, true);
// Focus/unfocus a cell when the user clicks somewhere
this.handleDocumentClick = (event) => {
// Note: we use mousedown event to more reliably focus editor
// (e.g. if the user selects some text within the editor
// and mouseup happens outside the editor)
this.handleDocumentMouseDown = (event) => {
// Find the parent with cell id info, if there is one
const cell = event.target.closest("[data-cell-id]");
const cellId = cell ? cell.dataset.cellId : null;
@ -101,7 +105,7 @@ const Session = {
}
};
document.addEventListener("click", this.handleDocumentClick);
document.addEventListener("mousedown", this.handleDocumentMouseDown);
},
updated() {
@ -110,7 +114,7 @@ const Session = {
destroyed() {
document.removeEventListener("keydown", this.handleDocumentKeydown);
document.removeEventListener("click", this.handleDocumentClick);
document.removeEventListener("mousedown", this.handleDocumentMouseDown);
},
};

View file

@ -20,7 +20,7 @@ defmodule LiveBookWeb.HomeLive do
<header class="flex justify-center p-4 border-b">
<h1 class="text-2xl font-medium">LiveBook</h1>
</header>
<div class="mt-4 container max-w-4xl w-full mx-auto flex flex-col items-center space-y-4 pb-8">
<div class="container max-w-5xl w-full mx-auto p-4 pb-8 flex flex-col items-center space-y-4">
<div class="w-full flex justify-end">
<button class="button-base button-sm"
phx-click="new">

View file

@ -25,11 +25,13 @@ defmodule LiveBook.EvaluatorTest do
Evaluator.evaluate_code(evaluator, self(), "x = 1", :code_1)
assert_receive {:evaluation_response, :code_1, _}
Evaluator.evaluate_code(evaluator, self(), "x", :code_2)
ignore_warnings(fn ->
Evaluator.evaluate_code(evaluator, self(), "x", :code_2)
assert_receive {:evaluation_response, :code_2,
{:error, _kind, %CompileError{description: "undefined function x/0"},
_stacktrace}}
assert_receive {:evaluation_response, :code_2,
{:error, _kind, %CompileError{description: "undefined function x/0"},
_stacktrace}}
end)
end
test "given prev_ref sees previous evaluation context", %{evaluator: evaluator} do
@ -91,17 +93,19 @@ defmodule LiveBook.EvaluatorTest do
LiveBook.EvaluatorTest.Stacktrace.Cat.meow()
"""
Evaluator.evaluate_code(evaluator, self(), code, :code_1)
ignore_warnings(fn ->
Evaluator.evaluate_code(evaluator, self(), code, :code_1)
expected_stacktrace = [
{LiveBook.EvaluatorTest.Stacktrace.Math, :bad_math, 0, [file: 'nofile', line: 3]},
{LiveBook.EvaluatorTest.Stacktrace.Cat, :meow, 0, [file: 'nofile', line: 10]}
]
expected_stacktrace = [
{LiveBook.EvaluatorTest.Stacktrace.Math, :bad_math, 0, [file: 'nofile', line: 3]},
{LiveBook.EvaluatorTest.Stacktrace.Cat, :meow, 0, [file: 'nofile', line: 10]}
]
# Note: evaluating module definitions is relatively slow, so we use a higher wait timeout.
assert_receive {:evaluation_response, :code_1,
{:error, _kind, _error, ^expected_stacktrace}},
1000
# Note: evaluating module definitions is relatively slow, so we use a higher wait timeout.
assert_receive {:evaluation_response, :code_1,
{:error, _kind, _error, ^expected_stacktrace}},
1000
end)
end
end
@ -111,11 +115,23 @@ defmodule LiveBook.EvaluatorTest do
assert_receive {:evaluation_response, :code_1, _}
Evaluator.forget_evaluation(evaluator, :code_1)
Evaluator.evaluate_code(evaluator, self(), "x", :code_2, :code_1)
assert_receive {:evaluation_response, :code_2,
{:error, _kind, %CompileError{description: "undefined function x/0"},
_stacktrace}}
ignore_warnings(fn ->
Evaluator.evaluate_code(evaluator, self(), "x", :code_2, :code_1)
assert_receive {:evaluation_response, :code_2,
{:error, _kind, %CompileError{description: "undefined function x/0"},
_stacktrace}}
end)
end
end
# Helpers
# Some of the code passed to Evaluator above is expected
# to produce compilation warnings, so we ignore them.
defp ignore_warnings(fun) do
ExUnit.CaptureIO.capture_io(:stderr, fun)
:ok
end
end