mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-05 20:44:30 +08:00
Fixes (#62)
* 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:
parent
9fed524ed5
commit
d2cd541ce1
3 changed files with 42 additions and 22 deletions
|
@ -53,7 +53,7 @@ const Session = {
|
||||||
this.pushEvent("delete_focused_cell", {});
|
this.pushEvent("delete_focused_cell", {});
|
||||||
} else if (
|
} else if (
|
||||||
this.props.focusedCellType === "elixir" &&
|
this.props.focusedCellType === "elixir" &&
|
||||||
keyBuffer.tryMatch(["e", "e"])
|
(keyBuffer.tryMatch(["e", "e"]) || (cmd && key === "Enter"))
|
||||||
) {
|
) {
|
||||||
this.pushEvent("queue_focused_cell_evaluation", {});
|
this.pushEvent("queue_focused_cell_evaluation", {});
|
||||||
} else if (keyBuffer.tryMatch(["e", "s"])) {
|
} else if (keyBuffer.tryMatch(["e", "s"])) {
|
||||||
|
@ -85,7 +85,11 @@ const Session = {
|
||||||
document.addEventListener("keydown", this.handleDocumentKeydown, true);
|
document.addEventListener("keydown", this.handleDocumentKeydown, true);
|
||||||
|
|
||||||
// Focus/unfocus a cell when the user clicks somewhere
|
// 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
|
// Find the parent with cell id info, if there is one
|
||||||
const cell = event.target.closest("[data-cell-id]");
|
const cell = event.target.closest("[data-cell-id]");
|
||||||
const cellId = cell ? cell.dataset.cellId : null;
|
const cellId = cell ? cell.dataset.cellId : null;
|
||||||
|
@ -101,7 +105,7 @@ const Session = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
document.addEventListener("click", this.handleDocumentClick);
|
document.addEventListener("mousedown", this.handleDocumentMouseDown);
|
||||||
},
|
},
|
||||||
|
|
||||||
updated() {
|
updated() {
|
||||||
|
@ -110,7 +114,7 @@ const Session = {
|
||||||
|
|
||||||
destroyed() {
|
destroyed() {
|
||||||
document.removeEventListener("keydown", this.handleDocumentKeydown);
|
document.removeEventListener("keydown", this.handleDocumentKeydown);
|
||||||
document.removeEventListener("click", this.handleDocumentClick);
|
document.removeEventListener("mousedown", this.handleDocumentMouseDown);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ defmodule LiveBookWeb.HomeLive do
|
||||||
<header class="flex justify-center p-4 border-b">
|
<header class="flex justify-center p-4 border-b">
|
||||||
<h1 class="text-2xl font-medium">LiveBook</h1>
|
<h1 class="text-2xl font-medium">LiveBook</h1>
|
||||||
</header>
|
</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">
|
<div class="w-full flex justify-end">
|
||||||
<button class="button-base button-sm"
|
<button class="button-base button-sm"
|
||||||
phx-click="new">
|
phx-click="new">
|
||||||
|
|
|
@ -25,11 +25,13 @@ defmodule LiveBook.EvaluatorTest do
|
||||||
Evaluator.evaluate_code(evaluator, self(), "x = 1", :code_1)
|
Evaluator.evaluate_code(evaluator, self(), "x = 1", :code_1)
|
||||||
assert_receive {:evaluation_response, :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,
|
assert_receive {:evaluation_response, :code_2,
|
||||||
{:error, _kind, %CompileError{description: "undefined function x/0"},
|
{:error, _kind, %CompileError{description: "undefined function x/0"},
|
||||||
_stacktrace}}
|
_stacktrace}}
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "given prev_ref sees previous evaluation context", %{evaluator: evaluator} do
|
test "given prev_ref sees previous evaluation context", %{evaluator: evaluator} do
|
||||||
|
@ -91,17 +93,19 @@ defmodule LiveBook.EvaluatorTest do
|
||||||
LiveBook.EvaluatorTest.Stacktrace.Cat.meow()
|
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 = [
|
expected_stacktrace = [
|
||||||
{LiveBook.EvaluatorTest.Stacktrace.Math, :bad_math, 0, [file: 'nofile', line: 3]},
|
{LiveBook.EvaluatorTest.Stacktrace.Math, :bad_math, 0, [file: 'nofile', line: 3]},
|
||||||
{LiveBook.EvaluatorTest.Stacktrace.Cat, :meow, 0, [file: 'nofile', line: 10]}
|
{LiveBook.EvaluatorTest.Stacktrace.Cat, :meow, 0, [file: 'nofile', line: 10]}
|
||||||
]
|
]
|
||||||
|
|
||||||
# Note: evaluating module definitions is relatively slow, so we use a higher wait timeout.
|
# Note: evaluating module definitions is relatively slow, so we use a higher wait timeout.
|
||||||
assert_receive {:evaluation_response, :code_1,
|
assert_receive {:evaluation_response, :code_1,
|
||||||
{:error, _kind, _error, ^expected_stacktrace}},
|
{:error, _kind, _error, ^expected_stacktrace}},
|
||||||
1000
|
1000
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -111,11 +115,23 @@ defmodule LiveBook.EvaluatorTest do
|
||||||
assert_receive {:evaluation_response, :code_1, _}
|
assert_receive {:evaluation_response, :code_1, _}
|
||||||
|
|
||||||
Evaluator.forget_evaluation(evaluator, :code_1)
|
Evaluator.forget_evaluation(evaluator, :code_1)
|
||||||
Evaluator.evaluate_code(evaluator, self(), "x", :code_2, :code_1)
|
|
||||||
|
|
||||||
assert_receive {:evaluation_response, :code_2,
|
ignore_warnings(fn ->
|
||||||
{:error, _kind, %CompileError{description: "undefined function x/0"},
|
Evaluator.evaluate_code(evaluator, self(), "x", :code_2, :code_1)
|
||||||
_stacktrace}}
|
|
||||||
|
assert_receive {:evaluation_response, :code_2,
|
||||||
|
{:error, _kind, %CompileError{description: "undefined function x/0"},
|
||||||
|
_stacktrace}}
|
||||||
|
end)
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue