mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-23 01:07:16 +09:00
Improve remove performance
This commit is contained in:
@@ -2,7 +2,6 @@ package buffer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
@@ -124,33 +123,35 @@ func (eh *EventHandler) InsertBytes(start Loc, text []byte) {
|
||||
Deltas: []Delta{{text, start, Loc{0, 0}}},
|
||||
Time: time.Now(),
|
||||
}
|
||||
// oldl := eh.buf.LinesNum()
|
||||
oldl := eh.buf.LinesNum()
|
||||
eh.Execute(e)
|
||||
// linecount := eh.buf.LinesNum() - oldl
|
||||
linecount := eh.buf.LinesNum() - oldl
|
||||
textcount := utf8.RuneCount(text)
|
||||
lastnl := bytes.LastIndex(text, []byte{'\n'})
|
||||
var endX int
|
||||
var textX int
|
||||
if lastnl >= 0 {
|
||||
endX = utf8.RuneCount(text[lastnl:])
|
||||
endX = utf8.RuneCount(text[lastnl+1:])
|
||||
textX = endX
|
||||
} else {
|
||||
// endX = start.X + textcount
|
||||
endX = start.X + textcount
|
||||
textX = textcount
|
||||
}
|
||||
|
||||
e.Deltas[0].End = start.MoveLA(textcount, eh.buf.LineArray)
|
||||
// e.Deltas[0].End = clamp(Loc{endX, start.Y + linecount}, eh.buf.LineArray)
|
||||
e.Deltas[0].End = clamp(Loc{endX, start.Y + linecount}, eh.buf.LineArray)
|
||||
end := e.Deltas[0].End
|
||||
|
||||
for _, c := range eh.cursors {
|
||||
move := func(loc Loc) Loc {
|
||||
log.Println("move", loc)
|
||||
if start.Y != end.Y && loc.GreaterThan(start) {
|
||||
loc.Y += end.Y - start.Y
|
||||
} else if loc.Y == start.Y && loc.GreaterEqual(start) {
|
||||
loc.Y += end.Y - start.Y
|
||||
loc.X += textX
|
||||
if lastnl >= 0 {
|
||||
loc.X = textX
|
||||
} else {
|
||||
loc.X += textX
|
||||
}
|
||||
}
|
||||
return loc
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user