Make line commands aware of folded blocks#2508
Conversation
Greptile SummaryThis PR introduces
Confidence Score: 4/5Safe to merge for move and delete; the copy commands produce a visible UX regression (duplicate appears on the wrong side of the cursor) that was flagged in an earlier review thread and remains unaddressed. The move and delete paths correctly swap blocks, translate fold effects to their new positions, and fall back to native commands when no folds are active. The copy path inserts the duplicate at block.from for copy-down — placing the new copy above the original — while copy-up inserts at block.to, placing the copy below. Both directions are reversed relative to native CodeMirror behavior. The cursor ends up at the right line number in the test fixture only because the two copies are textually identical, so the assertion passes without distinguishing which duplicate holds the cursor. The copy direction logic in copyFoldedLines (lines 219–224 of foldAwareLineCommands.ts) warrants a second look before merging. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User triggers line command] --> B{Active folds in selection?}
B -- No --> C[Delegate to native copyLineDown/Up moveLineDown/Up deleteLine]
B -- Yes --> D[getFoldIndex build FoldGroup list]
D --> E[selectedLineBlocks expand each selection to full fold group]
E --> F{Command type}
F -- copy --> G[copyFoldedLines insert duplicate text re-apply foldEffects for both copies]
F -- move --> H[moveFoldedLines swap block with neighbor re-apply translated foldEffects]
F -- delete --> I[deleteLineFoldAware delete entire block including surrounding newline]
G --> J[view.dispatch changes + selection + foldEffect array]
H --> J
I --> K[view.dispatch changes + cursor at former block start]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[User triggers line command] --> B{Active folds in selection?}
B -- No --> C[Delegate to native copyLineDown/Up moveLineDown/Up deleteLine]
B -- Yes --> D[getFoldIndex build FoldGroup list]
D --> E[selectedLineBlocks expand each selection to full fold group]
E --> F{Command type}
F -- copy --> G[copyFoldedLines insert duplicate text re-apply foldEffects for both copies]
F -- move --> H[moveFoldedLines swap block with neighbor re-apply translated foldEffects]
F -- delete --> I[deleteLineFoldAware delete entire block including surrounding newline]
G --> J[view.dispatch changes + selection + foldEffect array]
H --> J
I --> K[view.dispatch changes + cursor at former block start]
Reviews (2): Last reviewed commit: "Merge main and address fold-aware copy r..." | Re-trigger Greptile |
Closes: #2492