feat: automatically create subtask relations based on indention #2443

Merged
konrad merged 6 commits from feature/subtask-via-indention into main 2022-09-30 11:47:22 +00:00
1 changed files with 6 additions and 6 deletions
Showing only changes of commit 8ce242bb65 - Show all commits

View File

@ -14,26 +14,26 @@ const spaceRegex = /^ */
export function parseSubtasksViaIndention(taskTitles: string): TaskWithParent[] {
const titles = taskTitles.split(/[\r\n]+/)
return titles.map((t, i) => {
return titles.map((title, index) => {
konrad marked this conversation as resolved Outdated

Picky: use clear variable name, e.g. title, index.

Makes reading easier since you don't have to remember and jump to the var definition.

Picky: use clear variable name, e.g. `title`, `index`. Makes reading easier since you don't have to remember and jump to the var definition.

Makes sense. Done!

Makes sense. Done!
const task: TaskWithParent = {
title: cleanupTitle(t),
title: cleanupTitle(title),
parent: null,
}
const matched = spaceRegex.exec(t)
const matched = spaceRegex.exec(title)
konrad marked this conversation as resolved Outdated

Move matched and matchedSpaces in condition aswell since it's not used for index === 0

Move `matched` and `matchedSpaces` in condition aswell since it's not used for `index === 0`

Added an earlier break for index === 0.

Added an earlier break for `index === 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
let pi = 1
let parentSpaces = 0
do {
task.parent = cleanupTitle(titles[i - pi])
task.parent = cleanupTitle(titles[index - pi])
pi++
const parentMatched = spaceRegex.exec(task.parent)
parentSpaces = parentMatched ? parentMatched[0].length : 0
} while (parentSpaces >= matchedSpaces)
task.title = cleanupTitle(t.replace(spaceRegex, ''))
task.title = cleanupTitle(title.replace(spaceRegex, ''))
task.parent = task.parent.replace(spaceRegex, '')
}