Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate inputs to Kino #714

Merged
merged 11 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions assets/js/cell/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,6 @@ const Cell = {
});
}

if (this.props.type === "input") {
const input = getInput(this);

input.addEventListener("blur", (event) => {
// Wait for other handlers to complete and if still in insert
// force focus
setTimeout(() => {
if (this.state.isFocused && this.state.insertMode) {
input.focus();
}
}, 0);
});
}

this._unsubscribeFromNavigationEvents = globalPubSub.subscribe(
"navigation",
(event) => {
Expand Down Expand Up @@ -185,14 +171,6 @@ function getProps(hook) {
};
}

function getInput(hook) {
if (hook.props.type === "input") {
return hook.el.querySelector(`[data-element="input"]`);
} else {
return null;
}
}

/**
* Handles client-side navigation event.
*/
Expand Down Expand Up @@ -231,8 +209,6 @@ function handleElementFocused(hook, focusableId, scroll) {
}

function handleInsertModeChanged(hook, insertMode) {
const input = getInput(hook);

if (hook.state.isFocused && !hook.state.insertMode && insertMode) {
hook.state.insertMode = insertMode;

Expand All @@ -255,24 +231,12 @@ function handleInsertModeChanged(hook, insertMode) {

broadcastSelection(hook);
}

if (input) {
input.focus();
// selectionStart is only supported on text based input
if (input.selectionStart !== null) {
input.selectionStart = input.selectionEnd = input.value.length;
}
}
} else if (hook.state.insertMode && !insertMode) {
hook.state.insertMode = insertMode;

if (hook.state.liveEditor) {
hook.state.liveEditor.blur();
}

if (input) {
input.blur();
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions assets/js/session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,15 @@ function handleDocumentKeyDown(hook, event) {
saveNotebook(hook);
}
} else {
// Ignore inputs and notebook/section title fields
// Ignore keystrokes on input fields
if (isEditableElement(event.target)) {
keyBuffer.reset();

// Use Escape for universal blur
if (key === "Escape") {
event.target.blur();
}

return;
}

Expand Down Expand Up @@ -429,7 +435,7 @@ function handleDocumentMouseDown(hook, event) {
function editableElementClicked(event, element) {
if (element) {
const editableElement = element.querySelector(
`[data-element="editor-container"], [data-element="input"], [data-element="heading"]`
`[data-element="editor-container"], [data-element="heading"]`
);
return editableElement.contains(event.target);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/livebook/evaluator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ defmodule Livebook.Evaluator do
state = put_in(state.contexts[ref], result_context)

Evaluator.IOProxy.flush(state.io_proxy)
Evaluator.IOProxy.clear_input_buffers(state.io_proxy)
Evaluator.IOProxy.clear_input_cache(state.io_proxy)

output = state.formatter.format_response(response)
metadata = %{evaluation_time_ms: evaluation_time_ms}
Expand Down
Loading