Skip to content

Commit

Permalink
Merge pull request #212 from wiktor2200/fix-toggle-checkbox-indentation
Browse files Browse the repository at this point in the history
toggle-checkbox: Fix checkbox indentation
  • Loading branch information
pbek authored Dec 4, 2023
2 parents d1db1f0 + e59e94c commit fc2b3f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion toggle-checkbox/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Toggle checkbox",
"identifier": "toggle-checkbox",
"script": "toggle-checkbox.qml",
"version": "1.4.0",
"version": "1.4.1",
"minAppVersion": "19.3.2",
"authors": ["@sanderboom", "@pbek", "@wiktor2200"],
"description" : "This script creates a menu item and a button to toggle checkbox state. Change one or more selected lines regarding checkboxes: plainlist -> unchecked, unchecked -> checked, checked -> disabled, disabled -> unchecked. Hint: assign a shortcut."
Expand Down
18 changes: 9 additions & 9 deletions toggle-checkbox/toggle-checkbox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -118,31 +118,31 @@ QtObject {
// synchronizeChecked in effect.
// checkboxCharacter is already correctly set.
if (multipleLinesMethod === 'synchronizeChecked' && mixedStatesPresent) {
lines[i] = lines[i].replace(/- \[( |x|X)\] /, checkboxCharacter);
lines[i] = lines[i].replace(/(^\s*)- \[( |x|X)\] /, "$1" + checkboxCharacter);
}
// Default: cycle-all-lines-mode.
else {
script.log('Scenario: cycle-all-lines');

// Toggle unchecked to checked.
if (lines[i].match(/^- \[ \] /)) {
if (lines[i].match(/(^\s*)- \[ \] /)) {
script.log('Convert unchecked to checked');
lines[i] = lines[i].replace(/- \[ \] /, CHECKED);
lines[i] = lines[i].replace(/(^\s*)- \[ \] /, "$1" + CHECKED);
}
// Toggle checked to disabled.
else if (lines[i].match(/^- \[(x|X)\] /)) {
else if (lines[i].match(/(^\s*)- \[(x|X)\] /)) {
script.log('Convert checked to disabled');
lines[i] = lines[i].replace(/- \[(x|X)\] /, DISABLED);
lines[i] = lines[i].replace(/(^\s*)- \[(x|X)\] /, "$1" + DISABLED);
}
// Toggle disabled to unchecked.
else if (lines[i].match(/^- \[-\] /)) {
else if (lines[i].match(/(^\s*)- \[-\] /)) {
script.log('Convert disabled to unchecked');
lines[i] = lines[i].replace(/- \[-\] /, UNCHECKED);
lines[i] = lines[i].replace(/(^\s*)- \[-\] /, "$1" + UNCHECKED);
}
// Convert plain list lines (-, *, +) to unchecked checkboxes lines.
else if (!onlyTouchCheckboxes && lines[i].match(/^(-|\*|\+) /)) {
else if (!onlyTouchCheckboxes && lines[i].match(/(^\s*)(-|\*|\+) /)) {
script.log('Convert plain list to unchecked');
lines[i] = lines[i].replace(/^(-|\*|\+) /, UNCHECKED);
lines[i] = lines[i].replace(/(^\s*)(-|\*|\+) /, "$1" + UNCHECKED);
}
// Add checkboxes when unpresent (empty lines are skipped).
else if (!onlyTouchCheckboxes) {
Expand Down

0 comments on commit fc2b3f0

Please sign in to comment.