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.
|
// We have to calculate the rune position from the byte position.
|
||||||
rcount := 0
|
rcount := 0
|
||||||
idx := 0
|
sidx, eidx := 0, 0
|
||||||
for p := range before {
|
for p := range before {
|
||||||
for i := range edits[idx:] {
|
for i := range edits[sidx:] {
|
||||||
if edits[i].Start == p {
|
if edits[sidx+i].Start == p {
|
||||||
edits[i].Start = rcount
|
edits[sidx+i].Start = rcount
|
||||||
|
sidx += i
|
||||||
|
break
|
||||||
}
|
}
|
||||||
if edits[i].End == p {
|
}
|
||||||
edits[i].End = rcount
|
for i := range edits[eidx:] {
|
||||||
idx++
|
if edits[i+eidx].End == p {
|
||||||
|
edits[i+eidx].End = rcount
|
||||||
|
eidx += i
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rcount++
|
rcount++
|
||||||
if idx == len(edits) {
|
if eidx == len(edits) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,7 +119,7 @@ func main() {
|
|||||||
addr := fmt.Sprintf("#%d,#%d", edit.Start, edit.End)
|
addr := fmt.Sprintf("#%d,#%d", edit.Start, edit.End)
|
||||||
e = win.Addr(addr)
|
e = win.Addr(addr)
|
||||||
if e != nil {
|
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))
|
win.Write("data", []byte(edit.New))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user