Skip to content

Commit fc2b3f0

Browse files
authored
Merge pull request #212 from wiktor2200/fix-toggle-checkbox-indentation
toggle-checkbox: Fix checkbox indentation
2 parents d1db1f0 + e59e94c commit fc2b3f0

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

toggle-checkbox/info.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Toggle checkbox",
33
"identifier": "toggle-checkbox",
44
"script": "toggle-checkbox.qml",
5-
"version": "1.4.0",
5+
"version": "1.4.1",
66
"minAppVersion": "19.3.2",
77
"authors": ["@sanderboom", "@pbek", "@wiktor2200"],
88
"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."

toggle-checkbox/toggle-checkbox.qml

+9-9
Original file line numberDiff line numberDiff line change
@@ -118,31 +118,31 @@ QtObject {
118118
// synchronizeChecked in effect.
119119
// checkboxCharacter is already correctly set.
120120
if (multipleLinesMethod === 'synchronizeChecked' && mixedStatesPresent) {
121-
lines[i] = lines[i].replace(/- \[( |x|X)\] /, checkboxCharacter);
121+
lines[i] = lines[i].replace(/(^\s*)- \[( |x|X)\] /, "$1" + checkboxCharacter);
122122
}
123123
// Default: cycle-all-lines-mode.
124124
else {
125125
script.log('Scenario: cycle-all-lines');
126126

127127
// Toggle unchecked to checked.
128-
if (lines[i].match(/^- \[ \] /)) {
128+
if (lines[i].match(/(^\s*)- \[ \] /)) {
129129
script.log('Convert unchecked to checked');
130-
lines[i] = lines[i].replace(/- \[ \] /, CHECKED);
130+
lines[i] = lines[i].replace(/(^\s*)- \[ \] /, "$1" + CHECKED);
131131
}
132132
// Toggle checked to disabled.
133-
else if (lines[i].match(/^- \[(x|X)\] /)) {
133+
else if (lines[i].match(/(^\s*)- \[(x|X)\] /)) {
134134
script.log('Convert checked to disabled');
135-
lines[i] = lines[i].replace(/- \[(x|X)\] /, DISABLED);
135+
lines[i] = lines[i].replace(/(^\s*)- \[(x|X)\] /, "$1" + DISABLED);
136136
}
137137
// Toggle disabled to unchecked.
138-
else if (lines[i].match(/^- \[-\] /)) {
138+
else if (lines[i].match(/(^\s*)- \[-\] /)) {
139139
script.log('Convert disabled to unchecked');
140-
lines[i] = lines[i].replace(/- \[-\] /, UNCHECKED);
140+
lines[i] = lines[i].replace(/(^\s*)- \[-\] /, "$1" + UNCHECKED);
141141
}
142142
// Convert plain list lines (-, *, +) to unchecked checkboxes lines.
143-
else if (!onlyTouchCheckboxes && lines[i].match(/^(-|\*|\+) /)) {
143+
else if (!onlyTouchCheckboxes && lines[i].match(/(^\s*)(-|\*|\+) /)) {
144144
script.log('Convert plain list to unchecked');
145-
lines[i] = lines[i].replace(/^(-|\*|\+) /, UNCHECKED);
145+
lines[i] = lines[i].replace(/(^\s*)(-|\*|\+) /, "$1" + UNCHECKED);
146146
}
147147
// Add checkboxes when unpresent (empty lines are skipped).
148148
else if (!onlyTouchCheckboxes) {

0 commit comments

Comments
 (0)