Commit 93de374
committed
fix insert branch bugs in modify TUI
Fix three bugs with the insert branch feature in the modify TUI, and
adjust rename behavior on inserted nodes.
## Bug 1: False "moved" annotations on existing branches
After inserting a branch, all branches below the insertion point
displayed "↕ moved 1 layer down" annotations. This happened because
`nodeAnnotation` and `toNodeData` compared each node's
`OriginalPosition` against its raw array index, which gets shifted
when an inserted node is added to the slice.
Fix: introduce an `effectiveIdx` parameter that counts only
non-inserted nodes, so position comparisons reflect the original
ordering. The View loop computes effective indices by incrementing
only for non-inserted nodes and passes them to the rendering
functions.
## Bug 2: Header branch count inflated by staged inserts
The branch count in the header ("N branches") included inserted
placeholder nodes, making it appear as though the stack had grown
before changes were applied.
Fix: `buildHeaderConfig` now excludes `IsInserted` nodes from the
branch count. The count reflects only the original branches in the
stack.
## Bug 3: Operations allowed on inserted placeholder nodes
Inserted nodes could be folded into other branches, which makes no
sense for a placeholder with no commits. Additionally, the "last
branch" guard counted inserted nodes as active, allowing users to
drop all original branches and bypass the empty-stack check.
Fix:
- `fold()` rejects inserted nodes with a descriptive error message.
- `toggleDrop()` on an inserted node removes it entirely and pops
the original insert action from the undo stack (clean cancellation
rather than a separate undo entry).
- All three "active branch" guards (`toggleDrop`, `fold`, `tryApply`)
now exclude `IsInserted` nodes, ensuring at least one original
branch always remains in the stack.
## Rename on inserted branches
Instead of blocking renames on inserted nodes, pressing `r` now
enters rename mode and updates the insert action's name in place.
The node's `Ref.Branch` and `PendingAction.NewName` are both updated
directly — no separate rename action is created in the undo stack.
This lets users fix a typo without having to drop and re-insert.
## Tests added
- `TestInsertDoesNotShowMovedAnnotation` — verifies no false move
annotations appear on existing branches after an insert
- `TestBranchCountExcludesInserts` — verifies header count stays
stable after insert
- `TestCannotFoldInsertedBranch` — verifies fold is blocked
- `TestCannotRenameInsertedBranch` — verifies rename updates the
insert name in place
- `TestDropInsertedBranchRemovesIt` — verifies drop removes the node
- `TestDropInsertedBranchCanBeUndone` — verifies drop pops the
original insert from the undo stack
- `TestCannotDropAllOriginalBranchesWithInsert` — verifies the
empty-stack guard excludes inserted nodes1 parent d7d2bb9 commit 93de374
2 files changed
Lines changed: 272 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
316 | 334 | | |
317 | 335 | | |
318 | 336 | | |
| |||
443 | 461 | | |
444 | 462 | | |
445 | 463 | | |
446 | | - | |
| 464 | + | |
447 | 465 | | |
448 | 466 | | |
449 | 467 | | |
| |||
452 | 470 | | |
453 | 471 | | |
454 | 472 | | |
455 | | - | |
| 473 | + | |
456 | 474 | | |
457 | 475 | | |
458 | 476 | | |
| |||
664 | 682 | | |
665 | 683 | | |
666 | 684 | | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
667 | 709 | | |
668 | 710 | | |
669 | 711 | | |
| |||
708 | 750 | | |
709 | 751 | | |
710 | 752 | | |
711 | | - | |
| 753 | + | |
712 | 754 | | |
713 | 755 | | |
714 | 756 | | |
715 | 757 | | |
716 | 758 | | |
717 | | - | |
| 759 | + | |
718 | 760 | | |
719 | 761 | | |
720 | 762 | | |
| |||
740 | 782 | | |
741 | 783 | | |
742 | 784 | | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
743 | 790 | | |
744 | 791 | | |
745 | 792 | | |
| |||
803 | 850 | | |
804 | 851 | | |
805 | 852 | | |
806 | | - | |
| 853 | + | |
807 | 854 | | |
808 | 855 | | |
809 | 856 | | |
810 | 857 | | |
811 | 858 | | |
812 | | - | |
| 859 | + | |
813 | 860 | | |
814 | 861 | | |
815 | 862 | | |
| |||
979 | 1026 | | |
980 | 1027 | | |
981 | 1028 | | |
982 | | - | |
| 1029 | + | |
983 | 1030 | | |
984 | 1031 | | |
985 | | - | |
| 1032 | + | |
986 | 1033 | | |
987 | 1034 | | |
988 | 1035 | | |
| |||
1013 | 1060 | | |
1014 | 1061 | | |
1015 | 1062 | | |
1016 | | - | |
| 1063 | + | |
1017 | 1064 | | |
1018 | 1065 | | |
1019 | 1066 | | |
| |||
1043 | 1090 | | |
1044 | 1091 | | |
1045 | 1092 | | |
1046 | | - | |
| 1093 | + | |
1047 | 1094 | | |
1048 | 1095 | | |
1049 | 1096 | | |
| |||
1077 | 1124 | | |
1078 | 1125 | | |
1079 | 1126 | | |
1080 | | - | |
1081 | | - | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
1082 | 1130 | | |
1083 | 1131 | | |
1084 | 1132 | | |
| |||
1116 | 1164 | | |
1117 | 1165 | | |
1118 | 1166 | | |
1119 | | - | |
| 1167 | + | |
1120 | 1168 | | |
1121 | 1169 | | |
1122 | 1170 | | |
| |||
1125 | 1173 | | |
1126 | 1174 | | |
1127 | 1175 | | |
1128 | | - | |
1129 | | - | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
1130 | 1179 | | |
1131 | 1180 | | |
1132 | 1181 | | |
| |||
1147 | 1196 | | |
1148 | 1197 | | |
1149 | 1198 | | |
1150 | | - | |
1151 | | - | |
| 1199 | + | |
| 1200 | + | |
1152 | 1201 | | |
1153 | 1202 | | |
1154 | 1203 | | |
| |||
1184 | 1233 | | |
1185 | 1234 | | |
1186 | 1235 | | |
| 1236 | + | |
1187 | 1237 | | |
1188 | | - | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
1189 | 1245 | | |
1190 | | - | |
| 1246 | + | |
1191 | 1247 | | |
1192 | 1248 | | |
1193 | 1249 | | |
| |||
1247 | 1303 | | |
1248 | 1304 | | |
1249 | 1305 | | |
1250 | | - | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
1251 | 1313 | | |
1252 | 1314 | | |
1253 | 1315 | | |
| |||
0 commit comments