Skip to content

Commit

Permalink
Calculate basic sliders
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilfred committed Jun 28, 2023
1 parent ff44d26 commit c5644b2
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/diff/text_sliders.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
use std::collections::HashMap;

use itertools::Itertools;

use crate::parse::syntax::MatchedPos;
use crate::{
lines::LineNumber,
parse::syntax::{MatchKind, MatchedPos},
};

pub fn fix_sliders(lines: &[String], lhs_mps: &[MatchedPos], rhs_mps: &[MatchedPos]) {
pub fn fix_sliders(
lhs_lines: &[String],
rhs_lines: &[String],
lhs_mps: &[MatchedPos],
rhs_mps: &[MatchedPos],
) {
// GOAL: Join contiguous novel regions where possible.
//
// Iterate through novel regions pairwise, and if there's a gap
// between them that also occurs after the second novel region,
// slide.
let lhs_novel_regions = novel_regions(lhs_mps);

// Slider: (lhs_old, (lhs_new, rhs_line)).
let mut lhs_sliders: HashMap<usize, (usize, LineNumber)> = HashMap::new();

for (prev_region, next_region) in lhs_novel_regions.iter().tuple_windows() {
if can_slide(lines, lhs_mps, prev_region.1, next_region.0, next_region.1) {}
if can_slide(
lhs_lines,
lhs_mps,
prev_region.1,
next_region.0,
next_region.1,
) {
let unchanged_mp = &lhs_mps[prev_region.1 + 1];
if let MatchKind::UnchangedToken { opposite_pos, .. } = &unchanged_mp.kind {
lhs_sliders.insert(prev_region.1 + 1, (next_region.1 + 1, opposite_pos[0].line));
}
}
}
}

Expand Down

0 comments on commit c5644b2

Please sign in to comment.