From a69f89d2380433cbae0e620eb8d01c946daf949b Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Sat, 24 Jan 2015 21:15:32 -0800 Subject: [PATCH] Fixed bug in v2d_to_index code that was causing cursor nav issues. --- src/buffer/node.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/buffer/node.rs b/src/buffer/node.rs index 854732b..a5b3518 100644 --- a/src/buffer/node.rs +++ b/src/buffer/node.rs @@ -307,7 +307,17 @@ impl BufferNode { pub fn v2d_to_index_recursive(&self, f: &T, pos: (usize, usize), rounding: (RoundingBehavior, RoundingBehavior)) -> usize { match self.data { BufferNodeData::Leaf(ref line) => { - return f.v2d_to_index(line, pos, rounding); + let mut r = f.v2d_to_index(line, pos, rounding); + + // TODO: is this the right thing to do? The idea is that + // the non-leaf branch code should put us in the right leaf + // anyway, and returning and index equal to the leaf's + // grapheme count is putting it on the next line instead of + // this one. + if r == self.grapheme_count && self.grapheme_count > 0 { + r -= 1; + } + return r; }, BufferNodeData::Branch(ref left, ref right) => {