From f50204a98b2221e2c4b5cdc6a4ad9f3455c24e06 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Thu, 27 Aug 2026 12:59:15 -0400 Subject: [PATCH] editor: detekt counts returns, so the promotion guards collapse into one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `promotingTasks` had four returns against ReturnCount's limit of two — three of them the same `return this`. Collapsed into a null-or-task guard and a `changed` flag, which says the contract more plainly anyway: the list comes back untouched unless something was actually promoted. Mirrored in blocks.ts even though nothing lints it there. The two files are kept line-by-line alike on purpose, and letting them drift on shape is how the next person stops trusting that reading one tells you the other. Co-Authored-By: Claude Opus 5 --- .../java/com/fabledsword/thoughtsync/ui/EditorBlock.kt | 10 ++++++---- frontend/src/notes/blocks.ts | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/android/app/src/main/java/com/fabledsword/thoughtsync/ui/EditorBlock.kt b/android/app/src/main/java/com/fabledsword/thoughtsync/ui/EditorBlock.kt index 1309dc7..2c39a40 100644 --- a/android/app/src/main/java/com/fabledsword/thoughtsync/ui/EditorBlock.kt +++ b/android/app/src/main/java/com/fabledsword/thoughtsync/ui/EditorBlock.kt @@ -167,11 +167,13 @@ fun List.plusTask(): Pair, Long> { * only the way it is drawn. */ internal fun List.promotingTasks(index: Int): List { - val block = getOrNull(index) ?: return this - if (block.isTask) return this + val block = getOrNull(index) + if (block == null || block.isTask) return this val split = splitBlocks(block.value.text, nextId()) - if (split.size == 1 && !split.first().isTask) return this - return take(index) + split + drop(index + 1) + // A single prose block back means there was nothing to promote. `splitBlocks` never + // returns an empty list, so `first()` is safe. + val changed = split.size > 1 || split.first().isTask + return if (changed) take(index) + split + drop(index + 1) else this } /** diff --git a/frontend/src/notes/blocks.ts b/frontend/src/notes/blocks.ts index d6851c2..772437b 100644 --- a/frontend/src/notes/blocks.ts +++ b/frontend/src/notes/blocks.ts @@ -137,6 +137,8 @@ export function promoteTasks(blocks: EditorBlock[], index: number): EditorBlock[ const block = blocks[index]; if (!block || block.checked !== null) return blocks; const split = splitBlocks(block.text, nextId(blocks)); - if (split.length === 1 && split[0].checked === null) return blocks; - return [...blocks.slice(0, index), ...split, ...blocks.slice(index + 1)]; + // A single prose block back means there was nothing to promote. `splitBlocks` never + // returns an empty array, so `split[0]` is safe. + const changed = split.length > 1 || split[0].checked !== null; + return changed ? [...blocks.slice(0, index), ...split, ...blocks.slice(index + 1)] : blocks; }