1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-18 13:55:23 -05:00

Add documentation to explain the process

This commit is contained in:
Christian Duerr 2018-04-02 21:12:04 +02:00 committed by Joe Wilm
parent 54b21b66ec
commit 0d56818076

View file

@ -747,25 +747,28 @@ impl<'a, T: Copy + 'a> Iterator for DisplayIter<'a, T> {
#[inline] #[inline]
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
// Make sure indices are valid. Return None if we've reached the end. // Check if the end of the line was reached
let next_line = self.col == self.grid.num_cols(); let next_line = self.col == self.grid.num_cols();
if next_line { if next_line {
// Return `None` if we've reached the end of the last line
if self.offset == self.limit { if self.offset == self.limit {
return None; return None;
} }
// Switch to the next line
self.col = Column(0); self.col = Column(0);
self.offset -= 1; self.offset -= 1;
self.line = Line(*self.grid.lines - 1 - (self.offset - self.limit)); self.line = Line(*self.grid.lines - 1 - (self.offset - self.limit));
} }
// Return the next item. // Return the next item
let item = Some(Indexed { let item = Some(Indexed {
inner: self.grid.raw[self.offset][self.col], inner: self.grid.raw[self.offset][self.col],
line: self.line, line: self.line,
column: self.col column: self.col
}); });
// Only increment column if the line hasn't changed
if !next_line { if !next_line {
self.col += 1; self.col += 1;
} }