Add strikout functionality.

This commit is contained in:
CentreMetre
2026-05-31 15:17:37 +01:00
parent bb16421a87
commit 37207cff97
2 changed files with 54 additions and 28 deletions

View File

@@ -28,15 +28,13 @@
</h3> </h3>
<div> <div>
<div id="output"> <div id="output">
<div id="gutter"></div> <div id="output-area" class="output-area"></div>
<div contenteditable="true" id="output-area" class="output-area"></div>
</div> </div>
</div> </div>
</div> </div>
<script> <script>
const gutter = document.getElementById("gutter");
const outputArea = document.getElementById("output-area"); const outputArea = document.getElementById("output-area");
let lineCount = getLineCount(); // 1 by default even though theres no \n because its splits by \n so its just 1 line let lineCount = getLineCount(); // 1 by default even though theres no \n because its splits by \n so its just 1 line
@@ -48,34 +46,58 @@
return outputArea.children.length; return outputArea.children.length;
} }
function updateGutterLineCount() { // TODO: Refactor so its not slow when theres more /**
gutter.innerHTML = "" * Sets the rows to the output
console.log("update gutter line count") * @param {string[]} codes - The array of codes to set the output to
*/
function setRows(codes) {
for (let i = 0; i < codes.length; i++) {
appendRow(codes[i], i+1)
}
for (let i = 0; i < lineCount; i++) { }
function appendRow(code, lineNumber) {
const row = document.createElement("div")
row.classList.add("output-row")
/**
* GUTTER
* **/
const gutterRow = document.createElement("div") const gutterRow = document.createElement("div")
gutterRow.className = "gutter-row" gutterRow.classList.add("gutter-row")
const checkbox = document.createElement("input") const gutterCheckBox = document.createElement("input")
checkbox.type = "checkbox" gutterCheckBox.type = "checkbox"
gutterCheckBox.dataset.lineNumber = lineNumber
const lineNumber = document.createElement("span")
lineNumber.textContent = i+1
gutterRow.append(checkbox, lineNumber) const gutterNumber = document.createElement("span")
gutterNumber.textContent = lineNumber
gutter.append(gutterRow) gutterRow.append(gutterCheckBox, gutterNumber)
}
console.log(lineCount) /**
* OUTPUT
* **/
const contentRow = document.createElement("div")
contentRow.classList.add("content-row")
contentRow.dataset.lineNumber = lineNumber
contentRow.textContent = code
gutterCheckBox.addEventListener("change", (e) => {
console.log(`event line number: ${lineNumber}`)
contentRow.classList.toggle("strike")
})
row.append(gutterRow, contentRow)
outputArea.append(row)
} }
outputArea.addEventListener("input", (event) => { setRows(["1","2","3","4","5"])
lineCount = getLineCount()
updateGutterLineCount()
});
updateGutterLineCount()
</script> </script>
</body> </body>
</html> </html>

View File

@@ -11,6 +11,10 @@
background-color: rgb(230, 230, 230); background-color: rgb(230, 230, 230);
} }
#output { #output-row {
display: flex; display: flex;
} }
.strike {
text-decoration: line-through;
}