From a8130c864d11bf11120fb5120cfff18904328247 Mon Sep 17 00:00:00 2001 From: fef Date: Sun, 24 Jul 2022 14:03:38 +0200 Subject: [PATCH] cursor: break line after \n Up to now, the cursor broke the line *before* the \n and made that character the 0th one in the new line. I don't know why i did this, but at least it's fixed now. --- src/lex/cursor.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lex/cursor.rs b/src/lex/cursor.rs index e89cb3a..e4debfc 100644 --- a/src/lex/cursor.rs +++ b/src/lex/cursor.rs @@ -18,7 +18,7 @@ impl Iterator for Cursor { let c = self.raw[self.pos]; self.pos += 1; - if c == '\n' { + if self.current == Some('\n') { self.new_line(); } else { self.col += 1; @@ -51,10 +51,9 @@ impl Cursor { self.pos -= 1; let c = self.raw[self.pos]; + self.col -= 1; if self.col == 0 { self.prev_line(); - } else { - self.col -= 1; } self.current = Some(c); @@ -132,7 +131,7 @@ impl Cursor { fn new_line(&mut self) { self.line_lengths.push(self.col); - self.col = 0; + self.col = 1; self.line += 1; }