Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextInput view: UI does not react when updating buffer value to previous value entered #789

Open
sexnine opened this issue Mar 11, 2025 · 0 comments

Comments

@sexnine
Copy link
Contributor

sexnine commented Mar 11, 2025

When the signal that serves as the value for a TextInput is updated, if the value it was last set to by method of user input is the same, the UI does not react.

This is due to TextInput.buffer.last_buffer only being set on user input and an optimization where request_layout is not called when the last buffer and the current buffer are the same:

floem/src/views/text_input.rs

Lines 1044 to 1060 in 4bf974c

fn update(&mut self, cx: &mut UpdateCx, state: Box<dyn Any>) {
if let Ok(state) = state.downcast::<(String, bool)>() {
let (value, is_focused) = *state;
// Only update recomputation if the state has actually changed
if self.is_focused != is_focused || value != self.buffer.last_buffer {
if is_focused && !cx.app_state.is_active(&self.id) {
self.selection = None;
self.cursor_glyph_idx = self.buffer.with_untracked(|buf| buf.len());
}
self.is_focused = is_focused;
self.id.request_layout();
}
} else {
eprintln!("downcast failed");
}
}

My use case for this is listening to arrow key up/down events and increasing the value in the TextInput accordingly. As a temporary fix, I am calling request_layout myself in that event handler when I update the value.

Demo of issue with my use case:

upnp_3cHDqTShhs.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant