mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-06 04:40:32 +09:00
Fix cursor bug
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
11
src/rope.go
11
src/rope.go
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user