Checklists in the body, colour from tags, and commit-derived CalVer #4
@@ -167,11 +167,13 @@ fun List<EditorBlock>.plusTask(): Pair<List<EditorBlock>, Long> {
|
|||||||
* only the way it is drawn.
|
* only the way it is drawn.
|
||||||
*/
|
*/
|
||||||
internal fun List<EditorBlock>.promotingTasks(index: Int): List<EditorBlock> {
|
internal fun List<EditorBlock>.promotingTasks(index: Int): List<EditorBlock> {
|
||||||
val block = getOrNull(index) ?: return this
|
val block = getOrNull(index)
|
||||||
if (block.isTask) return this
|
if (block == null || block.isTask) return this
|
||||||
val split = splitBlocks(block.value.text, nextId())
|
val split = splitBlocks(block.value.text, nextId())
|
||||||
if (split.size == 1 && !split.first().isTask) return this
|
// A single prose block back means there was nothing to promote. `splitBlocks` never
|
||||||
return take(index) + split + drop(index + 1)
|
// 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
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -137,6 +137,8 @@ export function promoteTasks(blocks: EditorBlock[], index: number): EditorBlock[
|
|||||||
const block = blocks[index];
|
const block = blocks[index];
|
||||||
if (!block || block.checked !== null) return blocks;
|
if (!block || block.checked !== null) return blocks;
|
||||||
const split = splitBlocks(block.text, nextId(blocks));
|
const split = splitBlocks(block.text, nextId(blocks));
|
||||||
if (split.length === 1 && split[0].checked === null) return blocks;
|
// A single prose block back means there was nothing to promote. `splitBlocks` never
|
||||||
return [...blocks.slice(0, index), ...split, ...blocks.slice(index + 1)];
|
// 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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user