chore: use better variable names
This commit is contained in:
parent
5f5ed410df
commit
8ce242bb65
1 changed files with 6 additions and 6 deletions
|
@ -14,26 +14,26 @@ const spaceRegex = /^ */
|
||||||
export function parseSubtasksViaIndention(taskTitles: string): TaskWithParent[] {
|
export function parseSubtasksViaIndention(taskTitles: string): TaskWithParent[] {
|
||||||
const titles = taskTitles.split(/[\r\n]+/)
|
const titles = taskTitles.split(/[\r\n]+/)
|
||||||
|
|
||||||
return titles.map((t, i) => {
|
return titles.map((title, index) => {
|
||||||
const task: TaskWithParent = {
|
const task: TaskWithParent = {
|
||||||
title: cleanupTitle(t),
|
title: cleanupTitle(title),
|
||||||
parent: null,
|
parent: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
const matched = spaceRegex.exec(t)
|
const matched = spaceRegex.exec(title)
|
||||||
const matchedSpaces = matched ? matched[0].length : 0
|
const matchedSpaces = matched ? matched[0].length : 0
|
||||||
|
|
||||||
if (matchedSpaces > 0 && i > 0) {
|
if (matchedSpaces > 0 && index > 0) {
|
||||||
// Go up the tree to find the first task with less indention than the current one
|
// Go up the tree to find the first task with less indention than the current one
|
||||||
let pi = 1
|
let pi = 1
|
||||||
let parentSpaces = 0
|
let parentSpaces = 0
|
||||||
do {
|
do {
|
||||||
task.parent = cleanupTitle(titles[i - pi])
|
task.parent = cleanupTitle(titles[index - pi])
|
||||||
pi++
|
pi++
|
||||||
const parentMatched = spaceRegex.exec(task.parent)
|
const parentMatched = spaceRegex.exec(task.parent)
|
||||||
parentSpaces = parentMatched ? parentMatched[0].length : 0
|
parentSpaces = parentMatched ? parentMatched[0].length : 0
|
||||||
} while (parentSpaces >= matchedSpaces)
|
} while (parentSpaces >= matchedSpaces)
|
||||||
task.title = cleanupTitle(t.replace(spaceRegex, ''))
|
task.title = cleanupTitle(title.replace(spaceRegex, ''))
|
||||||
task.parent = task.parent.replace(spaceRegex, '')
|
task.parent = task.parent.replace(spaceRegex, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue