diff --git a/Cargo.lock b/Cargo.lock index fe9084e..a1f68b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -948,9 +948,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "foldhash" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" [[package]] name = "font-kit" diff --git a/Cargo.toml b/Cargo.toml index fa559ed..babe7af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ ratatui = { git = "https://github.com/itsjunetime/ratatui.git" } # ratatui = { path = "./ratatui/ratatui" } # We're using this to have the vb64 feature (for faster base64 encoding, since that does take up a good bit of time when converting images to the `Protocol`. It also just includes a few more features that I'm waiting on main to upstream ratatui-image = { git = "https://github.com/itsjunetime/ratatui-image.git", branch = "vb64_on_personal", default-features = false } -# ratatui-image = { path = "./ratatui-image", features = ["vb64"], default-features = false } +# ratatui-image = { path = "./ratatui-image", default-features = false } crossterm = { version = "0.28.1", features = ["event-stream"] } image = { version = "0.25.1", features = ["pnm", "rayon", "png"], default-features = false } notify = { version = "8.0.0", features = ["crossbeam-channel"] } diff --git a/benches/utils.rs b/benches/utils.rs index aba8776..86230ed 100644 --- a/benches/utils.rs +++ b/benches/utils.rs @@ -77,6 +77,14 @@ pub fn start_rendering_loop( width: columns * FONT_SIZE.0 }; + let main_area = Rect { + x: 0, + y: 0, + width: columns - 2, + height: rows - 6 + }; + to_render_tx.send(RenderNotif::Area(main_area)).unwrap(); + std::thread::spawn(move || { start_rendering( &str_path, @@ -87,14 +95,6 @@ pub fn start_rendering_loop( ) }); - let main_area = Rect { - x: 0, - y: 0, - width: columns - 2, - height: rows - 6 - }; - to_render_tx.send(RenderNotif::Area(main_area)).unwrap(); - let from_render_rx = from_render_rx.into_stream(); (from_render_rx, to_render_tx) } diff --git a/src/renderer.rs b/src/renderer.rs index 246ec50..87c95e9 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -210,6 +210,7 @@ pub fn start_rendering( }}; } + let any_not_searched = rendered.iter().any(|r| r.num_search_found.is_none()); let (left, right) = rendered.split_at_mut(start_point); // This is our iterator over all the pages we want to look at and render. It uses this @@ -235,7 +236,12 @@ pub fn start_rendering( // If they haven't limited it, and we DO have a search term we need to look // for, just do 20 so that we don't dramatically slow down the search process // since they've specifically initiated that and so we want it to take priority - (PrerenderLimit::All, Some(_)) => 20 + (PrerenderLimit::All, Some(_)) => + if any_not_searched { + 20 + } else { + n_pages + }, }); let area_w = f32::from(area.width) * f32::from(col_w); @@ -281,21 +287,6 @@ pub fn start_rendering( // If that fn returned Some, that means it needed to be re-rendered for some // reason or another, so we're sending it here Ok(ctx) => { - let num_results = ctx.result_rects.len(); - // If we previously successfully rendered it and it has no results last - // time as well, don't send another new image - if rendered.num_search_found == Some(0) - && num_results == 0 && rendered.successful - { - continue; - } - - // we make a potentially incorrect assumption here that writing the context - // to a png won't fail, and mark that it all rendered correctly here before - // spawning off the thread to do so and send it. - rendered.num_search_found = Some(num_results); - rendered.successful = true; - let w = ctx.pixmap.width(); let h = ctx.pixmap.height(); let cap = (w * h * u32::from(ctx.pixmap.n())) as usize + 16; @@ -305,6 +296,9 @@ pub fn start_rendering( continue; }; + rendered.num_search_found = Some(ctx.result_rects.len()); + rendered.successful = true; + sender.send(Ok(RenderInfo::Page(PageInfo { img_data: ImageData { pixels, @@ -336,9 +330,8 @@ pub fn start_rendering( // And we only want to take max SEARCH_AT_TIME of them since we don't want // to block on this for *too* long .take(SEARCH_AT_TIME) - // We want to remove all the ones that we've already determined did not - // contain the current term... - .filter(|(_, r)| r.num_search_found.is_none_or(|n| n > 0)) + // And we only want the ones that we still don't know about... + .filter(|(_, r)| r.num_search_found.is_none()) // And then adjust the index to be correct for the actual page number .map(|(idx, r)| (idx + search_start, r)); @@ -374,6 +367,10 @@ pub fn start_rendering( // now, we want to check if we've gone past the end - if so, we go back to the // beginning so we can get the pages before the current one. if search_start > n_pages { + if start_point == 0 { + break; + } + search_start = 0; } else if ((search_start - SEARCH_AT_TIME) + 1..search_start) .contains(&start_point) @@ -392,6 +389,13 @@ pub fn start_rendering( } } + // So now we've just *searched* all the pages but not necessarily rendered all of them. + // So if there are any we have yet to render, we need to loop back to the beginning of + // this loop to continue rendering all of them + if rendered.iter().any(|r| !r.successful) { + continue; + } + // Then once we've rendered all these pages, wait until we get another notification // that this doc needs to be reloaded // This once returned None despite the main thing being still connected (I think, at