mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-27 07:46:25 +00:00
fix(core): clearing an undefined type's icon defines nothing
Also covers that renaming a plain tag leaves an undefined (suggested) type of that name alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bd2236bb89
commit
872073a0a0
2 files changed
+27
-3
No files matched your search
@@ -245,8 +245,8 @@ impl Graph {
|
|||||||
Ok(name)
|
Ok(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets (or with `None` clears) the emoji of a type, defining the type if needed (see
|
/// Sets (or with `None` clears) the emoji of a type, defining the type when setting one
|
||||||
/// [`normalize_icon`] for what an icon may be).
|
/// (see [`normalize_icon`] for what an icon may be). Clearing an undefined type is a no-op.
|
||||||
pub fn set_type_icon(&self, name: &str, icon: Option<&str>) -> Result<()> {
|
pub fn set_type_icon(&self, name: &str, icon: Option<&str>) -> Result<()> {
|
||||||
let name = checked_type_name(name)?;
|
let name = checked_type_name(name)?;
|
||||||
let icon = match icon {
|
let icon = match icon {
|
||||||
@@ -255,7 +255,8 @@ impl Graph {
|
|||||||
};
|
};
|
||||||
let tx = self.tx()?;
|
let tx = self.tx()?;
|
||||||
let current = self.type_def(&name)?.filter(|d| !d.removed);
|
let current = self.type_def(&name)?.filter(|d| !d.removed);
|
||||||
if current.as_ref().is_some_and(|d| d.icon == icon) {
|
// Clearing the icon of an undefined type changes nothing (and defines nothing).
|
||||||
|
if current.as_ref().map_or(icon.is_none(), |d| d.icon == icon) {
|
||||||
tx.commit()?;
|
tx.commit()?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1089,6 +1089,29 @@ fn renaming_a_type_keeps_its_icon_and_removing_drops_it() {
|
|||||||
assert_eq!(type_row(&g, "lugar"), Some(("lugar".into(), 1, None)));
|
assert_eq!(type_row(&g, "lugar"), Some(("lugar".into(), 1, None)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn renaming_a_tag_leaves_undefined_types_alone() {
|
||||||
|
let (_d, g) = graph();
|
||||||
|
let a = page(&g, "A", &["x"]);
|
||||||
|
g.add_page_tag(a, "idea").unwrap();
|
||||||
|
let seq = g.last_seq().unwrap();
|
||||||
|
g.rename_tag("idea", "ocurrencia").unwrap();
|
||||||
|
// "idea" is only a suggestion (no definition): it stays offered, nothing is defined.
|
||||||
|
assert_eq!(type_row(&g, "idea"), Some(("idea".into(), 0, None)));
|
||||||
|
assert!(g.type_defs().unwrap().is_empty());
|
||||||
|
assert!(
|
||||||
|
g.ops_since(seq, 100)
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.all(|r| !matches!(r.op, Op::PutTypeDef { .. }))
|
||||||
|
);
|
||||||
|
// Clearing the icon of an undefined type is a no-op.
|
||||||
|
g.set_type_icon("idea", None).unwrap();
|
||||||
|
g.set_type_icon("nueva", None).unwrap();
|
||||||
|
assert!(g.type_defs().unwrap().is_empty());
|
||||||
|
assert_eq!(type_row(&g, "nueva"), None);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tag_catalog_says_where_each_tag_comes_from() {
|
fn tag_catalog_says_where_each_tag_comes_from() {
|
||||||
let (_d, g) = graph();
|
let (_d, g) = graph();
|
||||||
|
|||||||
Reference in new issue
Block a user