Skip to content

Commit 4b7f080

Browse files
author
Noam Lewis
committed
fix seek
1 parent c66a13f commit 4b7f080

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/virtual_file.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,22 @@ impl VirtualFile {
126126

127127
// Move the anchor to be as near as possible to the requested seek position:
128128
for (index, line) in self.chunk_lines.iter().enumerate() {
129+
log!(
130+
"seek: Checking line[{:?}] loc: {:?} >= offset {:?}",
131+
index,
132+
line.loaded_loc,
133+
offset
134+
);
135+
self.line_anchor = index.try_into().unwrap();
129136
if line
130137
.loaded_loc
131138
.map(|loc| loc.loaded_offset >= offset)
132139
.unwrap_or(false)
133140
{
134-
self.line_anchor = index.try_into().unwrap();
135141
break;
136142
}
137143
}
144+
log!("seek: Set line_anchor = {:?}", self.line_anchor);
138145
}
139146

140147
fn load_lines(&mut self, offset: u64) {
@@ -500,16 +507,13 @@ mod tests {
500507
log!("line_index: {:?}", line_index);
501508
assert_eq!(vf.get(&line_index).unwrap().str(), "");
502509
let line_index = vf.prev_line(&line_index).unwrap();
503-
log!("line_index: {:?}", line_index);
504-
assert_eq!(vf.get(&line_index).unwrap().str(), "");
505-
let line_index = vf.prev_line(&line_index).unwrap();
506510
assert_eq!(vf.get(&line_index).unwrap().str(), "line3");
507511
let line_index = vf.prev_line(&line_index).unwrap();
508512
assert_eq!(vf.get(&line_index).unwrap().str(), "line2");
509513
let line_index = vf.prev_line(&line_index).unwrap();
510514
assert_eq!(vf.get(&line_index).unwrap().str(), "line1");
511515
let line_index = vf.prev_line(&line_index).unwrap();
512-
assert_eq!(vf.get(&line_index).unwrap().str(), "");
516+
assert_eq!(vf.get(&line_index).unwrap().str(), "line1");
513517
let last = vf.prev_line(&line_index);
514518
assert_eq!(last, Some(line_index));
515519
}

0 commit comments

Comments
 (0)