added a format button if on mobile device

This commit is contained in:
chromoxdor
2025-07-21 18:35:12 +02:00
parent 120ea954d3
commit d5f3b9f830
2 changed files with 36 additions and 13 deletions
+35 -12
View File
@@ -243,22 +243,45 @@ function initCM() {
}
//--------------------------------------------------------------------------------- add formatting option
document.addEventListener('keydown', function (e) {
// Ctrl + Shift + F to format
if (e.ctrlKey && e.shiftKey && e.key.toLowerCase() === 'f') {
e.preventDefault();
console.log('Formatting...');
initalAutocorrection();
const textarea = document.getElementById('rules');
textarea.value = formatLogic(textarea.value);
// Add Format button inside the form
document.addEventListener('DOMContentLoaded', () => {
const form = document.getElementById('rulesselect');
if (form) {
const btn = document.createElement('button');
btn.type = 'button'; // prevent form submission
btn.id = 'formatBtn';
btn.textContent = 'Format';
btn.className = 'button'; // just the class, no inline style
form.appendChild(btn);
// Clean up previous CodeMirror instances (if any)
document.querySelectorAll('div.cm-s-default').forEach(el => el.remove());
initCM();
btn.addEventListener('click', () => {
console.log('Format button clicked');
triggerFormatting();
});
}
document.addEventListener('keydown', function (e) {
if (e.ctrlKey && e.shiftKey && e.key.toLowerCase() === 'f') {
e.preventDefault();
console.log('Keyboard shortcut detected: Formatting...');
triggerFormatting();
}
});
});
// Function to trigger formatting
function triggerFormatting() {
initalAutocorrection();
const textarea = document.getElementById('rules');
textarea.value = formatLogic(textarea.value);
// Clean up previous CodeMirror instances (if any)
document.querySelectorAll('div.cm-s-default').forEach(el => el.remove());
initCM();
}
function initalAutocorrection() {
const textarea = document.getElementById("rules");
let text = textarea.value;
@@ -287,7 +310,7 @@ function formatLogic(text) {
const trimmed = line.trimStart(); // remove leading spaces only
return trimmed.startsWith('//') ? line : trimmed;
});
let indentLevel = 0;
const result = [];
const stack = [];
+1 -1
View File
File diff suppressed because one or more lines are too long