codesort/
focused.rs

1use crate::*;
2
3#[derive(Debug, Clone)]
4pub struct Focused {
5    pub before: LocList,
6    pub focus: LocList,
7    pub after: LocList,
8}
9
10impl Focused {
11    pub fn print_debug(&self) {
12        self.before.print_debug(" BEFORE ");
13        self.focus.print_debug(" FOCUS ");
14        self.after.print_debug(" AFTER ");
15    }
16    pub fn sort(self) -> LocList {
17        let mut locs = self.before.locs;
18        let mut blocks = self.focus.into_blocks();
19        let spacing = Spacing::recognize(&blocks);
20        blocks.sort();
21        spacing.apply(&mut blocks);
22        for block in blocks {
23            locs.extend(block.locs);
24        }
25        locs.extend(self.after.locs);
26        LocList { locs }
27    }
28}