mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-27 19:57:38 +00:00
added a format button if on mobile device
This commit is contained in:
+35
-12
@@ -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 = [];
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user