mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-12-10 05:36:15 +08:00
* Show all sections and enable cross-section focus navigation * Move focus to the client * Add shortcut for evaluating all cells * Fix and expand tests * Make section links scroll to the given section
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
export function isMacOS() {
|
|
return /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);
|
|
}
|
|
|
|
export function isEditableElement(element) {
|
|
return (
|
|
["input", "textarea"].includes(element.tagName.toLowerCase()) ||
|
|
element.contentEditable === "true"
|
|
);
|
|
}
|
|
|
|
export function clamp(n, x, y) {
|
|
return Math.min(Math.max(n, x), y);
|
|
}
|
|
|
|
export function getLineHeight(element) {
|
|
const computedStyle = window.getComputedStyle(element);
|
|
const lineHeight = parseInt(computedStyle.lineHeight, 10);
|
|
|
|
if (Number.isNaN(lineHeight)) {
|
|
const clone = element.cloneNode();
|
|
clone.innerHTML = "<br>";
|
|
element.appendChild(clone);
|
|
const singleLineHeight = clone.clientHeight;
|
|
clone.innerHTML = "<br><br>";
|
|
const doubleLineHeight = clone.clientHeight;
|
|
element.removeChild(clone);
|
|
const lineHeight = doubleLineHeight - singleLineHeight;
|
|
return lineHeight;
|
|
} else {
|
|
return lineHeight;
|
|
}
|
|
}
|
|
|
|
export function selectElementContent(element) {
|
|
const selection = window.getSelection();
|
|
const range = document.createRange();
|
|
range.selectNodeContents(element);
|
|
selection.removeAllRanges();
|
|
selection.addRange(range);
|
|
}
|
|
|
|
export function smoothlyScrollToElement(element) {
|
|
element.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
}
|