Files
figcraft/crates/engine/src/text_fill_tests.rs
T
BFlatandClaude Opus 5.5 b5db089db6 M4: text range fills in the Fill section (#18)
- While a range of text is selected in a text being edited, the Fill section shows that range's
  colour ("Mixed" when it varies): the swatch opens the colour picker on the range, the hex field
  sets it, and a button returns the range to the layer's fill.
- Colour picker: a text-range target that reads the range's fill and writes `text.style
  {textFills}`.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 03:52:11 +07:00

25 lines
1.1 KiB
Rust

//! Range fills on text: set on a range, cleared back to the layer's fill.
use serde_json::json;
use crate::Session;
use crate::params::id_of;
#[test]
fn range_fill_sets_and_clears() {
let mut s = Session::new();
let t = id_of(&s.execute("text.create", &json!({"text": "Hello brand world", "x": 0, "y": 0})).unwrap()["id"]).unwrap();
s.execute("text.style", &json!({"id": t, "start": 6, "end": 11, "textFills": ["#0D99FF"]})).unwrap();
let fill_at = |s: &Session, i: usize| {
let n = s.doc().unwrap().node(t).unwrap().clone();
let tx = n.kind.text().unwrap().clone();
tx.style_at(i).fills.clone().unwrap_or(n.fills).first().and_then(|p| p.solid_color()).map(|c| c.to_hex())
};
assert_eq!(fill_at(&s, 7), Some("0D99FF".into()));
assert_ne!(fill_at(&s, 1), Some("0D99FF".into()));
s.execute("text.style", &json!({"id": t, "start": 6, "end": 11, "textFills": null})).unwrap();
assert_eq!(fill_at(&s, 7), fill_at(&s, 1), "back to the layer's fill");
s.undo().unwrap();
assert_eq!(fill_at(&s, 7), Some("0D99FF".into()));
}