Set maxlength on EditView
- Dominant language
- Rust
- Stars
- 4.8k
- Forks
- 270
- Avg merge
- 5d 19h
- Merged PRs (30d)
- 2
Description
I have a current application where I want to insert a number (u32) in a EditView but with limited space. I know that excact, maximum length (10) and dont want the cursor to scroll to position 11, when I type in more that 10 characters, because the first one then disappears.
I tried to solve it via callbacks
```
EditView::new()
.on_edit(move |cursive: &mut Cursive, s: &str, cur: usize| {
cursive.call_on_id("comid", |view: &mut EditView| {
view.set_cursor(cmp::min(cur, 9));
});
})
.with_id("comid")
.fixed_width(10)
````
but no way, even worse, it will insert the characters at the current posotion, resulting in shifting all the content to the right.
I understand, that this is a desired behavoir for any text, but not in my application.
So i request two (and ½) changes:
- [ ] Add a method to set the maximum length of a editview to not let the cursor go out of this range
- [ ] Add an option to replace instead of insert content in a textview
- [ ] (optional) listen on the Insert key to toggle the replace/insert behavoir
Contributor guide
Assessment
This issue has not been assessed yet.