diff --git a/TODO.md b/TODO.md index d1deba8..3a4af17 100644 --- a/TODO.md +++ b/TODO.md @@ -18,10 +18,10 @@ - [ ] Consolidate menu creation (card menus and burger menu) - [ ] Extract line parsing logic - separate parsing from state management - [ ] Make createAddForm more generic to handle both columns and cards -- [ ] Extract and consolidate indent detection functions ## Done +- [x] Extract and consolidate indent detection functions - [x] Reduce IndexedDB boilerplate with generic DB operation wrapper - [x] Simplify drop indicator logic - [x] Extract file operations into higher-level abstraction diff --git a/index.html b/index.html index f07452e..a6caa02 100644 --- a/index.html +++ b/index.html @@ -1121,11 +1121,13 @@ chmod 755 kbtd } } - function detectIndentInFile(text) { - const lines = text.split('\n'); + function detectIndent(lines, defaultIndent = ' ') { + if (!lines || lines.length === 0) return defaultIndent; + + const lineArray = typeof lines === 'string' ? lines.split('\n') : lines; let minIndent = null; - for (const line of lines) { + for (const line of lineArray) { if (line.trim() === '') continue; const match = line.match(/^(\s+)/); @@ -1137,27 +1139,7 @@ chmod 755 kbtd } } - return minIndent || ' '; - } - - function detectBaseIndent(nestedLines) { - if (nestedLines.length === 0) return ''; - - let minIndent = null; - - for (const line of nestedLines) { - if (line.trim() === '') continue; - - const match = line.match(/^(\s+)/); - if (match) { - const indent = match[1]; - if (minIndent === null || indent.length < minIndent.length) { - minIndent = indent; - } - } - } - - return minIndent || ''; + return minIndent || defaultIndent; } function stripBaseIndent(nestedLines, baseIndent) { @@ -1734,10 +1716,10 @@ chmod 755 kbtd const cardDetailModal = createModal('card-detail-modal', async (card) => { const file = await state.fileHandle.getFile(); const text = await file.text(); - const defaultIndent = detectIndentInFile(text); + const defaultIndent = detectIndent(text); const baseIndent = card.nestedLines.length > 0 - ? detectBaseIndent(card.nestedLines) + ? detectIndent(card.nestedLines, '') : defaultIndent; const strippedContent = stripBaseIndent(card.nestedLines, baseIndent);