diff --git a/frontend/rust-lib/flowy-document/tests/editor/attribute_test.rs b/frontend/rust-lib/flowy-document/tests/editor/attribute_test.rs index a60254a7c9..ecf5aeb238 100644 --- a/frontend/rust-lib/flowy-document/tests/editor/attribute_test.rs +++ b/frontend/rust-lib/flowy-document/tests/editor/attribute_test.rs @@ -775,7 +775,7 @@ fn delta_compose() { } assert_eq!( delta.json_str(), - r#"[{"insert":"a"},{"insert":"\n","attributes":{"list":"unchecked"}},{"insert":"\n"}]"# + r#"[{"insert":"a"},{"insert":"\n","attributes":{"list":"unchecked"}},{"insert":"\n","attributes":{"list":""}}]"# ); let ops = vec![ diff --git a/shared-lib/lib-ot/src/core/attributes/attribute.rs b/shared-lib/lib-ot/src/core/attributes/attribute.rs index 6438ccc05c..ed91a793af 100644 --- a/shared-lib/lib-ot/src/core/attributes/attribute.rs +++ b/shared-lib/lib-ot/src/core/attributes/attribute.rs @@ -214,6 +214,7 @@ impl AttributeValue { pub fn none() -> Self { Self { ty: None, value: None } } + pub fn from_int(val: i64) -> Self { Self { ty: Some(ValueType::IntType), @@ -235,8 +236,9 @@ impl AttributeValue { value: Some(val.to_string()), } } - pub fn from_string(s: &str) -> Self { - let value = if s.is_empty() { None } else { Some(s.to_string()) }; + + pub fn from_string(s: T) -> Self { + let value = Some(s.to_string()); Self { ty: Some(ValueType::StrType), value, @@ -283,7 +285,7 @@ impl std::convert::From<&str> for AttributeValue { impl std::convert::From for AttributeValue { fn from(value: String) -> Self { - AttributeValue::from_string(&value) + AttributeValue::from_string(value) } } diff --git a/shared-lib/lib-ot/src/text_delta/attributes.rs b/shared-lib/lib-ot/src/text_delta/attributes.rs index 574130b214..97d5335fed 100644 --- a/shared-lib/lib-ot/src/text_delta/attributes.rs +++ b/shared-lib/lib-ot/src/text_delta/attributes.rs @@ -1,5 +1,5 @@ #![allow(non_snake_case)] -use crate::core::{AttributeEntry, AttributeHashMap, AttributeKey}; +use crate::core::{AttributeEntry, AttributeHashMap, AttributeKey, AttributeValue}; use crate::text_delta::DeltaTextOperation; use crate::{inline_attribute_entry, inline_list_attribute_entry}; use lazy_static::lazy_static; diff --git a/shared-lib/lib-ot/src/text_delta/macros.rs b/shared-lib/lib-ot/src/text_delta/macros.rs index 0ca226733d..a93c2f4dc0 100644 --- a/shared-lib/lib-ot/src/text_delta/macros.rs +++ b/shared-lib/lib-ot/src/text_delta/macros.rs @@ -21,13 +21,13 @@ macro_rules! inline_list_attribute_entry { ) => { pub fn $key(b: bool) -> $crate::core::AttributeEntry { let value = match b { - true => $value, - false => "", + true => $value.into(), + false => AttributeValue::none(), }; AttributeEntry { key: BuildInTextAttributeKey::List.as_ref().to_string(), - value: value.into(), + value, } } };