JSFiddle - React, Tailwind, and code Playground
by tsdexter
HTML
<div contenteditable="true">text text more text <span>and a text in a span</span></div>
<input type="text" />
<textarea></textarea>
JavaScript
window.text = "";
window.bold = false;
window.italic = false;
document.onkeydown = (e) => {
const evtobj = window.event ? event : e;
// console.log(evtobj.keyCode, evtobj.ctrlKey);
if (evtobj.keyCode == 66 && evtobj.ctrlKey) {
console.log("embolden");
window.bold = !window.bold;
};
};
window.conversion = {
bold: {
a: "๐ฎ",
b: "๐ฏ",
c: "๐ฐ",
d: "๐ฑ",
e: "๐ฒ",
f: "๐ณ",
g: "๐ด",
h: "๐ต",
i: "๐ถ",
j: "๐ท",
k: "๐ธ",
l: "๐น",
m: "๐บ",
n: "๐ป",
o: "๐ผ",
p: "๐ฝ",
q: "๐พ",
r: "๐ฟ",
s: "๐",
t: "๐",
u: "๐",
v: "๐",
w: "๐",
x: "๐
",
y: "๐"
}
}
window.addEventListener('keypress', (e) => {
const evtobj = window.event ? event : e;
const el = document.activeElement;
const text = el.value || el.innerText;
if (!evtobj.ctrlKey) {
const c = String.fromCharCode(evtobj.which);
const n = window.bold && window.conversion.bold[c] ? window.conversion.bold[c] : c;
el.value = text.length > 0 ? text.substring(0, text.length - 1) + n : n;
}
});