mirror of
https://github.com/groldsf/obsidian_check_plugin.git
synced 2026-07-22 05:37:48 +00:00
Added support for different list types
This commit is contained in:
parent
a4ff7f9bab
commit
2ff122bf60
1 changed files with 9 additions and 6 deletions
15
main.ts
15
main.ts
|
|
@ -14,25 +14,28 @@ export default class CheckboxSyncPlugin extends Plugin {
|
|||
let updates: { line: number; ch: number; value: string }[] = [];
|
||||
|
||||
for (let i = lines.length - 1; i >= 0; i--) {
|
||||
const match = lines[i].match(/^(\s*)- \[(.)\] /);
|
||||
// Регулярные выражения для всех типов списков (с учетом пробела перед чекбоксом)
|
||||
const match = lines[i].match(/^(\s*)([*+-]|\d+\.) \[([ x-])\] /);
|
||||
if (!match) continue;
|
||||
|
||||
const indent = match[1].length;
|
||||
const isChecked = match[2] === "x";
|
||||
const indent = match[1].length; // Индентирование
|
||||
const isChecked = match[3] === "x"; // Состояние чекбокса
|
||||
let allChildrenChecked = true;
|
||||
let hasChildren = false;
|
||||
let j = i + 1;
|
||||
|
||||
// Ищем вложенные элементы для всех типов списков
|
||||
while (j < lines.length) {
|
||||
const childMatch = lines[j].match(/^(\s*)- \[(.)\] /);
|
||||
const childMatch = lines[j].match(/^(\s*)([*+-]|\d+\.) \[([ x-])\] /);
|
||||
if (!childMatch || childMatch[1].length <= indent) break;
|
||||
hasChildren = true;
|
||||
if (childMatch[2] !== "x") allChildrenChecked = false;
|
||||
if (childMatch[3] !== "x") allChildrenChecked = false;
|
||||
j++;
|
||||
}
|
||||
|
||||
// Обновляем родительский чекбокс, если есть дочерние
|
||||
if (hasChildren) {
|
||||
const checkboxPos = match[1].length + 3; // позиция "x" или " " в строке
|
||||
const checkboxPos = match[1].length + match[2].length + 2; // Позиция чекбокса
|
||||
if (allChildrenChecked && !isChecked) {
|
||||
updates.push({ line: i, ch: checkboxPos, value: "x" });
|
||||
} else if (!allChildrenChecked && isChecked) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue