Fold one visible change's semantic ops into every trunk of the current closure. Folding the same change twice, or folding before any closure was aligned, is a no-op.
(&mut self, change_id: NodeId, change: &Change)
| 123 | /// current closure. Folding the same change twice, or folding before |
| 124 | /// any closure was aligned, is a no-op. |
| 125 | pub(super) fn fold(&mut self, change_id: NodeId, change: &Change) { |
| 126 | let Some(closure) = self.closures.first_mut() else { |
| 127 | return; |
| 128 | }; |
| 129 | if !closure.folded.insert(change_id) { |
| 130 | return; |
| 131 | } |
| 132 | for ops in change.file_ops() { |
| 133 | if matches!( |
| 134 | ops.trunk_op(), |
| 135 | Some(atomic_core::crdt::TrunkOp::ProjectedSpanEdit { .. }) |
| 136 | ) { |
| 137 | continue; |
| 138 | } |
| 139 | let trunk = resolve_trunk(change_id, ops.trunk_id()); |
| 140 | let state = closure.trunks.entry(trunk).or_default(); |
| 141 | for line in ops.line_ops() { |
| 142 | let branch = resolve_branch(change_id, line.branch_id()); |
| 143 | match line.operation() { |
| 144 | BranchOp::Insert { after, .. } => { |
| 145 | state.alive.insert(branch, true); |
| 146 | state |
| 147 | .after |
| 148 | .insert(branch, after.map(|id| resolve_branch(change_id, id))); |
| 149 | } |
| 150 | BranchOp::Modify { .. } | BranchOp::Restore { .. } => { |
| 151 | state.alive.insert(branch, true); |
| 152 | } |
| 153 | BranchOp::Delete { .. } => { |
| 154 | state.alive.insert(branch, false); |
| 155 | } |
| 156 | BranchOp::Reparent { new_after, .. } => { |
| 157 | state |
| 158 | .after |
| 159 | .insert(branch, new_after.map(|id| resolve_branch(change_id, id))); |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /// The folded state of `trunk` in the current closure; empty when the |
| 167 | /// closure never touched it. |
no test coverage detected