Add searchable input controls and display profile editing
This commit is contained in:
1 parent
78ce1ed590
commit
a2be421974
24 files changed
+3426
-249
No files matched your search
@@ -350,6 +350,36 @@ impl Document {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Restore one top-level setting from an earlier document, including its
|
||||
/// authored nodes and comments, while retaining all other current settings.
|
||||
pub fn restore_top_level(&mut self, key: &str, baseline: &Self) -> Result<(), Error> {
|
||||
if key.is_empty() || key.contains('.') {
|
||||
return Err(Error("Expected a top-level setting".into()));
|
||||
}
|
||||
let mut candidate = self.clone();
|
||||
let index = candidate
|
||||
.doc
|
||||
.nodes()
|
||||
.iter()
|
||||
.position(|node| field(node.name().value(), "") == key)
|
||||
.unwrap_or(candidate.doc.nodes().len());
|
||||
candidate
|
||||
.doc
|
||||
.nodes_mut()
|
||||
.retain(|node| field(node.name().value(), "") != key);
|
||||
let restored = baseline
|
||||
.doc
|
||||
.nodes()
|
||||
.iter()
|
||||
.filter(|node| field(node.name().value(), "") == key)
|
||||
.cloned();
|
||||
let index = index.min(candidate.doc.nodes().len());
|
||||
candidate.doc.nodes_mut().splice(index..index, restored);
|
||||
candidate.refresh()?;
|
||||
*self = candidate;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn refresh(&mut self) -> Result<(), Error> {
|
||||
self.value = Value::Object(object(&self.doc, "")?);
|
||||
Ok(())
|
||||
@@ -1124,6 +1154,36 @@ pub fn from_str<T: DeserializeOwned>(source: &str) -> Result<T, Error> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn restoring_display_records_keeps_authored_comments_and_other_current_settings() {
|
||||
let baseline=Document::parse("// desk note\noutput-profile \"Desk\" { output match=\"DP-1\" scale=2; }\ninput { repeat-rate 25; }\n").unwrap();
|
||||
let mut current = baseline.clone();
|
||||
current
|
||||
.set("output_profiles.0.outputs.0.scale", 1.5.into())
|
||||
.unwrap();
|
||||
current.set("input.repeat_rate", 31.into()).unwrap();
|
||||
current
|
||||
.restore_top_level("output_profiles", &baseline)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
current.get("output_profiles"),
|
||||
baseline.get("output_profiles")
|
||||
);
|
||||
assert_eq!(
|
||||
current.get("input.repeat_rate"),
|
||||
Some(&serde_json::json!(31))
|
||||
);
|
||||
assert!(current.to_string().contains("// desk note"));
|
||||
current
|
||||
.restore_top_level("output_profiles", &Document::parse("").unwrap())
|
||||
.unwrap();
|
||||
assert!(current.get("output_profiles").is_none());
|
||||
assert_eq!(
|
||||
current.get("input.repeat_rate"),
|
||||
Some(&serde_json::json!(31))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn structured_activity_rules_use_native_kdl_syntax() {
|
||||
let mut doc = Document::parse("activities { max-visible 2; }\n").unwrap();
|
||||
|
||||
Reference in new issue
Block a user