瀏覽代碼

[rust]: support blockqutoe and code attribute

appflowy 3 年之前
父節點
當前提交
99d39e30f8

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

@@ -18,5 +18,8 @@
     "editor.minimap.maxColumn": 140,
     "prettier.printWidth": 140,
     "editor.wordWrap": "wordWrapColumn",
-    "dart.lineLength": 120
+    "dart.lineLength": 120,
+    "files.associations": {
+        "*.log.*": "log"
+    },
 }

+ 4 - 3
app_flowy/lib/workspace/application/doc/doc_bloc.dart

@@ -20,7 +20,7 @@ class DocBloc extends Bloc<DocEvent, DocState> {
   final IViewListener listener;
   final ITrash trasnManager;
   late Document document;
-  late StreamSubscription _subscription;
+  late StreamSubscription? _subscription;
 
   DocBloc({
     required this.view,
@@ -57,7 +57,8 @@ class DocBloc extends Bloc<DocEvent, DocState> {
   @override
   Future<void> close() async {
     await listener.stop();
-    await _subscription.cancel();
+
+    await _subscription?.cancel();
     docManager.closeDoc();
     return super.close();
   }
@@ -104,7 +105,7 @@ class DocBloc extends Bloc<DocEvent, DocState> {
 
   void _composeDelta(Delta composedDelta, Delta documentDelta) async {
     final json = jsonEncode(composedDelta.toJson());
-    Log.debug("Send json: $json");
+    Log.debug("doc_id: $view.id - Send json: $json");
     final result = await docManager.composeDelta(json: json);
 
     result.fold((rustDoc) {

+ 8 - 8
app_flowy/lib/workspace/presentation/stack_page/doc/widget/toolbar/tool_bar.dart

@@ -93,14 +93,14 @@ class EditorToolbar extends StatelessWidget implements PreferredSizeWidget {
           controller: controller,
           background: true,
         ),
-        FlowyImageButton(
-          iconSize: toolbarIconSize,
-          controller: controller,
-          onImagePickCallback: onImagePickCallback,
-          filePickImpl: filePickImpl,
-          webImagePickImpl: webImagePickImpl,
-          mediaPickSettingSelector: mediaPickSettingSelector,
-        ),
+        // FlowyImageButton(
+        //   iconSize: toolbarIconSize,
+        //   controller: controller,
+        //   onImagePickCallback: onImagePickCallback,
+        //   filePickImpl: filePickImpl,
+        //   webImagePickImpl: webImagePickImpl,
+        //   mediaPickSettingSelector: mediaPickSettingSelector,
+        // ),
         FlowyHeaderStyleButton(
           controller: controller,
           iconSize: toolbarIconSize,

+ 4 - 6
rust-lib/flowy-document/src/services/doc/edit/doc_actor.rs

@@ -13,14 +13,16 @@ use std::{convert::TryFrom, sync::Arc};
 use tokio::sync::{mpsc, RwLock};
 
 pub struct DocumentActor {
+    doc_id: String,
     document: Arc<RwLock<Document>>,
     receiver: Option<mpsc::UnboundedReceiver<DocumentMsg>>,
 }
 
 impl DocumentActor {
-    pub fn new(delta: Delta, receiver: mpsc::UnboundedReceiver<DocumentMsg>) -> Self {
+    pub fn new(doc_id: &str, delta: Delta, receiver: mpsc::UnboundedReceiver<DocumentMsg>) -> Self {
         let document = Arc::new(RwLock::new(Document::from_delta(delta)));
         Self {
+            doc_id: doc_id.to_owned(),
             document,
             receiver: Some(receiver),
         }
@@ -114,11 +116,7 @@ impl DocumentActor {
         // tracing::debug!("{:?} thread handle_message", thread::current(),);
         let mut document = self.document.write().await;
         let result = document.compose_delta(&delta);
-        tracing::debug!(
-            "Compose push delta: {}. result: {}",
-            delta.to_json(),
-            document.to_json()
-        );
+        tracing::debug!("doc_id:{} - Compose push delta: {}", &self.doc_id, delta.to_json(),);
         drop(document);
 
         result

+ 2 - 2
rust-lib/flowy-document/src/services/doc/edit/edit_doc.rs

@@ -321,9 +321,9 @@ async fn save_document(document: UnboundedSender<DocumentMsg>, rev_id: RevId) ->
     result
 }
 
-fn spawn_doc_edit_actor(_doc_id: &str, delta: Delta, _pool: Arc<ConnectionPool>) -> UnboundedSender<DocumentMsg> {
+fn spawn_doc_edit_actor(doc_id: &str, delta: Delta, _pool: Arc<ConnectionPool>) -> UnboundedSender<DocumentMsg> {
     let (sender, receiver) = mpsc::unbounded_channel::<DocumentMsg>();
-    let actor = DocumentActor::new(delta, receiver);
+    let actor = DocumentActor::new(doc_id, delta, receiver);
     tokio::spawn(actor.run());
     sender
 }

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

@@ -1,3 +1,4 @@
+#![cfg_attr(rustfmt, rustfmt::skip)]
 use crate::editor::{TestBuilder, TestOp::*};
 use flowy_document::services::doc::{FlowyDoc, PlainDoc};
 use flowy_ot::core::{Delta, DeltaBuilder, Interval, OperationTransformable, NEW_LINE, WHITESPACE};

+ 8 - 15
rust-lib/flowy-log/src/lib.rs

@@ -39,7 +39,7 @@ impl Builder {
     pub fn local(mut self, directory: impl AsRef<Path>) -> Self {
         let directory = directory.as_ref().to_str().unwrap().to_owned();
         let local_file_name = format!("{}.log", &self.name);
-        self.file_appender = Some(tracing_appender::rolling::hourly(directory, local_file_name));
+        self.file_appender = Some(tracing_appender::rolling::daily(directory, local_file_name));
 
         self
     }
@@ -48,29 +48,22 @@ impl Builder {
         let env_filter = EnvFilter::new(self.env_filter);
         let file_appender = self.file_appender.unwrap();
         let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
-        let formatting_layer = FlowyFormattingLayer::new(std::io::stdout);
-
-        let formatter =
-            // Construct a custom formatter for `Debug` fields
-            format::debug_fn(|writer, field, value| write!(writer, "{}: {:?}", field, value))
-                // Use the `tracing_subscriber::MakeFmtExt` trait to wrap the
-                // formatter so that a delimiter is added between fields.
-                .delimited(", ");
-
         let subscriber = tracing_subscriber::fmt()
             // .with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
-            // .without_time()
             .with_ansi(false)
             .with_target(false)
             .with_max_level(tracing::Level::TRACE)
             .with_writer(std::io::stderr)
-            .fmt_fields(formatter)
-            // .with_thread_ids(true)
-            .with_writer(non_blocking)
+            .with_thread_ids(true)
+            // .with_writer(non_blocking)
             .json()
+            .with_current_span(true)
+            .with_span_list(true)
             .compact()
             .finish()
-            .with(env_filter).with(JsonStorageLayer).with(formatting_layer);
+            .with(env_filter).with(JsonStorageLayer)
+            .with(FlowyFormattingLayer::new(std::io::stdout))
+            .with(FlowyFormattingLayer::new(non_blocking));
 
         // if cfg!(feature = "use_bunyan") {
         //     let formatting_layer = BunyanFormattingLayer::new(self.name.clone(),

+ 8 - 4
rust-lib/flowy-ot/src/core/attributes/attribute.rs

@@ -24,6 +24,7 @@ impl Attribute {
     inline_attribute!(Font, usize);
     inline_attribute!(Size, usize);
     inline_attribute!(Background, String);
+    inline_attribute!(InlineCode, bool);
 
     // block
     block_attribute!(Header, usize);
@@ -31,7 +32,7 @@ impl Attribute {
     block_attribute!(Align, String);
     block_attribute!(List, &str);
     block_attribute!(CodeBlock, bool);
-    block_attribute!(QuoteBlock, bool);
+    block_attribute!(BlockQuote, bool);
 
     // ignore
     ignore_attribute!(Width, usize);
@@ -97,10 +98,12 @@ pub enum AttributeKey {
     Align,
     #[serde(rename = "code_block")]
     CodeBlock,
+    #[serde(rename = "code")]
+    InlineCode,
     #[serde(rename = "list")]
     List,
-    #[serde(rename = "quote_block")]
-    QuoteBlock,
+    #[serde(rename = "blockquote")]
+    BlockQuote,
     #[serde(rename = "width")]
     Width,
     #[serde(rename = "height")]
@@ -169,7 +172,7 @@ lazy_static! {
         AttributeKey::Align,
         AttributeKey::CodeBlock,
         AttributeKey::List,
-        AttributeKey::QuoteBlock,
+        AttributeKey::BlockQuote,
     ]);
     static ref INLINE_KEYS: HashSet<AttributeKey> = HashSet::from_iter(vec![
         AttributeKey::Bold,
@@ -181,6 +184,7 @@ lazy_static! {
         AttributeKey::Font,
         AttributeKey::Size,
         AttributeKey::Background,
+        AttributeKey::InlineCode,
     ]);
     static ref INGORE_KEYS: HashSet<AttributeKey> =
         HashSet::from_iter(vec![AttributeKey::Width, AttributeKey::Height,]);

+ 2 - 1
rust-lib/flowy-ot/src/core/attributes/attributes_serde.rs

@@ -52,7 +52,8 @@ where
             | AttributeKey::Underline
             | AttributeKey::StrikeThrough
             | AttributeKey::CodeBlock
-            | AttributeKey::QuoteBlock => match &v.parse::<bool>() {
+            | AttributeKey::InlineCode
+            | AttributeKey::BlockQuote => match &v.parse::<bool>() {
                 Ok(value) => map_serializer.serialize_entry(&key, value)?,
                 Err(e) => log::error!("Serial {:?} failed. {:?}", &key, e),
             },