Skip to content

Commit

Permalink
ellipsis token picking
Browse files Browse the repository at this point in the history
  • Loading branch information
misson20000 committed Nov 24, 2024
1 parent e72cbe7 commit ad788e4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/view/listing/pick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ pub enum Part {
index: usize,
offset: addr::Address,
low_nybble: bool,
}
},
Ellipsis {
index: usize,
offset: addr::Address,
},
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -72,6 +76,12 @@ fn path_part_to_endpoint<'a>(document: &'_ document::Document, tuple: &'a (struc
child_index: *index,
offset: *offset
},

(path, Part::Ellipsis { index, offset, .. }) => selection::listing::StructureEndpoint {
parent: &path[..],
child_index: *index,
offset: *offset
},
})
}

Expand Down Expand Up @@ -102,6 +112,7 @@ impl Part {
Part::Hexstring { low_nybble, .. } => cursor::PlacementHint::Hexstring(cursor::hexstring::HexstringPlacementHint {
low_nybble: *low_nybble
}),
Part::Ellipsis { .. } => cursor::PlacementHint::Unused,
}
}

Expand All @@ -110,6 +121,7 @@ impl Part {
Part::Title => addr::unit::NULL,
Part::Hexdump { offset, .. } => *offset,
Part::Hexstring { offset, .. } => *offset,
Part::Ellipsis { offset, .. } => *offset,
}
}
}
Expand All @@ -133,6 +145,8 @@ impl<'a> Ord for PickSort<'a> {
(Part::Hexdump { index: _, .. }, _) => std::cmp::Ordering::Greater,
(Part::Hexstring { index: self_index, .. }, other_index) if *self_index <= other_index => std::cmp::Ordering::Less,
(Part::Hexstring { index: _, .. }, _) => std::cmp::Ordering::Greater,
(Part::Ellipsis { index: self_index, .. }, other_index) if *self_index <= other_index => std::cmp::Ordering::Less,
(Part::Ellipsis { index: _, .. }, _) => std::cmp::Ordering::Greater,
}
} else if self.0.0.len() > prefix_length && other.0.0.len() == prefix_length {
return match (self.0.0[prefix_length], &other.0.1) {
Expand All @@ -141,6 +155,8 @@ impl<'a> Ord for PickSort<'a> {
(_, Part::Hexdump { index: _, .. }) => std::cmp::Ordering::Less,
(self_index, Part::Hexstring { index: other_index, .. }) if self_index >= *other_index => std::cmp::Ordering::Greater,
(_, Part::Hexstring { index: _, .. }) => std::cmp::Ordering::Less,
(self_index, Part::Ellipsis { index: other_index, .. }) if self_index >= *other_index => std::cmp::Ordering::Greater,
(_, Part::Ellipsis { index: _, .. }) => std::cmp::Ordering::Less,
}
} else if self.0.0.len() > prefix_length && other.0.0.len() > prefix_length {
return self.0.0[prefix_length].cmp(&other.0.0[prefix_length]);
Expand Down
14 changes: 14 additions & 0 deletions src/view/listing/token_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,20 @@ impl TokenView {
offset: t.extent.end,
low_nybble: false,
})),
token::Token::Ellipsis(t) => Some(listing::pick::Triplet {
begin: (t.node_path().clone(), listing::pick::Part::Ellipsis {
index: t.node_child_index(),
offset: t.extent.begin,
}),
middle: (t.node_path().clone(), listing::pick::Part::Ellipsis {
index: t.node_child_index(),
offset: t.extent.begin,
}),
end: (t.node_path().clone(), listing::pick::Part::Ellipsis {
index: t.node_child_index(),
offset: t.extent.end,
}),
}),

/* Hexdump tokens can be picked, but that's done as part of HexdumpBucket picking logic and not done here. */

Expand Down

0 comments on commit ad788e4

Please sign in to comment.