Skip to content

Commit 8776cfc

Browse files
committed
Update download progress with a mark
1 parent 7a5f145 commit 8776cfc

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/tab.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ impl Tab {
534534
url: Url,
535535
mut stream: T,
536536
) -> anyhow::Result<()> {
537-
// FIXME: iter moves
538537
let d_path = Self::download_path(&url)?;
539538

540539
let mut buffer = Vec::with_capacity(8192);
@@ -549,7 +548,11 @@ impl Tab {
549548
ctx.insert_paragraph(
550549
&mut text_iter,
551550
"to interrupt the download, leave this page\n",
551+
552552
);
553+
554+
let mark = ctx.text_buffer.create_mark(None, &text_iter, true);
555+
553556
ctx.insert_paragraph(&mut text_iter, "downloaded\t KB\n");
554557

555558
let mut file = File::create(&d_path).await?;
@@ -560,13 +563,11 @@ impl Tab {
560563
file.write_all(&buffer[..n]).await?;
561564
read += n;
562565
debug!("lines {}", ctx.text_buffer.line_count());
563-
let old_line_iter = ctx
564-
.text_buffer
565-
.iter_at_line(ctx.text_buffer.line_count() - 2);
566+
let mut progress_info_iter = ctx.text_buffer.iter_at_mark(&mark);
566567
ctx.text_buffer
567-
.delete(&mut old_line_iter.unwrap(), &mut ctx.text_buffer.end_iter());
568+
.delete(&mut progress_info_iter, &mut ctx.text_buffer.end_iter());
568569
ctx.insert_paragraph(
569-
&mut old_line_iter.unwrap(),
570+
&mut progress_info_iter,
570571
&format!("downloaded\t {}KB\n", read / 1000),
571572
);
572573
}

0 commit comments

Comments
 (0)