MCPcopy Index your code
hub / github.com/cifertech/DisplayKit / beginInlineTextEdit

Function beginInlineTextEdit

app.js:4891–4946  ·  view source on GitHub ↗
(elementId)

Source from the content-addressed store, hash-verified

4889}
4890
4891function beginInlineTextEdit(elementId) {
4892 const el = elements.find((e) => e.id === elementId);
4893 if (!el || !elementHasText(el.type)) return;
4894 const node = document.querySelector(`.ui-element[data-id="${elementId}"]`);
4895 if (!node) return;
4896
4897 const input = document.createElement("input");
4898 input.type = "text";
4899 input.value = el.text || "";
4900 input.className = "inline-text-editor";
4901 input.style.position = "absolute";
4902 input.style.left = "0";
4903 input.style.top = "0";
4904 input.style.width = "100%";
4905 input.style.height = "100%";
4906 input.style.border = "1px solid rgba(255, 109, 31, 0.6)";
4907 input.style.borderRadius = "8px";
4908 input.style.background = "rgba(0,0,0,0.25)";
4909 input.style.color = "inherit";
4910 input.style.padding = "6px 8px";
4911 input.style.font = "inherit";
4912 input.style.outline = "none";
4913
4914 // Replace visible text while editing
4915 const prevText = node.textContent;
4916 node.textContent = "";
4917 node.appendChild(input);
4918 input.focus();
4919 input.select();
4920
4921 const commit = () => {
4922 el.text = input.value;
4923 node.removeChild(input);
4924 node.textContent = prevText; // renderElements will refresh anyway
4925 renderElements();
4926 renderLayers();
4927 updatePropsInputs(false);
4928 updateCode();
4929 pushHistory();
4930 };
4931 const cancel = () => {
4932 node.removeChild(input);
4933 node.textContent = prevText;
4934 };
4935
4936 input.addEventListener("keydown", (e) => {
4937 if (e.key === "Enter") {
4938 e.preventDefault();
4939 commit();
4940 } else if (e.key === "Escape") {
4941 e.preventDefault();
4942 cancel();
4943 }
4944 });
4945 input.addEventListener("blur", () => commit());
4946}
4947
4948function openContextMenu(x, y) {

Callers 1

renderElementsFunction · 0.85

Calls 3

elementHasTextFunction · 0.85
commitFunction · 0.85
cancelFunction · 0.85

Tested by

no test coverage detected