fix: renumber sibling sequences when list indentation changes

This commit is contained in:
2026-10-19 19:00:16 +02:00
parent afa27b941f
commit 662200e684
3 changed files with 104 additions and 4 deletions
@@ -515,6 +515,38 @@ func listTabAndShiftTabPreserveMarkersSourceSelectionsUndoAndPersistence() throw
editor.breakUndoCoalescing()
editor.undoManager?.removeAllActions()
}
for (before, after, shift) in [
("1. hello,\n2. world!", "1. hello,\n 1. world!", false),
("1. parent\n2. world!\n3. tail", "1. parent\n 1. world!\n2. tail", false),
("1. parent\n 1. child\n2. world!\n3. tail", "1. parent\n 1. child\n 2. world!\n2. tail", false),
("1. parent\n 1. world!\n2. tail", "1. parent\n2. world!\n3. tail", true),
("7) parent\n 1) child\n 2) world!\n8) tail", "7) parent\n 1) child\n8) world!\n9) tail", true),
("1. parent\n - bullet\n2. world!", "1. parent\n - bullet\n 1. world!", false),
("1. parent\n\t1. child\n 2. world!", "1. parent\n\t1. child\n 2. world!", false),
("1. parent\n2. world!\n\n9. separate", "1. parent\n 1. world!\n\n9. separate", false),
("9) parent\n 1) world!\n10) tail", "9) parent\n10) world!\n11) tail", true),
("1. parent\n10. world!\n11. tail", "1. parent\n 1. world!\n2. tail", false),
("1. parent\n2. world!\n3. tail\n 7. separate", "1. parent\n 1. world!\n2. tail\n 7. separate", false),
("1. parent\n 1. world!\n 2. child\n2. tail", "1. parent\n2. world!\n 1. child\n3. tail", true),
("1. parent\r\n2) [X]\tworld!\r\n3. tail", "1. parent\r\n 1) [X]\tworld!\r\n2. tail", false),
] {
reset(before)
let selected = (editor.string as NSString).range(of: "world!")
editor.setSelectedRange(selected)
editor.keyDown(with: shift ? backtab : tab)
editor.breakUndoCoalescing()
#expect(editor.markdownString == after)
#expect((editor.string as NSString).substring(with: editor.selectedRange()) == "world!")
let id = try #require(defaults.string(forKey: "selectedNote").flatMap(UUID.init(uuidString:)))
let saved = try NotesStore(directory: directory).notes.first { $0.id == id }?.contents.string
#expect(saved == after.replacingOccurrences(of: "\r\n", with: "\n"))
editor.undoManager?.undo()
#expect(editor.markdownString == before)
#expect(editor.selectedRange() == selected)
#expect(editor.undoManager?.canUndo == false)
editor.undoManager?.redo()
#expect(editor.markdownString == after)
}
for marker in ["-", "*", "+", "009)", "12.", "- [X]", "2) []"] {
let source = " " + marker + " \t🦊 café\n - child"
reset(source)