problem
I made a <textarea> and used Javascript to put the value into a <pre> tag (contenteditable was being weird), and I want a way to put a blinking caret in the <pre>, like pressing F7. I couldn't just have used the <textarea> because I'm making a JSON formatter (I was bored) and I wanted to add syntax highlighting.
what i have
document.querySelector("pre.stuff").addEventListener("click", function() {
document.querySelector("textarea.text").focus();
});
document.querySelector("textarea.text").addEventListener("input", function() {
document.querySelector("pre.stuff").innerText = this.value;
});
textarea.text {
position: absolute;
border: none;
padding: 0px;
opacity: 0;
width: 0px;
height: 0px;
}
pre.stuff {
width: calc(100% - 20px);
height: 250px;
border: solid gray 2px;
margin: 0px;
border-radius: 5px;
padding: 10px;
transition: 0.3s;
font-family: "Source Code Pro", monospace;
tab-size: var(--tab-size);
overflow: scroll;
cursor: text;
}
textarea.text:focus ~ pre.stuff, pre.stuff:focus {
outline: none;
box-shadow: #0066ff55 0px 0px 0px 4px; /* glowwww */
border: solid #66a3ff 2px;
}
body {
margin: 16px;
}
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap" rel="stylesheet">
<textarea class="text"></textarea>
<pre class="stuff" spellcheck="false" tabindex="-1"></pre>
<br>
I removed the syntax highlighting part :P
Also, the focus has to be on the <textarea> or it won't work.