mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-09-20 10:05:57 +08:00
Focus notebook name after creation (#122)
This commit is contained in:
parent
fdadefae32
commit
e335ecb791
|
@ -47,8 +47,6 @@ const Session = {
|
|||
handleSectionListClick(this, event);
|
||||
});
|
||||
|
||||
updateSectionListHighlight();
|
||||
|
||||
getNotebook().addEventListener("scroll", (event) => {
|
||||
updateSectionListHighlight();
|
||||
});
|
||||
|
@ -59,6 +57,11 @@ const Session = {
|
|||
toggleSectionsPanel(this);
|
||||
});
|
||||
|
||||
// DOM setup
|
||||
|
||||
updateSectionListHighlight();
|
||||
focusNotebookNameIfNew();
|
||||
|
||||
// Server events
|
||||
|
||||
this.handleEvent("cell_inserted", ({ cell_id: cellId }) => {
|
||||
|
@ -470,6 +473,16 @@ function handleSectionDeleted(hook, sectionId) {
|
|||
}
|
||||
}
|
||||
|
||||
function focusNotebookNameIfNew() {
|
||||
const sections = getSections();
|
||||
const nameElement = document.querySelector(`[data-element="notebook-name"]`);
|
||||
|
||||
if (sections.length === 0 && nameElement.innerText === "Untitled notebook") {
|
||||
nameElement.focus();
|
||||
selectElementContent(nameElement);
|
||||
}
|
||||
}
|
||||
|
||||
// Helpers
|
||||
|
||||
function nearbyCellId(cellId, offset) {
|
||||
|
|
|
@ -124,6 +124,7 @@ defmodule LivebookWeb.SessionLive do
|
|||
<div class="pb-4 mb-6 border-b border-gray-200">
|
||||
<h1 class="text-gray-800 font-semibold text-3xl p-1 -ml-1 rounded-lg border border-transparent hover:border-blue-200 focus:border-blue-300"
|
||||
id="notebook-name"
|
||||
data-element="notebook-name"
|
||||
contenteditable
|
||||
spellcheck="false"
|
||||
phx-blur="set_notebook_name"
|
||||
|
|
Loading…
Reference in a new issue