Bläddra i källkod

Fix: 1802 [Bug] Math Equation would be null. #1802 (#1806)

* fix: #1290 [Bug] 300ms delay on buttons in titlebar

* fix: #1802 Math Equation would be null

* fix: retain  as a attribute value

---------

Co-authored-by: nathan <[email protected]>
Lucas.Xu 2 år sedan
förälder
incheckning
a41894a5ec

+ 1 - 1
frontend/rust-lib/flowy-document/tests/editor/attribute_test.rs

@@ -775,7 +775,7 @@ fn delta_compose() {
     }
     }
     assert_eq!(
     assert_eq!(
         delta.json_str(),
         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![
     let ops = vec![

+ 5 - 3
shared-lib/lib-ot/src/core/attributes/attribute.rs

@@ -214,6 +214,7 @@ impl AttributeValue {
     pub fn none() -> Self {
     pub fn none() -> Self {
         Self { ty: None, value: None }
         Self { ty: None, value: None }
     }
     }
+
     pub fn from_int(val: i64) -> Self {
     pub fn from_int(val: i64) -> Self {
         Self {
         Self {
             ty: Some(ValueType::IntType),
             ty: Some(ValueType::IntType),
@@ -235,8 +236,9 @@ impl AttributeValue {
             value: Some(val.to_string()),
             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<T: ToString>(s: T) -> Self {
+        let value = Some(s.to_string());
         Self {
         Self {
             ty: Some(ValueType::StrType),
             ty: Some(ValueType::StrType),
             value,
             value,
@@ -283,7 +285,7 @@ impl std::convert::From<&str> for AttributeValue {
 
 
 impl std::convert::From<String> for AttributeValue {
 impl std::convert::From<String> for AttributeValue {
     fn from(value: String) -> Self {
     fn from(value: String) -> Self {
-        AttributeValue::from_string(&value)
+        AttributeValue::from_string(value)
     }
     }
 }
 }
 
 

+ 1 - 1
shared-lib/lib-ot/src/text_delta/attributes.rs

@@ -1,5 +1,5 @@
 #![allow(non_snake_case)]
 #![allow(non_snake_case)]
-use crate::core::{AttributeEntry, AttributeHashMap, AttributeKey};
+use crate::core::{AttributeEntry, AttributeHashMap, AttributeKey, AttributeValue};
 use crate::text_delta::DeltaTextOperation;
 use crate::text_delta::DeltaTextOperation;
 use crate::{inline_attribute_entry, inline_list_attribute_entry};
 use crate::{inline_attribute_entry, inline_list_attribute_entry};
 use lazy_static::lazy_static;
 use lazy_static::lazy_static;

+ 3 - 3
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 {
         pub fn $key(b: bool) -> $crate::core::AttributeEntry {
             let value = match b {
             let value = match b {
-                true => $value,
-                false => "",
+                true => $value.into(),
+                false => AttributeValue::none(),
             };
             };
 
 
             AttributeEntry {
             AttributeEntry {
                 key: BuildInTextAttributeKey::List.as_ref().to_string(),
                 key: BuildInTextAttributeKey::List.as_ref().to_string(),
-                value: value.into(),
+                value,
             }
             }
         }
         }
     };
     };