use std::{cell::RefCell, collections::HashMap, rc::Rc, time::Duration};
use arc_motion::{
BlurFallback, CubicBezier, arc_spring, arc_spring_with_options, arc_transition,
is_reduced_motion, motion_now, spring::SpringOptions,
};
use arc_tokens::{ActiveArcTheme as _, Radii, Spacing, Typography, oklab_mix};
use gpui_kit::{
App, Bounds, ElementId, Entity, Focusable as _, IntoElement, KeyDownEvent, MouseButton,
ParentElement, Pixels, RenderOnce, Role, SharedString, Styled, TestSupportExt as _, Window,
assets::IconName,
base::StyledExt as _,
canvas,
component::{
Icon,
input::{Input as KitInput, InputState},
},
div,
prelude::*,
px,
};
use super::field_message::render_field_message;
type TagInputChangeHandler = Rc<dyn Fn(&[SharedString], &mut Window, &mut App)>;
type TagRectMap = Rc<RefCell<HashMap<SharedString, (f32, f32, f32, f32)>>>;
pub const TAG_DUPLICATE_PULSE_SECS: f64 = 0.36;
pub const TAG_INPUT_MIN_CONTENT_H_PX: f32 = 34.0;
pub fn tag_duplicate_pulse_scale(elapsed: f64, reduced: bool) -> f32 {
if reduced || !(0.0..TAG_DUPLICATE_PULSE_SECS).contains(&elapsed) {
return 1.0;
}
let norm = (elapsed / TAG_DUPLICATE_PULSE_SECS).clamp(0.0, 1.0) as f32;
let ease = CubicBezier::new(0.65, 0.0, 0.35, 1.0);
let wave = if norm < 0.5 {
ease.sample(norm * 2.0)
} else {
1.0 - ease.sample((norm - 0.5) * 2.0)
};
1.0 + 0.06 * wave
}
pub fn tag_placeholder_sample(elapsed: f64, reduced: bool) -> (f32, f32) {
if reduced {
let t = (elapsed / 0.12).clamp(0.0, 1.0) as f32;
return (t, 0.0);
}
let t = (elapsed / 0.24).clamp(0.0, 1.0) as f32;
let e = CubicBezier::new(0.16, 1.0, 0.3, 1.0).sample(t);
let blur = BlurFallback::evaluate(px(4.0 * (1.0 - e)), false);
(
(e * blur.opacity_multiplier).clamp(0.0, 1.0),
4.2 * (1.0 - e),
)
}
pub fn try_add_tag(
tags: &[SharedString],
draft: &str,
) -> Option<Result<Vec<SharedString>, SharedString>> {
let trimmed = draft.trim();
if trimmed.is_empty() {
return None;
}
let lower = trimmed.to_lowercase();
if let Some(existing) = tags.iter().find(|t| t.to_lowercase() == lower) {
return Some(Err(existing.clone()));
}
let mut next = tags.to_vec();
next.push(SharedString::from(trimmed.to_string()));
Some(Ok(next))
}
#[derive(Clone)]
struct TagInputInternal {
uncontrolled_tags: Vec<SharedString>,
picked: Option<SharedString>,
ring_seeded: bool,
last_ring_rect: Option<(f32, f32, f32, f32)>,
pulsed_tag: Option<(SharedString, f64)>,
empty_entered_at_secs: f64,
was_empty: bool,
last_draft: SharedString,
control_hovered: bool,
pressed_remove: Option<SharedString>,
measured_content_h: Rc<RefCell<Option<f32>>>,
content_bounds: Rc<RefCell<Option<Bounds<Pixels>>>>,
tag_rects: TagRectMap,
draft_input: Entity<InputState>,
}
impl TagInputInternal {
fn new(default_tags: Vec<SharedString>, now: f64, window: &mut Window, cx: &mut App) -> Self {
let draft_input = cx.new(|cx| InputState::new(window, cx));
let is_empty = default_tags.is_empty();
Self {
uncontrolled_tags: default_tags,
picked: None,
ring_seeded: false,
last_ring_rect: None,
pulsed_tag: None,
empty_entered_at_secs: now - 10.0,
was_empty: is_empty,
last_draft: "".into(),
control_hovered: false,
pressed_remove: None,
measured_content_h: Rc::new(RefCell::new(None)),
content_bounds: Rc::new(RefCell::new(None)),
tag_rects: Rc::new(RefCell::new(HashMap::new())),
draft_input,
}
}
}
#[derive(IntoElement)]
pub struct TagInput {
id: ElementId,
label: SharedString,
value: Option<Vec<SharedString>>,
default_value: Vec<SharedString>,
placeholder: SharedString,
description: Option<SharedString>,
disabled: bool,
width: Option<Pixels>,
on_value_change: Option<TagInputChangeHandler>,
}
impl TagInput {
pub fn new(id: impl Into<ElementId>, label: impl Into<SharedString>) -> Self {
Self {
id: id.into(),
label: label.into(),
value: None,
default_value: Vec::new(),
placeholder: "Add a tag".into(),
description: None,
disabled: false,
width: None,
on_value_change: None,
}
}
pub fn value<I, S>(mut self, value: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<SharedString>,
{
self.value = Some(value.into_iter().map(Into::into).collect());
self
}
pub fn default_value<I, S>(mut self, value: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<SharedString>,
{
self.default_value = value.into_iter().map(Into::into).collect();
self
}
pub fn placeholder(mut self, placeholder: impl Into<SharedString>) -> Self {
self.placeholder = placeholder.into();
self
}
pub fn description(mut self, description: impl Into<SharedString>) -> Self {
self.description = Some(description.into());
self
}
pub fn disabled(mut self, disabled: bool) -> Self {
self.disabled = disabled;
self
}
pub fn width(mut self, width: impl Into<Pixels>) -> Self {
self.width = Some(width.into());
self
}
pub fn on_value_change(
mut self,
handler: impl Fn(&[SharedString], &mut Window, &mut App) + 'static,
) -> Self {
self.on_value_change = Some(Rc::new(handler));
self
}
}
impl RenderOnce for TagInput {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let theme = cx.arc_theme().clone();
let colors = theme.colors;
let motion = theme.motion;
let reduced = is_reduced_motion(cx);
let now = motion_now(cx);
let initial_tags = self
.value
.clone()
.unwrap_or_else(|| self.default_value.clone());
let state_id =
ElementId::NamedChild(self.id.clone().into(), "__arc-tag-input-state".into());
let internal = window.use_keyed_state(state_id, cx, |window, cx| {
TagInputInternal::new(initial_tags.clone(), now, window, cx)
});
let tags: Vec<SharedString> = self
.value
.clone()
.unwrap_or_else(|| internal.read(cx).uncontrolled_tags.clone());
{
let d_in = internal.read(cx).draft_input.clone();
let raw_draft = d_in.read(cx).value().to_string();
let last_d = internal.read(cx).last_draft.clone();
if raw_draft.as_str() != last_d.as_ref() {
if raw_draft.ends_with(',') {
let candidate = raw_draft.trim_end_matches(',');
match try_add_tag(&tags, candidate) {
Some(Ok(next_tags)) => {
d_in.update(cx, |s, cx| s.set_value("", window, cx));
internal.update(cx, |s, _| {
s.uncontrolled_tags = next_tags.clone();
s.picked = None;
s.last_draft = "".into();
});
if let Some(cb) = &self.on_value_change {
cb(&next_tags, window, cx);
}
}
Some(Err(dup)) => {
d_in.update(cx, |s, cx| {
s.set_value(candidate.to_string(), window, cx);
});
internal.update(cx, |s, _| {
s.pulsed_tag = Some((dup, now));
s.last_draft = SharedString::from(candidate.to_string());
});
}
None => {
d_in.update(cx, |s, cx| s.set_value("", window, cx));
internal.update(cx, |s, _| {
s.last_draft = "".into();
});
}
}
} else {
internal.update(cx, |s, _| {
s.last_draft = SharedString::from(raw_draft);
s.picked = None;
});
}
}
}
let tags: Vec<SharedString> = self
.value
.clone()
.unwrap_or_else(|| internal.read(cx).uncontrolled_tags.clone());
let draft_str = internal.read(cx).draft_input.read(cx).value().to_string();
let is_empty = tags.is_empty() && draft_str.is_empty();
{
let target_ph = if tags.is_empty() {
self.placeholder.clone()
} else {
SharedString::default()
};
let d_in = internal.read(cx).draft_input.clone();
d_in.update(cx, |s, cx| {
s.set_placeholder(target_ph, window, cx);
});
}
{
let was_empty = internal.read(cx).was_empty;
if is_empty != was_empty {
internal.update(cx, |s, _| {
s.was_empty = is_empty;
if is_empty {
s.empty_entered_at_secs = now;
}
});
}
}
let snap = internal.read(cx).clone();
let active_pick: Option<SharedString> = snap.picked.clone().filter(|p| tags.contains(p));
let is_focused = snap
.draft_input
.read(cx)
.focus_handle(cx)
.is_focused(window);
let measured_h = snap
.measured_content_h
.borrow()
.map(|h| h.max(TAG_INPUT_MIN_CONTENT_H_PX));
let shell_h = arc_motion::arc_measured_spring(
(self.id.clone(), "control-h"),
measured_h,
TAG_INPUT_MIN_CONTENT_H_PX,
motion.spring.smooth,
window,
cx,
)
.max(TAG_INPUT_MIN_CONTENT_H_PX);
let active_rect = active_pick
.as_ref()
.and_then(|t| snap.tag_rects.borrow().get(t).copied())
.or(snap.last_ring_rect);
let has_ring = active_pick.is_some() && active_rect.is_some();
let ring_op = arc_transition(
(self.id.clone(), "ring-op"),
if has_ring { 1.0 } else { 0.0 },
if reduced {
motion.duration.instant
} else if has_ring {
motion.duration.fast
} else {
motion.duration.instant
},
motion.ease.standard,
window,
cx,
);
let (rx_t, ry_t, rw_t, rh_t) = active_rect.unwrap_or((7.0, 7.0, 64.0, 28.0));
let (ring_x, ring_y, ring_w, ring_h) = if reduced || !snap.ring_seeded || ring_op < 0.02 {
let _ = arc_spring_with_options(
(self.id.clone(), "ring-x"),
rx_t,
SpringOptions::new(motion.spring.morph).with_initial_value(rx_t),
window,
cx,
);
let _ = arc_spring_with_options(
(self.id.clone(), "ring-y"),
ry_t,
SpringOptions::new(motion.spring.morph).with_initial_value(ry_t),
window,
cx,
);
let _ = arc_spring_with_options(
(self.id.clone(), "ring-w"),
rw_t,
SpringOptions::new(motion.spring.morph).with_initial_value(rw_t),
window,
cx,
);
let _ = arc_spring_with_options(
(self.id.clone(), "ring-h"),
rh_t,
SpringOptions::new(motion.spring.morph).with_initial_value(rh_t),
window,
cx,
);
if has_ring && !snap.ring_seeded {
internal.update(cx, |s, _| {
s.ring_seeded = true;
s.last_ring_rect = Some((rx_t, ry_t, rw_t, rh_t));
});
} else if !has_ring && ring_op < 0.02 && snap.ring_seeded {
internal.update(cx, |s, _| s.ring_seeded = false);
}
(rx_t, ry_t, rw_t, rh_t)
} else {
internal.update(cx, |s, _| {
s.last_ring_rect = Some((rx_t, ry_t, rw_t, rh_t));
});
(
arc_spring(
(self.id.clone(), "ring-x"),
rx_t,
motion.spring.morph,
window,
cx,
),
arc_spring(
(self.id.clone(), "ring-y"),
ry_t,
motion.spring.morph,
window,
cx,
),
arc_spring(
(self.id.clone(), "ring-w"),
rw_t,
motion.spring.morph,
window,
cx,
),
arc_spring(
(self.id.clone(), "ring-h"),
rh_t,
motion.spring.morph,
window,
cx,
),
)
};
let empty_elapsed = (now - snap.empty_entered_at_secs).max(0.0);
let (ph_op, ph_y) = if is_empty {
if empty_elapsed < 0.25 {
window.request_animation_frame();
}
tag_placeholder_sample(empty_elapsed, reduced)
} else {
(0.0, 0.0)
};
let hover_p = arc_transition(
(self.id.clone(), "control-hover"),
if !self.disabled && !is_focused && snap.control_hovered {
1.0
} else {
0.0
},
if reduced {
Duration::ZERO
} else {
motion.duration.fast
},
motion.ease.standard,
window,
cx,
);
let border_color = if !self.disabled && is_focused {
colors.foreground
} else {
oklab_mix(colors.border_strong, colors.border, hover_p)
};
let content_h_ref = snap.measured_content_h.clone();
let content_b_ref = snap.content_bounds.clone();
let content_probe = canvas(
move |rect, window, _| {
*content_b_ref.borrow_mut() = Some(rect);
let h = f32::from(rect.size.height).max(TAG_INPUT_MIN_CONTENT_H_PX);
let prev = *content_h_ref.borrow();
*content_h_ref.borrow_mut() = Some(h);
if prev.is_none_or(|prev| (prev - h).abs() > 0.5) {
window.request_animation_frame();
}
},
|_, _, _, _| {},
)
.absolute()
.inset_0();
let disabled = self.disabled;
let tag_els = tags
.iter()
.map(|tag| {
let is_picked = active_pick.as_ref() == Some(tag);
let tag_op = arc_transition(
(self.id.clone(), format!("tag-op-{tag}")),
1.0,
if reduced {
motion.duration.instant
} else {
motion.duration.fast
},
motion.ease.enter,
window,
cx,
);
let blur = BlurFallback::evaluate(motion.blur.soft * (1.0 - tag_op), reduced);
let pulse_scale = if let Some((ref p_tag, started_at)) = snap.pulsed_tag
&& p_tag == tag
{
let el = (now - started_at).max(0.0);
if el < TAG_DUPLICATE_PULSE_SECS {
window.request_animation_frame();
}
tag_duplicate_pulse_scale(el, reduced)
} else {
1.0
};
let extra_px = ((pulse_scale - 1.0) * 18.0).max(0.0);
let rects_map = snap.tag_rects.clone();
let content_b_for_tag = snap.content_bounds.clone();
let tag_key = tag.clone();
let tag_probe = canvas(
move |rect, _, _| {
if let Some(cb) = *content_b_for_tag.borrow() {
let rel_x = f32::from(rect.origin.x - cb.origin.x);
let rel_y = f32::from(rect.origin.y - cb.origin.y);
let w = f32::from(rect.size.width);
let h = f32::from(rect.size.height);
rects_map
.borrow_mut()
.insert(tag_key.clone(), (rel_x, rel_y, w, h));
}
},
|_, _, _, _| {},
)
.absolute()
.inset_0();
let int_pick = internal.clone();
let int_rem = internal.clone();
let int_down = internal.clone();
let int_up = internal.clone();
let int_out = internal.clone();
let on_change = self.on_value_change.clone();
let cur_tags = tags.clone();
let tag_for_pick = tag.clone();
let tag_for_rem = tag.clone();
let tag_for_down = tag.clone();
let is_rem_pressed = snap.pressed_remove.as_ref() == Some(tag);
let rem_sz = if is_rem_pressed && !reduced {
21.0
} else {
22.0
};
let rem_hover_bg = colors.surface;
let rem_hover_fg = colors.foreground;
let rem_fg = if is_picked {
colors.foreground
} else {
colors.text_secondary
};
div()
.id(ElementId::NamedChild(
self.id.clone().into(),
SharedString::from(format!("tag-{tag}")),
))
.test_support()
.relative()
.flex_none()
.h(px(28.0 + extra_px))
.pl(px(9.0 + extra_px * 0.5))
.pr(px(4.0 + extra_px * 0.5))
.flex()
.flex_row()
.items_center()
.gap(px(3.0))
.rounded(Radii::PILL)
.border_1()
.border_color(if is_picked {
colors.accent
} else {
colors.border
})
.bg(if is_picked {
colors.accent_subtle
} else {
colors.surface_muted
})
.opacity((tag_op * blur.opacity_multiplier).clamp(0.0, 1.0))
.text_size(Typography::TEXT_SM)
.text_color(colors.foreground)
.when(!disabled, |this| this.cursor_pointer())
.on_click(move |_, window, cx| {
if disabled {
return;
}
let d_in = int_pick.read(cx).draft_input.clone();
d_in.update(cx, |s, cx| s.focus(window, cx));
int_pick.update(cx, |s, _| {
if s.picked.as_ref() == Some(&tag_for_pick) {
s.picked = None;
} else {
s.picked = Some(tag_for_pick.clone());
}
});
window.refresh();
})
.child(tag_probe)
.child(div().flex_none().whitespace_nowrap().child(tag.clone()))
.child(
div()
.id(ElementId::NamedChild(
self.id.clone().into(),
SharedString::from(format!("remove-{tag}")),
))
.test_support()
.role(Role::Button)
.aria_label(SharedString::from(format!("Remove {tag}")))
.on_click(move |_, window, cx| {
if disabled {
return;
}
let next_tags: Vec<SharedString> = cur_tags
.iter()
.filter(|&item| item != &tag_for_rem)
.cloned()
.collect();
let d_in = int_rem.read(cx).draft_input.clone();
d_in.update(cx, |s, cx| s.focus(window, cx));
int_rem.update(cx, |s, _| {
s.uncontrolled_tags = next_tags.clone();
s.picked = None;
s.pressed_remove = None;
});
if let Some(cb) = &on_change {
cb(&next_tags, window, cx);
}
window.refresh();
})
.w(px(rem_sz))
.h(px(rem_sz))
.flex_none()
.flex()
.items_center()
.justify_center()
.rounded(Radii::PILL)
.text_color(rem_fg)
.when(!disabled, |this| {
this.cursor_pointer()
.hover(move |s| s.bg(rem_hover_bg).text_color(rem_hover_fg))
})
.on_mouse_down(MouseButton::Left, move |_, window, cx| {
int_down.update(cx, |s, _| {
s.pressed_remove = Some(tag_for_down.clone());
});
window.refresh();
})
.on_mouse_up(MouseButton::Left, move |_, window, cx| {
int_up.update(cx, |s, _| s.pressed_remove = None);
window.refresh();
})
.on_mouse_up_out(MouseButton::Left, move |_, window, cx| {
int_out.update(cx, |s, _| s.pressed_remove = None);
window.refresh();
})
.child(Icon::new(IconName::X).text_size(px(13.0))),
)
.into_any_element()
})
.collect::<Vec<_>>();
let int_hover = internal.clone();
let int_focus_bg = internal.clone();
let int_key = internal.clone();
let tags_for_key = tags.clone();
let active_for_key = active_pick;
let on_change_key = self.on_value_change.clone();
let _ = (ph_op, ph_y);
let content_el = div()
.relative()
.w_full()
.min_h(px(TAG_INPUT_MIN_CONTENT_H_PX))
.p(px(7.0))
.flex()
.flex_row()
.flex_wrap()
.items_center()
.gap(px(6.0))
.child(content_probe)
.when(ring_op > 0.01, |this| {
this.child(
div()
.absolute()
.left(px(ring_x))
.top(px(ring_y))
.w(px(ring_w))
.h(px(ring_h))
.rounded(Radii::PILL)
.border_1()
.border_color(colors.accent)
.bg(colors.accent_subtle)
.opacity(ring_op),
)
})
.children(tag_els)
.child(
div()
.flex_1()
.min_w(px(96.0))
.h(px(28.0))
.flex()
.items_center()
.text_size(Typography::TEXT_SM)
.text_color(colors.foreground)
.child(
KitInput::new(&snap.draft_input)
.appearance(false)
.disabled(disabled)
.px(px(2.0))
.py(px(0.0))
.h(px(28.0))
.w_full(),
),
);
let control = div()
.id(ElementId::NamedChild(
self.id.clone().into(),
"control".into(),
))
.test_support()
.w_full()
.h(px(shell_h + 2.0))
.rounded(Radii::CONTROL)
.border_1()
.border_color(border_color)
.bg(colors.surface)
.opacity(if disabled { 0.5 } else { 1.0 })
.overflow_hidden()
.on_hover(move |hovered, window, cx| {
int_hover.update(cx, |s, _| s.control_hovered = *hovered);
window.refresh();
})
.on_click(move |_, window, cx| {
if !disabled {
let d_in = int_focus_bg.read(cx).draft_input.clone();
d_in.update(cx, |s, cx| s.focus(window, cx));
}
})
.on_key_down(move |event: &KeyDownEvent, window, cx| {
if disabled {
return;
}
let d_in = int_key.read(cx).draft_input.clone();
let cur_draft = d_in.read(cx).value().to_string();
let active_idx = active_for_key
.as_ref()
.and_then(|a| tags_for_key.iter().position(|t| t == a))
.unwrap_or(tags_for_key.len());
match event.keystroke.key.as_str() {
"enter" => {
let t_now = motion_now(cx);
match try_add_tag(&tags_for_key, &cur_draft) {
Some(Ok(next_tags)) => {
d_in.update(cx, |s, cx| s.set_value("", window, cx));
int_key.update(cx, |s, _| {
s.uncontrolled_tags = next_tags.clone();
s.picked = None;
s.last_draft = "".into();
});
if let Some(cb) = &on_change_key {
cb(&next_tags, window, cx);
}
window.refresh();
}
Some(Err(existing)) => {
int_key.update(cx, |s, _| {
s.pulsed_tag = Some((existing, t_now));
});
window.refresh();
}
None => {}
}
}
"backspace" | "delete" => {
if let Some(ref picked_tag) = active_for_key {
let next_tags: Vec<SharedString> = tags_for_key
.iter()
.filter(|&t| t != picked_tag)
.cloned()
.collect();
int_key.update(cx, |s, _| {
s.uncontrolled_tags = next_tags.clone();
s.picked = None;
});
if let Some(cb) = &on_change_key {
cb(&next_tags, window, cx);
}
window.refresh();
} else if event.keystroke.key.as_str() == "backspace"
&& cur_draft.is_empty()
&& let Some(last_tag) = tags_for_key.last()
{
let t = last_tag.clone();
int_key.update(cx, |s, _| {
s.picked = Some(t);
});
window.refresh();
}
}
"left" | "arrowleft"
if (cur_draft.is_empty() || active_for_key.is_some()) && active_idx > 0 =>
{
let prev_tag = tags_for_key[active_idx - 1].clone();
int_key.update(cx, |s, _| {
s.picked = Some(prev_tag);
});
window.refresh();
}
"right" | "arrowright" if active_for_key.is_some() => {
let next_pick = tags_for_key.get(active_idx + 1).cloned();
int_key.update(cx, |s, _| {
s.picked = next_pick;
});
window.refresh();
}
"escape" if active_for_key.is_some() => {
int_key.update(cx, |s, _| {
s.picked = None;
});
window.refresh();
}
_ => {}
}
})
.child(content_el);
let desc_id = ElementId::NamedChild(self.id.clone().into(), "description".into());
div()
.id(self.id)
.test_support()
.when_some(self.width, |this, w| this.w(w))
.when(self.width.is_none(), |this| this.w_full())
.flex()
.flex_col()
.child(
div()
.mb(Spacing::S2)
.text_size(Typography::TEXT_SM)
.font_medium()
.text_color(colors.foreground)
.child(self.label),
)
.child(control)
.child(render_field_message(
desc_id,
self.description,
false,
window,
cx,
))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn try_add_tag_rejects_empty_and_detects_case_insensitive_duplicates() {
let existing: Vec<SharedString> = vec!["Rust".into(), "GPUI".into()];
assert!(try_add_tag(&existing, " ").is_none());
assert_eq!(
try_add_tag(&existing, "rust"),
Some(Err(SharedString::from("Rust")))
);
assert_eq!(
try_add_tag(&existing, " Motion "),
Some(Ok(vec![
SharedString::from("Rust"),
SharedString::from("GPUI"),
SharedString::from("Motion")
]))
);
}
#[test]
fn tag_duplicate_pulse_peaks_at_1_06_and_settles_to_1_0() {
assert!((tag_duplicate_pulse_scale(0.0, false) - 1.0).abs() < 1e-4);
let peak = tag_duplicate_pulse_scale(TAG_DUPLICATE_PULSE_SECS * 0.5, false);
assert!((peak - 1.06).abs() < 1e-3);
assert!((tag_duplicate_pulse_scale(0.40, false) - 1.0).abs() < 1e-4);
assert!((tag_duplicate_pulse_scale(0.18, true) - 1.0).abs() < 1e-4);
}
#[test]
fn tag_placeholder_sample_rises_from_4_2px_to_zero() {
let (op0, y0) = tag_placeholder_sample(0.0, false);
assert!(op0 < 0.01);
assert!((y0 - 4.2).abs() < 1e-4);
let (op1, y1) = tag_placeholder_sample(0.26, false);
assert!((op1 - 1.0).abs() < 1e-4);
assert!(y1.abs() < 1e-4);
}
}