Skip to content

Commit

Permalink
yabl
Browse files Browse the repository at this point in the history
  • Loading branch information
najmiter authored Jan 27, 2024
1 parent 3b340a6 commit b967d8f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@ fetch("./settings.json")
.then((response) => response.json())
.then((settings) => (Settings = settings));

document.addEventListener("DOMContentLoaded", () => {
document.addEventListener("DOMContentLoaded", async () => {
// i forgot how to do it like a fire-emoji
// so i'm gonna do it like a sad-emoji
setTimeout(() => {
const n_spaces = +Settings.tab_size;

input_text.style.tabSize = n_spaces;
output_text.style.tabSize = n_spaces;

output_text.innerHTML = localStorage.getItem("styled_code") ?? "";
input_text.value = localStorage.getItem("plain_code") ?? "";
}, 100);

});

const is_space = (char) => char === " " || char === "\t";
Expand Down Expand Up @@ -249,8 +247,11 @@ const chittify = () => {
};

const put_shit_into_local_storage = () => {
localStorage.setItem("styled_code", output_text.innerHTML);
localStorage.setItem("plain_code", input_text.value);
// more sad-emoji stuff
setTimeout(() => {
localStorage.setItem("styled_code", output_text.innerHTML);
localStorage.setItem("plain_code", input_text.value);
}, 100);
};

const highlight_n_other_shit = () => {
Expand All @@ -259,6 +260,8 @@ const highlight_n_other_shit = () => {
};

const handle_key_down = (btn) => {
put_shit_into_local_storage();

if (btn.key === "Tab") {
btn.preventDefault();

Expand Down Expand Up @@ -296,10 +299,10 @@ document.addEventListener("keyup", (btn) => {
hightlight_btn.addEventListener("click", highlight_n_other_shit);
input_text.addEventListener("keydown", handle_key_down);
output_text.addEventListener("keydown", (btn) => {
put_shit_into_local_storage();

if (btn.key === "Tab") {
btn.preventDefault();
}
});


// document.getElementById("input-text").addEventListener("input", chittify); // React but O(n)

0 comments on commit b967d8f

Please sign in to comment.