Merge pull request #2262 from Koranir/text-input-disable-select
Allow disabled `TextInput` to still be interacted with
This commit is contained in:
commit
8d826cc662
1 changed files with 28 additions and 19 deletions
|
|
@ -395,11 +395,11 @@ where
|
||||||
position,
|
position,
|
||||||
);
|
);
|
||||||
|
|
||||||
let is_cursor_visible = ((focus.now - focus.updated_at)
|
let is_cursor_visible = !is_disabled
|
||||||
.as_millis()
|
&& ((focus.now - focus.updated_at).as_millis()
|
||||||
/ CURSOR_BLINK_INTERVAL_MILLIS)
|
/ CURSOR_BLINK_INTERVAL_MILLIS)
|
||||||
% 2
|
% 2
|
||||||
== 0;
|
== 0;
|
||||||
|
|
||||||
let cursor = if is_cursor_visible {
|
let cursor = if is_cursor_visible {
|
||||||
Some((
|
Some((
|
||||||
|
|
@ -531,12 +531,9 @@ where
|
||||||
fn diff(&self, tree: &mut Tree) {
|
fn diff(&self, tree: &mut Tree) {
|
||||||
let state = tree.state.downcast_mut::<State<Renderer::Paragraph>>();
|
let state = tree.state.downcast_mut::<State<Renderer::Paragraph>>();
|
||||||
|
|
||||||
// Unfocus text input if it becomes disabled
|
// Stop pasting if input becomes disabled
|
||||||
if self.on_input.is_none() {
|
if self.on_input.is_none() {
|
||||||
state.last_click = None;
|
|
||||||
state.is_focused = None;
|
|
||||||
state.is_pasting = None;
|
state.is_pasting = None;
|
||||||
state.is_dragging = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -597,11 +594,7 @@ where
|
||||||
| Event::Touch(touch::Event::FingerPressed { .. }) => {
|
| Event::Touch(touch::Event::FingerPressed { .. }) => {
|
||||||
let state = state::<Renderer>(tree);
|
let state = state::<Renderer>(tree);
|
||||||
|
|
||||||
let click_position = if self.on_input.is_some() {
|
let click_position = cursor.position_over(layout.bounds());
|
||||||
cursor.position_over(layout.bounds())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
state.is_focused = if click_position.is_some() {
|
state.is_focused = if click_position.is_some() {
|
||||||
state.is_focused.or_else(|| {
|
state.is_focused.or_else(|| {
|
||||||
|
|
@ -747,10 +740,6 @@ where
|
||||||
let state = state::<Renderer>(tree);
|
let state = state::<Renderer>(tree);
|
||||||
|
|
||||||
if let Some(focus) = &mut state.is_focused {
|
if let Some(focus) = &mut state.is_focused {
|
||||||
let Some(on_input) = &self.on_input else {
|
|
||||||
return event::Status::Ignored;
|
|
||||||
};
|
|
||||||
|
|
||||||
let modifiers = state.keyboard_modifiers;
|
let modifiers = state.keyboard_modifiers;
|
||||||
focus.updated_at = Instant::now();
|
focus.updated_at = Instant::now();
|
||||||
|
|
||||||
|
|
@ -774,6 +763,10 @@ where
|
||||||
if state.keyboard_modifiers.command()
|
if state.keyboard_modifiers.command()
|
||||||
&& !self.is_secure =>
|
&& !self.is_secure =>
|
||||||
{
|
{
|
||||||
|
let Some(on_input) = &self.on_input else {
|
||||||
|
return event::Status::Ignored;
|
||||||
|
};
|
||||||
|
|
||||||
if let Some((start, end)) =
|
if let Some((start, end)) =
|
||||||
state.cursor.selection(&self.value)
|
state.cursor.selection(&self.value)
|
||||||
{
|
{
|
||||||
|
|
@ -798,6 +791,10 @@ where
|
||||||
if state.keyboard_modifiers.command()
|
if state.keyboard_modifiers.command()
|
||||||
&& !state.keyboard_modifiers.alt() =>
|
&& !state.keyboard_modifiers.alt() =>
|
||||||
{
|
{
|
||||||
|
let Some(on_input) = &self.on_input else {
|
||||||
|
return event::Status::Ignored;
|
||||||
|
};
|
||||||
|
|
||||||
let content = match state.is_pasting.take() {
|
let content = match state.is_pasting.take() {
|
||||||
Some(content) => content,
|
Some(content) => content,
|
||||||
None => {
|
None => {
|
||||||
|
|
@ -841,6 +838,10 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(text) = text {
|
if let Some(text) = text {
|
||||||
|
let Some(on_input) = &self.on_input else {
|
||||||
|
return event::Status::Ignored;
|
||||||
|
};
|
||||||
|
|
||||||
state.is_pasting = None;
|
state.is_pasting = None;
|
||||||
|
|
||||||
if let Some(c) =
|
if let Some(c) =
|
||||||
|
|
@ -869,6 +870,10 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
keyboard::Key::Named(key::Named::Backspace) => {
|
keyboard::Key::Named(key::Named::Backspace) => {
|
||||||
|
let Some(on_input) = &self.on_input else {
|
||||||
|
return event::Status::Ignored;
|
||||||
|
};
|
||||||
|
|
||||||
if modifiers.jump()
|
if modifiers.jump()
|
||||||
&& state.cursor.selection(&self.value).is_none()
|
&& state.cursor.selection(&self.value).is_none()
|
||||||
{
|
{
|
||||||
|
|
@ -893,6 +898,10 @@ where
|
||||||
update_cache(state, &self.value);
|
update_cache(state, &self.value);
|
||||||
}
|
}
|
||||||
keyboard::Key::Named(key::Named::Delete) => {
|
keyboard::Key::Named(key::Named::Delete) => {
|
||||||
|
let Some(on_input) = &self.on_input else {
|
||||||
|
return event::Status::Ignored;
|
||||||
|
};
|
||||||
|
|
||||||
if modifiers.jump()
|
if modifiers.jump()
|
||||||
&& state.cursor.selection(&self.value).is_none()
|
&& state.cursor.selection(&self.value).is_none()
|
||||||
{
|
{
|
||||||
|
|
@ -1111,7 +1120,7 @@ where
|
||||||
) -> mouse::Interaction {
|
) -> mouse::Interaction {
|
||||||
if cursor.is_over(layout.bounds()) {
|
if cursor.is_over(layout.bounds()) {
|
||||||
if self.on_input.is_none() {
|
if self.on_input.is_none() {
|
||||||
mouse::Interaction::NotAllowed
|
mouse::Interaction::Idle
|
||||||
} else {
|
} else {
|
||||||
mouse::Interaction::Text
|
mouse::Interaction::Text
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue