feat: virtual scrolling with chunked buffer for large files
- Add ChunkedBuffer for 64KB chunked file access with dirty-chunk eviction protection - Add LineIndex for precise byte-offset-to-line-number mapping - Refactor IO task system with context cancellation, typed priorities, and new task types (ReadChunk, BuildLineIndex, StatFile) - Add ReadFileAt to FileSystem interface (mock + real implementations) - Integrate virtual scrolling into editor layout - Add comprehensive tests for chunked buffer eviction, dirty-chunk safety, and full edit lifecycle
This commit is contained in:
@@ -181,6 +181,34 @@ func (fs *FileSystem) ReadFile(path string) ([]byte, error) {
|
||||
return content, nil
|
||||
}
|
||||
|
||||
// ReadFileAt reads a specific range of bytes from a file at the given path.
|
||||
func (fs *FileSystem) ReadFileAt(path string, offset, size int) ([]byte, error) {
|
||||
fs.mu.Lock()
|
||||
|
||||
if fs.delay > 0 {
|
||||
fs.mu.Unlock()
|
||||
time.Sleep(fs.delay)
|
||||
fs.mu.Lock()
|
||||
}
|
||||
|
||||
f, ok := fs.files[path]
|
||||
if !ok {
|
||||
fs.mu.Unlock()
|
||||
return nil, fmt.Errorf("file not found: %s", path)
|
||||
}
|
||||
if offset >= len(f.Content) {
|
||||
fs.mu.Unlock()
|
||||
return []byte{}, nil
|
||||
}
|
||||
end := offset + size
|
||||
if end > len(f.Content) {
|
||||
end = len(f.Content)
|
||||
}
|
||||
content := append([]byte(nil), f.Content[offset:end]...)
|
||||
fs.mu.Unlock()
|
||||
return content, nil
|
||||
}
|
||||
|
||||
// WriteFile writes or replaces the content of a file at the given path.
|
||||
// This is the non-atomic path — use WriteFileAtomic for safety.
|
||||
func (fs *FileSystem) WriteFile(path string, content []byte) error {
|
||||
|
||||
Reference in New Issue
Block a user