fn item_bottom(item: isize) -> Self {
FilePosition { item, line: 1, width: None }
}
+
+ fn clip(self, first_index: isize, last_index: isize) -> Self {
+ let pos = self;
+ let pos = if pos.item < first_index {
+ Self::item_top(first_index)
+ } else {
+ pos
+ };
+ let pos = if pos.item > last_index {
+ Self::item_bottom(last_index)
+ } else {
+ pos
+ };
+ pos
+ }
}
trait FileDataSource {
let mut initial_pos = initial_pos.unwrap_or_else(
|| FilePosition::item_bottom(isize::MAX));
- initial_pos.item = max(initial_pos.item, contents.first_index());
- initial_pos.item = min(initial_pos.item, contents.last_index());
+ initial_pos = initial_pos.clip(
+ contents.first_index(), contents.last_index());
let ff = File {
contents,