Fix cursor bug

This commit is contained in:
Zachary Yedidia
2016-03-27 12:27:26 -04:00
parent c49ebaf87b
commit d9ab074276
2 changed files with 10 additions and 10 deletions

View File

@@ -1,6 +1,8 @@
package main
import (
"io/ioutil"
"strconv"
"strings"
)
@@ -9,14 +11,11 @@ func FromCharPos(loc int, buf *Buffer) (int, int) {
charNum := 0
x, y := 0, 0
for charNum+Count(buf.lines[y])+1 < loc {
for charNum+Count(buf.lines[y])+1 <= loc {
charNum += Count(buf.lines[y]) + 1
y++
}
for charNum+x < loc {
x++
}
x = loc - charNum
return x, y
}

View File

@@ -5,9 +5,9 @@ import (
)
const (
// RopeSplitLength defines how large can a string be before it is split into two nodes
RopeSplitLength = 1000
// RopeJoinLength defines how short can a string be before it is joined
// RopeSplitLength is the threshold used to split a leaf node into two child nodes.
RopeSplitLength = 1000000000
// RopeJoinLength is the threshold used to join two child nodes into one leaf node.
RopeJoinLength = 500
// RopeRebalanceRatio = 1.2
)
@@ -39,8 +39,9 @@ func (r *Rope) Adjust() {
if !r.valueNil {
if r.len > RopeSplitLength {
divide := int(math.Floor(float64(r.len) / 2))
r.left = NewRope(r.value[:divide])
r.right = NewRope(r.value[divide:])
runes := []rune(r.value)
r.left = NewRope(string(runes[:divide]))
r.right = NewRope(string(runes[divide:]))
r.valueNil = true
}
} else {