From 0d568180761d7da56e756762d5f4b1555eea6a7f Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Mon, 2 Apr 2018 21:12:04 +0200 Subject: Add documentation to explain the process --- src/grid/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/grid/mod.rs b/src/grid/mod.rs index 0564cdf5..15ddf30e 100644 --- a/src/grid/mod.rs +++ b/src/grid/mod.rs @@ -747,25 +747,28 @@ impl<'a, T: Copy + 'a> Iterator for DisplayIter<'a, T> { #[inline] fn next(&mut self) -> Option { - // 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(); if next_line { + // Return `None` if we've reached the end of the last line if self.offset == self.limit { return None; } + // Switch to the next line self.col = Column(0); self.offset -= 1; self.line = Line(*self.grid.lines - 1 - (self.offset - self.limit)); } - // Return the next item. + // Return the next item let item = Some(Indexed { inner: self.grid.raw[self.offset][self.col], line: self.line, column: self.col }); + // Only increment column if the line hasn't changed if !next_line { self.col += 1; } -- cgit v1.2.3-54-g00ecf