} else {
fs.add(Space, "Down", 99)
};
- let fs = fs.add(Pr('q'), "Exit", 100)
- .finalise();
+ let fs = fs.add(Pr('q'), "Exit", 100);
// FIXME: document more keys
- // FIXME: best-effort percentage calculation
+
+ // We calculate the percentage through the file in a loose
+ // sort of way, by assuming all items are the same size, and
+ // only calculating a partial item for the one we're actually
+ // in the middle of. This isn't how Mono did it, but Mono
+ // didn't have to dynamically rewrap whenever the window
+ // resized.
+ //
+ // (A robust way to get precise line-based percentages even so
+ // would be to eagerly rewrap the entire collection of items
+ // on every resize, but I don't think that's a sensible
+ // tradeoff!)
+ let fs = {
+ let base = self.contents.first_index();
+ let full_items = (start_item - base) as usize;
+ let total_items = (self.contents.index_limit() - base) as usize;
+ let mult = self.rendered.get(&start_item).unwrap().len();
+ fs.set_proportion(
+ full_items * mult + start_line,
+ total_items * mult)
+ };
+
+ let fs = fs.finalise();
+
lines.extend_from_slice(&fs.render(w));
(lines, CursorPosition::End)