fix recalc of byte offsets
This commit is contained in:
parent
94d148b913
commit
e6b687b25f
23
uncrust.go
23
uncrust.go
@ -83,19 +83,24 @@ func main() {
|
||||
|
||||
// We have to calculate the rune position from the byte position.
|
||||
rcount := 0
|
||||
idx := 0
|
||||
sidx, eidx := 0, 0
|
||||
for p := range before {
|
||||
for i := range edits[idx:] {
|
||||
if edits[i].Start == p {
|
||||
edits[i].Start = rcount
|
||||
for i := range edits[sidx:] {
|
||||
if edits[sidx+i].Start == p {
|
||||
edits[sidx+i].Start = rcount
|
||||
sidx += i
|
||||
break
|
||||
}
|
||||
if edits[i].End == p {
|
||||
edits[i].End = rcount
|
||||
idx++
|
||||
}
|
||||
for i := range edits[eidx:] {
|
||||
if edits[i+eidx].End == p {
|
||||
edits[i+eidx].End = rcount
|
||||
eidx += i
|
||||
break
|
||||
}
|
||||
}
|
||||
rcount++
|
||||
if idx == len(edits) {
|
||||
if eidx == len(edits) {
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -114,7 +119,7 @@ func main() {
|
||||
addr := fmt.Sprintf("#%d,#%d", edit.Start, edit.End)
|
||||
e = win.Addr(addr)
|
||||
if e != nil {
|
||||
log.Fatalf("error writing to acme/%d/addr: %s\n", wid, e)
|
||||
log.Fatalf("error writing %q to acme/%d/addr: %s\n", addr, wid, e)
|
||||
}
|
||||
win.Write("data", []byte(edit.New))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user