Improvements for large files

This commit is contained in:
Jeremy Soller 2023-11-02 10:02:07 -06:00
parent 90d2fead9c
commit c0e290f8a7
No known key found for this signature in database
GPG key ID: DCFCA852D3906975
2 changed files with 19 additions and 22 deletions

12
Cargo.lock generated
View file

@ -851,7 +851,7 @@ dependencies = [
[[package]]
name = "cosmic-text"
version = "0.10.0"
source = "git+https://github.com/pop-os/cosmic-text?branch=vi-editor#ca35e1f429af2ac3121f8afb0991963820dbd1bf"
source = "git+https://github.com/pop-os/cosmic-text?branch=vi-editor#6196d72266a99730ecf4d77d5e8d44dda86cfe1e"
dependencies = [
"fontdb 0.15.0",
"libm",
@ -4227,7 +4227,7 @@ dependencies = [
[[package]]
name = "taffy"
version = "0.3.11"
source = "git+https://github.com/DioxusLabs/taffy#278f5e39b6edcd6f5a3ee9e10da81c0bfb0b3124"
source = "git+https://github.com/DioxusLabs/taffy#6d7f3cf86a923a02c9d7b67053096a8b3486f15f"
dependencies = [
"arrayvec",
"grid",
@ -5532,18 +5532,18 @@ checksum = "dd15f8e0dbb966fd9245e7498c7e9e5055d9e5c8b676b95bd67091cd11a1e697"
[[package]]
name = "zerocopy"
version = "0.7.21"
version = "0.7.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "686b7e407015242119c33dab17b8f61ba6843534de936d94368856528eae4dcc"
checksum = "e50cbb27c30666a6108abd6bc7577556265b44f243e2be89a8bc4e07a528c107"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.21"
version = "0.7.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "020f3dfe25dfc38dfea49ce62d5d45ecdd7f0d8a724fa63eb36b6eba4ec76806"
checksum = "a25f293fe55f0a48e7010d65552bb63704f6ceb55a1a385da10d41d8f78e4a3d"
dependencies = [
"proc-macro2",
"quote",

View file

@ -160,12 +160,11 @@ where
fn layout(&self, _renderer: &Renderer, limits: &layout::Limits) -> layout::Node {
let limits = limits.width(Length::Fill).height(Length::Fill);
//TODO: allow lazy shape
let mut editor = self.editor.lock().unwrap();
//TODO: set size?
editor
.borrow_with(&mut FONT_SYSTEM.lock().unwrap())
.buffer_mut()
.shape_until(i32::max_value());
.shape_as_needed();
let mut layout_lines = 0;
for line in editor.buffer().lines.iter() {
@ -296,19 +295,17 @@ where
let start_line = start_line_opt.unwrap_or(end_line);
let lines = editor.buffer().lines.len();
let start_y = (start_line * image_h as usize) / lines;
let end_y = (end_line * image_h as usize) / lines;
if end_y > start_y {
draw_rect(
buffer,
image_w,
image_h,
image_w - scrollbar_w,
start_y as i32,
scrollbar_w,
(end_y - start_y) as i32,
0x40FFFFFF,
);
}
let end_y = ((end_line * image_h as usize) / lines).max(start_y + 1);
draw_rect(
buffer,
image_w,
image_h,
image_w - scrollbar_w,
start_y as i32,
scrollbar_w,
end_y as i32 - start_y as i32,
0x40FFFFFF,
);
}
}