Adds a new line to a file and returns its branch ID. # Arguments `trunk_id` - The file to add the line to `after` - The branch to insert after (None for start of file)
(
&mut self,
trunk_id: crate::crdt::TrunkId,
after: Option<BranchId>,
)
| 209 | /// * `trunk_id` - The file to add the line to |
| 210 | /// * `after` - The branch to insert after (None for start of file) |
| 211 | pub fn add_line( |
| 212 | &mut self, |
| 213 | trunk_id: crate::crdt::TrunkId, |
| 214 | after: Option<BranchId>, |
| 215 | ) -> BranchId { |
| 216 | let branch_id = self.alloc_branch_id(); |
| 217 | |
| 218 | let line_op = LineOps::insert(branch_id, after, Vec::new()); |
| 219 | |
| 220 | if let Some(&file_idx) = self.trunk_index.get(&trunk_id) { |
| 221 | let line_idx = self.file_ops[file_idx].line_ops.len(); |
| 222 | self.branch_index.insert(branch_id, (file_idx, line_idx)); |
| 223 | self.file_ops[file_idx].add_line_op(line_op); |
| 224 | } |
| 225 | |
| 226 | self.stats.lines_added += 1; |
| 227 | branch_id |
| 228 | } |
| 229 | |
| 230 | /// Adds a line with content, tokenizing into leaves. |
| 231 | pub fn add_line_with_content( |