1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-15 23:00:36 +02:00

All: Fixes #1427: Support checkoxes behind bullets

This commit is contained in:
Laurent Cozic
2019-04-20 19:00:22 +01:00
parent 27cce03968
commit 42119c8f42

View File

@ -236,21 +236,35 @@ shared.toggleCheckbox = function(ipcMessage, noteBody) {
const p = ipcMessage.split(':');
const lineIndex = Number(p[p.length - 1]);
if (lineIndex >= newBody.length) {
reg.logger().warn('Checkbox line out of bounds: ', ipcMessage, args);
reg.logger().warn('Checkbox line out of bounds: ', ipcMessage);
return newBody.join('\n');
}
let line = newBody[lineIndex];
if (line.trim().indexOf('- [ ] ') === 0) {
line = line.replace(/- \[ \] /, '- [x] ');
} else if (line.trim().indexOf('- [x] ') === 0 || line.trim().indexOf('- [X] ') === 0) {
line = line.replace(/- \[x\] /i, '- [ ] ');
} else {
reg.logger().warn('Could not find matching checkbox for message: ', ipcMessage, args);
const noCrossIndex = line.trim().indexOf('- [ ] ');
let crossIndex = line.trim().indexOf('- [x] ');
if (crossIndex < 0) crossIndex = line.trim().indexOf('- [X] ');
if (noCrossIndex < 0 && crossIndex < 0) {
reg.logger().warn('Could not find matching checkbox for message: ', ipcMessage);
return newBody.join('\n');
}
let isCrossLine = false;
if (noCrossIndex >= 0 && crossIndex >= 0) {
isCrossLine = crossIndex < noCrossIndex;
} else {
isCrossLine = crossIndex >= 0;
}
if (!isCrossLine) {
line = line.replace(/- \[ \] /, '- [x] ');
} else {
line = line.replace(/- \[x\] /i, '- [ ] ');
}
newBody[lineIndex] = line;
return newBody.join('\n')
}