From d2cd541ce1d74b30a917879422b8997a867f5575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Fri, 26 Feb 2021 20:39:32 +0100 Subject: [PATCH] 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 --- assets/js/session/index.js | 12 ++++--- lib/live_book_web/live/home_live.ex | 2 +- test/live_book/evaluator_test.exs | 50 +++++++++++++++++++---------- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/assets/js/session/index.js b/assets/js/session/index.js index 69c8143ae..f8f47e0d7 100644 --- a/assets/js/session/index.js +++ b/assets/js/session/index.js @@ -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); }, }; diff --git a/lib/live_book_web/live/home_live.ex b/lib/live_book_web/live/home_live.ex index 5a66c1eaa..2d6b14ed0 100644 --- a/lib/live_book_web/live/home_live.ex +++ b/lib/live_book_web/live/home_live.ex @@ -20,7 +20,7 @@ defmodule LiveBookWeb.HomeLive do

LiveBook

-
+