[BUG] TextArea text entry slows down as associated sibling TextView content increases
- Dominant language
- Rust
- Stars
- 4.8k
- Forks
- 270
- Avg merge
- 5d 19h
- Merged PRs (30d)
- 2
Description
On macOS 12.4, I've taken the TextView example, put the TextView into a LinearLayout, and then added a default TextArea as a second child. When the TextView has a small string, typing into the TextArea is fast. When the TextView's static content is big, however, typing is laggy.
Here's the code:
```
fn main() {
// Read some long text from a file.
// let content = include_str!("../marktwainworks.txt");
let content = include_str!("../norvig1mb.txt");
// let content = include_str!("../README.md");
let mut siv = cursive::default();
// We can quit by pressing q
siv.add_global_callback('q', |s| s.quit());
// The text is too long to fit on a line, so the view will wrap lines,
// and will adapt to the terminal size.
siv.add_fullscreen_layer(
Dialog::around(LinearLayout::vertical()
.child(Panel::new(
TextView::new(content)
.scrollable()
.wrap_with(OnEventView::new)
.on_pre_event_inner(Key::PageUp, |v, _| {
let scroller = v.get_scroller_mut();
if scroller.can_scroll_up() {
scroller.scroll_up(
scroller.last_outer_size().y.saturating_sub(1),
);
}
Some(EventResult::Consumed(None))
})
.on_pre_event_inner(Key::PageDown, |v, _| {
let scroller = v.get_scroller_mut();
if scroller.can_scroll_down() {
scroller.scroll_down(
scroller.last_outer_size().y.saturating_sub(1),
);
}
Some(EventResult::Consumed(None))
}),
))
.child(TextArea::new())
)
.title("Unicode and wide-character support")
// This is the alignment for the button
.h_align(HAlign::Center)
.button("Quit", |s| s.quit()),
);
// Show a popup on top of the view.
siv.add_layer(Dialog::info(
"Try resizing the terminal!\n(Press 'q' to \
quit when you're done.)",
));
siv.run();
}
```
The 1mb "Norvig" file referenced above is the first 1MB of Peter Norvig's [big.txt](https://norvig.com/big.txt). The collected works of Mark Twain come from Project Gutenberg and are ~15MB (https://www.gutenberg.org/cache/epub/3200/pg3200.txt). The "README.md" file, in contrast, is only 6KB.
With the README in the TextView, there's no noticeable lag for input into the TextArea. With the 1MB file there is. With the 15MB file, it's pretty bad.
**Expected behavior**
I'd expect that typing into the TextArea would never be laggy with the code above, regardless of the content in the associated TextView, as the view is not changing while typing into the TextArea. It seems like the TextView is being repainted, possibly with some repeated calculation (to compute the rows?).
**Environment**
* Operating system used: macOS 12.4, Monterrey
* Backend used: ncurses (I think)
* Current locale (run `locale` in a terminal)
```
jon@Lucretius % locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL=
```
* Cursive version (from crates.io, from git, ...): 0.18.0
Thank you!
Contributor guide
Assessment
This issue has not been assessed yet.