mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-28 12:26:52 -06:00
- 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>
25 lines
1.1 KiB
Rust
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()));
|
|
}
|