Parcourir la source

support order,bullet with list

appflowy il y a 3 ans
Parent
commit
69c8eb09c5

+ 2 - 1
app_flowy/.vscode/settings.json

@@ -1,5 +1,6 @@
 {
     "svgviewer.enableautopreview": true,
     "svgviewer.previewcolumn": "Active",
-    "svgviewer.showzoominout": true
+    "svgviewer.showzoominout": true,
+    "editor.wordWrapColumn": 120
 }

+ 9 - 3
rust-lib/flowy-ot/src/core/attributes/attribute.rs

@@ -1,6 +1,6 @@
 #![allow(non_snake_case)]
 
-use crate::{block_attribute, core::Attributes, ignore_attribute, inline_attribute};
+use crate::{block_attribute, core::Attributes, ignore_attribute, inline_attribute, list_attribute};
 use lazy_static::lazy_static;
 use serde::{Deserialize, Serialize};
 use std::{collections::HashSet, fmt, fmt::Formatter, iter::FromIterator};
@@ -28,13 +28,19 @@ impl Attribute {
     block_attribute!(Header, usize);
     block_attribute!(Indent, usize);
     block_attribute!(Align, String);
-    block_attribute!(List, String);
+    block_attribute!(List, &str);
     block_attribute!(CodeBlock, bool);
     block_attribute!(QuoteBlock, bool);
 
     // ignore
     ignore_attribute!(Width, usize);
     ignore_attribute!(Height, usize);
+
+    // List extension
+    list_attribute!(Bullet, "bullet");
+    list_attribute!(Ordered, "ordered");
+    list_attribute!(Checked, "checked");
+    list_attribute!(UnChecked, "unchecked");
 }
 
 impl fmt::Display for Attribute {
@@ -111,7 +117,7 @@ impl std::convert::From<usize> for AttributeValue {
 }
 
 impl std::convert::From<&str> for AttributeValue {
-    fn from(val: &str) -> Self { AttributeValue(Some(val.to_owned())) }
+    fn from(val: &str) -> Self { val.to_owned().into() }
 }
 
 impl std::convert::From<String> for AttributeValue {

+ 17 - 1
rust-lib/flowy-ot/src/core/attributes/macros.rs

@@ -18,7 +18,7 @@ macro_rules! inline_attribute {
 macro_rules! block_attribute {
     (
         $key: ident,
-        $value: ident
+        $value: ty
     ) => {
         pub fn $key(value: $value) -> Self {
             Self {
@@ -30,6 +30,22 @@ macro_rules! block_attribute {
     };
 }
 
+#[macro_export]
+macro_rules! list_attribute {
+    (
+        $key: ident,
+        $value: expr
+    ) => {
+        pub fn $key(b: bool) -> Self {
+            let value = match b {
+                true => $value,
+                false => "",
+            };
+            Attribute::List(value)
+        }
+    };
+}
+
 #[macro_export]
 macro_rules! ignore_attribute {
     (

+ 1 - 5
rust-lib/flowy-ot/tests/helper/mod.rs

@@ -123,11 +123,7 @@ impl TestBuilder {
             },
             TestOp::Bullet(delta_i, iv, enable) => {
                 let document = &mut self.documents[*delta_i];
-                let value = match *enable {
-                    true => "bullet",
-                    false => "",
-                };
-                let attribute = Attribute::List(value.to_owned());
+                let attribute = Attribute::Bullet(*enable);
                 document.format(*iv, attribute).unwrap();
             },
             TestOp::Transform(delta_a_i, delta_b_i) => {