Fix redundant file loading and buffer insertion bugs
- Fix ChunkedBuffer.Insert to always update file length. - Fix UpdateLineIndexAfterEdit to not shift the first line offset. - Remove redundant ReadFileTask dispatch in HandleBrowserTap. - Add end-to-end test for typing at start of buffer.
This commit is contained in:
@@ -59,7 +59,9 @@ func NewChunkedBuffer(filename string, chunkSize int, fs pool.FileSystem, basePa
|
||||
|
||||
// SetFileSize sets the total file length.
|
||||
func (cb *ChunkedBuffer) SetFileSize(length int64) {
|
||||
cb.fileLen = length
|
||||
if !cb.dirty {
|
||||
cb.fileLen = length
|
||||
}
|
||||
}
|
||||
|
||||
// FileLen returns the total file length.
|
||||
@@ -288,10 +290,7 @@ func (cb *ChunkedBuffer) Insert(pos int, text string) {
|
||||
copy(newChunk[offsetInChunk+len(text):], chunk[offsetInChunk:])
|
||||
cb.chunks[chunkIdx] = newChunk
|
||||
|
||||
// Update file length if insertion extends beyond current length
|
||||
if pos+len(text) > int(cb.fileLen) {
|
||||
cb.fileLen = int64(pos + len(text))
|
||||
}
|
||||
cb.fileLen += int64(len(text))
|
||||
|
||||
cb.dirty = true
|
||||
cb.dirtyChunks[chunkIdx] = true
|
||||
@@ -538,6 +537,9 @@ func (cb *ChunkedBuffer) UpdateLineIndexAfterEdit(editPos int, offsetShift int)
|
||||
idx := sort.Search(len(cb.LineIndex.Offsets), func(i int) bool {
|
||||
return int(cb.LineIndex.Offsets[i]) >= editPos
|
||||
})
|
||||
if idx == 0 {
|
||||
idx = 1
|
||||
}
|
||||
for i := idx; i < len(cb.LineIndex.Offsets); i++ {
|
||||
cb.LineIndex.Offsets[i] += int32(offsetShift)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user