mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 21:12:57 -05:00
Attributes: URL and Note fields use the shared selection target
The URL and Note fields now take their edit target from panels::selection_target instead of a copy of its key in attributes.rs. The shared target also holds the selected symbol part, so selecting a part of a symbol instance drops an unfinished URL or note: attributes.set does not edit a selected part.
This commit is contained in:
1 parent
4055f43172
commit
b026540672
1 file changed
+28
-16
@@ -24,7 +24,7 @@ use vectorcraft_doc::{ImageMap, NodeId, NodeKind};
|
||||
use vectorcraft_engine::cmd::{AttributesInfo, RECENT_URLS};
|
||||
use vectorcraft_geom::FillRule;
|
||||
|
||||
use super::{part_hidden, selection_len, set_part_hidden};
|
||||
use super::{part_hidden, selection_len, selection_target, set_part_hidden};
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
/// The part store's key for the options (centre, direction, fill rule, image map, URL).
|
||||
@@ -116,20 +116,6 @@ fn info(app: &mut VectorcraftApp) -> (AttributesInfo, bool) {
|
||||
v
|
||||
}
|
||||
|
||||
/// What the URL and Note fields edit, as their edit target: the document, how many times File › Revert and Undo or
|
||||
/// Redo replaced its content (after which a node id can name another object), and the selected objects (or the object
|
||||
/// targeted in the Layers panel) in id order. A field drops an unfinished value when this changes, even where the new
|
||||
/// objects hold the same text, and keeps it when the same objects are selected in another order.
|
||||
type EditTarget = Option<(u64, u64, u64, Vec<NodeId>)>;
|
||||
|
||||
/// The [`EditTarget`] of the active document.
|
||||
fn edit_target(app: &VectorcraftApp) -> EditTarget {
|
||||
let st = app.session.active()?;
|
||||
let mut subjects = st.selection.subjects().to_vec();
|
||||
subjects.sort_unstable();
|
||||
Some((st.uid, st.reverts, st.history_restores, subjects))
|
||||
}
|
||||
|
||||
/// A value the targets share, or mixed where they differ (`None`).
|
||||
fn or_mixed<T>(v: Option<T>) -> Mixed<T> {
|
||||
v.map_or(Mixed::Mixed, Mixed::Same)
|
||||
@@ -153,7 +139,8 @@ fn pair<T: Valued>(ui: &mut Ui, name: &'static str, enabled: bool, current: Opti
|
||||
pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let (info, paths) = info(app);
|
||||
let has = !info.ids.is_empty();
|
||||
let target = edit_target(app);
|
||||
// The URL and Note fields drop an unfinished value when the selection target changes.
|
||||
let target = selection_target(app);
|
||||
// (command, params) for each edit of this pass; errors show in the status bar through `run`.
|
||||
let mut acts: Vec<(&'static str, Value)> = Vec::new();
|
||||
Row::new().show(ui, |ui, _| {
|
||||
@@ -490,6 +477,31 @@ mod tests {
|
||||
assert_eq!((notes.0.as_deref(), notes.1.as_deref()), (Some("typed note"), Some("typed note")), "both objects take the note");
|
||||
}
|
||||
|
||||
/// Selecting a part of a symbol instance drops an unfinished note: a selected part takes no note, so selecting the
|
||||
/// instance again and clicking elsewhere leaves the instance's note.
|
||||
#[test]
|
||||
fn selecting_a_part_of_the_instance_drops_an_unfinished_note() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
run(&mut app, "file.new", json!({"width": 100, "height": 100}));
|
||||
let left = run(&mut app, "shape.rectangle", json!({"x": 0, "y": 0, "width": 30, "height": 30}))["id"].clone();
|
||||
let right = run(&mut app, "shape.rectangle", json!({"x": 50, "y": 0, "width": 30, "height": 30}))["id"].clone();
|
||||
let instance = run(&mut app, "symbol.new", json!({"name": "Pair", "ids": [left, right], "type": "dynamic"}))["id"].as_u64().unwrap();
|
||||
run(&mut app, "attributes.set", json!({"ids": [instance], "note": "instance note"}));
|
||||
run(&mut app, "select.set", json!({"ids": [instance]}));
|
||||
let mut panel = Panel::new(app, show);
|
||||
panel.room(egui::vec2(320.0, 480.0));
|
||||
panel.frame();
|
||||
unfinished(&mut panel, "Note", "typed note");
|
||||
run(&mut panel.app(), "symbol.instance.selectPart", json!({"id": instance, "path": [0]}));
|
||||
settle(&mut panel);
|
||||
assert_ne!(panel.value("Note").as_deref(), Some("typed note"), "the Note field drops the unfinished note");
|
||||
run(&mut panel.app(), "select.set", json!({"ids": [instance]}));
|
||||
settle(&mut panel);
|
||||
let at = below(&panel);
|
||||
panel.click_at(at);
|
||||
assert_eq!(url_and_note(&panel, instance).1.as_deref(), Some("instance note"), "the instance keeps its note");
|
||||
}
|
||||
|
||||
/// Only web and mail URLs reach the browser.
|
||||
#[test]
|
||||
fn the_browser_opens_web_and_mail_urls_only() {
|
||||
|
||||
Reference in new issue
Block a user