− let offset = old_bytes - diff.pos_a[up_context_idx].pos;
− debug!("offset {:?} {:?}", pos.0, offset);
+ let mut offset = old_bytes - diff.pos_a[up_context_idx].pos;
+ // Here, in the case where one side of the conflict
+ // ended with a "last line without a `\n`", the offset
+ // might be off by one.
+ //
+ // We detect that case by testing whether the vertex
+ // length is the same as the length of the "line".
+
+ let v_end = diff.pos_a[up_context_idx].vertex.end.0.into();
+ if pos.0 + offset <= v_end {
+ //
+ } else if pos.0 + offset == v_end + 1 {
+ assert_eq!(diff.contents_a[old_bytes - 1], b'\n');
+ offset -= 1
+ } else {
+ panic!("{:?} {:?} {:?}", pos.0, offset, v_end);
+ }