WIP baseline: Termux open-file bridge + word-wrap-aware viewport/scroll
- JNI: open_file_in_termux via ACTION_SEND intent (text/plain + file:// uri), global context ref kept from registerFragment - impl_android.go: OpenFile(path) attaches current thread if needed - NewLogic takes openfunc; State.open + ui.OpenFile now func(string) - ChunkedBuffer.VisibleByteRange: word-wrap path using GlyphLayout.VisualLineStarts (+byteOffset, lineHeight, visual index param) - GlyphLayout gains LineHeight; drawWrappedText records VisualLineStarts - WordWrap default true; State.ByteOffset tracks first visible line - types: VisualLineIndex - scroll_fix_test.go (new) - debug prints left in place (WIP; cleanup in later phase)
This commit is contained in:
+10
-10
@@ -58,9 +58,9 @@ const (
|
||||
TypeStatFile
|
||||
TypeBuildLineIndex
|
||||
TypeWriteFile
|
||||
TypeBuildIndex
|
||||
// Browser task types
|
||||
TypeReadDir
|
||||
TypeBuildIndex
|
||||
TypeLoadIndex
|
||||
TypeLoadPages
|
||||
TypeStatDir
|
||||
@@ -85,10 +85,10 @@ func (t TaskType) String() string {
|
||||
return "build_line_index"
|
||||
case TypeWriteFile:
|
||||
return "write_file"
|
||||
case TypeReadDir:
|
||||
return "read_dir"
|
||||
case TypeBuildIndex:
|
||||
return "build_index"
|
||||
case TypeReadDir:
|
||||
return "read_dir"
|
||||
case TypeLoadIndex:
|
||||
return "load_index"
|
||||
case TypeLoadPages:
|
||||
@@ -307,14 +307,14 @@ func (t *BuildIndexTask) Context() context.Context { return t.ctx }
|
||||
func (t *BuildIndexTask) Timeout() time.Duration { return 5 * time.Second }
|
||||
func (t *BuildIndexTask) Cancel() { if t.cancel != nil { t.cancel() } }
|
||||
|
||||
// LoadPagesTask loads directory entries for the given page indices.
|
||||
// LoadPagesTask loads specific pages from a directory index.
|
||||
type LoadPagesTask struct {
|
||||
taskID string
|
||||
Dir string
|
||||
PageIdxs []int
|
||||
FS FileSystem
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
taskID string
|
||||
Dir string
|
||||
PageIdxs []int
|
||||
FS FileSystem
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
// NewLoadPagesTask creates a new LoadPagesTask.
|
||||
|
||||
@@ -29,6 +29,25 @@ func NewLineIndex(offsets []int32, mtime int64, size int64) *LineIndex {
|
||||
}
|
||||
}
|
||||
|
||||
// VisualLineIndex maps visual line numbers (after wrapping) to byte offsets.
|
||||
// Built as a background task, cached on disk, and keyed by wrapWidth.
|
||||
type VisualLineIndex struct {
|
||||
Offsets []int32 // byte offset of each visual line start
|
||||
WrapWidth int // wrap width in pixels (or Dp) used for this index
|
||||
Mtime int64
|
||||
Size int64
|
||||
}
|
||||
|
||||
// NewVisualLineIndex creates a VisualLineIndex from a list of byte offsets.
|
||||
func NewVisualLineIndex(offsets []int32, wrapWidth int, mtime int64, size int64) *VisualLineIndex {
|
||||
return &VisualLineIndex{
|
||||
Offsets: offsets,
|
||||
WrapWidth: wrapWidth,
|
||||
Mtime: mtime,
|
||||
Size: size,
|
||||
}
|
||||
}
|
||||
|
||||
// LineCount returns the number of lines in the index.
|
||||
func (li *LineIndex) LineCount() int {
|
||||
return len(li.Offsets)
|
||||
@@ -43,6 +62,34 @@ func (li *LineIndex) ByteOffset(line int) int {
|
||||
return int(li.Offsets[line])
|
||||
}
|
||||
|
||||
// FindLogicalLineForByteOffset finds which logical line contains the given byte offset.
|
||||
// Returns the line number, or -1 if not found.
|
||||
func (li *LineIndex) FindLogicalLineForByteOffset(byteOffset int) int {
|
||||
if len(li.Offsets) == 0 {
|
||||
return -1
|
||||
}
|
||||
|
||||
// Binary search to find the line that contains this byte offset
|
||||
low, high := 0, len(li.Offsets)-1
|
||||
for low <= high {
|
||||
mid := (low + high) / 2
|
||||
midOffset := int(li.Offsets[mid])
|
||||
|
||||
if byteOffset >= midOffset {
|
||||
// This line starts at or before our byte offset
|
||||
// Check if the next line starts after our byte offset
|
||||
if mid == len(li.Offsets)-1 || int(li.Offsets[mid+1]) > byteOffset {
|
||||
return mid // Found the line
|
||||
}
|
||||
low = mid + 1
|
||||
} else {
|
||||
high = mid - 1
|
||||
}
|
||||
}
|
||||
|
||||
return -1 // Not found
|
||||
}
|
||||
|
||||
// String returns a string representation of the LineIndex.
|
||||
func (li *LineIndex) String() string {
|
||||
return fmt.Sprintf("LineIndex{lines=%d, size=%d, mtime=%d}", len(li.Offsets), li.Size, li.Mtime)
|
||||
|
||||
Reference in New Issue
Block a user