From f46924086017cb2400fb47d796c683de65c8d46d Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Sat, 20 Dec 2014 18:45:01 -0800 Subject: [PATCH] Misc bug fixes on the way towards a proper editing interface. --- src/buffer/text_node.rs | 18 +++++++----------- src/editor.rs | 8 ++++++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/buffer/text_node.rs b/src/buffer/text_node.rs index 2f15798..e14f359 100644 --- a/src/buffer/text_node.rs +++ b/src/buffer/text_node.rs @@ -150,9 +150,7 @@ impl TextNode { } if child_rot { - if let TextNodeData::Branch(_, ref mut rc) = right.data { - rc.rotate_left(); - } + left.rotate_left(); } rot = 1; @@ -167,9 +165,7 @@ impl TextNode { } if child_rot { - if let TextNodeData::Branch(ref mut lc, _) = right.data { - lc.rotate_right(); - } + right.rotate_right(); } rot = -1; @@ -342,6 +338,11 @@ impl TextNode { let mut col = offset; for c in iter { + // Check if we've hit a relevant character + if line > pos.0 || (line == pos.0 && col >= pos.1) { + break; + } + // Increment counters if c == '\n' { line += 1; @@ -351,11 +352,6 @@ impl TextNode { col += 1; } i += 1; - - // Check if we've hit a relevant character - if line > pos.0 || (line == pos.0 && col > pos.1) { - break; - } } // If we've reached the end of this text block but diff --git a/src/editor.rs b/src/editor.rs index db59cfd..5dbd383 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -62,6 +62,14 @@ impl Editor { self.buffer.insert_text(text, pos); self.dirty = true; + + if text == "\n" { + self.cursor.0 += 1; + self.cursor.1 = 0; + } + else { + self.cursor.1 += 1; + } } pub fn cursor_left(&mut self) {