Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

[rust]: fix compile issue on release mode

appflowy22b93f0343cc
diff --git a/app_flowy/lib/workspace/application/doc/doc_bloc.dart b/app_flowy/lib/workspace/application/doc/doc_bloc.dart
index 3811165b62..e90749dd8c 100644
--- a/app_flowy/lib/workspace/application/doc/doc_bloc.dart
+++ b/app_flowy/lib/workspace/application/doc/doc_bloc.dart
@@ -122,10 +122,6 @@ class DocBloc extends Bloc<DocEvent, DocState> {
}
Document _decodeJsonToDocument(String data) {
- // String d = r'''
- // "[{"insert":"\nπŸ‘‹ Welcome to AppFlowy!\n"},{"insert":"\n","attributes":{"header":1}},{"insert":"Here are the basics\n"},{"insert":"C","attributes":{"header":2}},{"insert":"lick anywhere and just start typing\n"},{"insert":"H","attributes":{"list":"unchecked"}},{"insert":"ighlight any text, and use the menu at the bottom to style your writing however you like\n"},{"insert":"C","attributes":{"list":"unchecked"}},{"insert":"lick + New Page button at the bottom of your sidebar to add a new page\n"},{"insert":"C","attributes":{"list":"unchecked"}},{"insert":"lick the + next to any page title in the sidebar to quickly add a new subpage\n"},{"insert":"\n","attributes":{"list":"unchecked"}},{"insert":"Have a question? \n"},{"insert":"C","attributes":{"header":2}},{"insert":"lick the '?' at the bottom right for help and support.\n\nLike AppFlowy? Follow us:\n"},{"insert":"G","attributes":{"header":2}},{"insert":"ithub: https://github.com/AppFlowy-IO/appflowy\n"},{"insert":"T","attributes":{"blockquote":true}},{"insert":"witter: https://twitter.com/appflowy\n"},{"insert":"N","attributes":{"blockquote":true}},{"insert":"ewsletter: https://www.appflowy.io/blog\n"},{"retain":1,"attributes":{"blockquote":true}},{"insert":"\n"}]"
- // ''';
-
final json = jsonDecode(data);
final document = Document.fromJson(json);
return document;
diff --git a/delta_markdown b/delta_markdown
deleted file mode 160000
index 3e121c546f..0000000000
--- a/delta_markdown
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 3e121c546fe40f91e9817ad0e0f04910315db681
diff --git a/rust-lib/flowy-document/src/READ_ME.json b/rust-lib/flowy-document/src/READ_ME.json
new file mode 100644
index 0000000000..2e0de59742
--- /dev/null
+++ b/rust-lib/flowy-document/src/READ_ME.json
@@ -0,0 +1 @@
+[{"insert":"\nπŸ‘‹ Welcome to AppFlowy!"},{"insert":"\n","attributes":{"header":1}},{"insert":"\nHere are the basics"},{"insert":"\n","attributes":{"header":2}},{"insert":"Click anywhere and just start typing"},{"insert":"\n","attributes":{"list":"unchecked"}},{"insert":"Highlight","attributes":{"background":"#fff2cd"}},{"insert":" any text, and use the menu at the bottom to "},{"insert":"style","attributes":{"italic":true}},{"insert":" "},{"insert":"your","attributes":{"bold":true}},{"insert":" "},{"insert":"writing","attributes":{"underline":true}},{"insert":" "},{"insert":"however","attributes":{"code":true}},{"insert":" "},{"insert":"you","attributes":{"strike":true}},{"insert":" "},{"insert":"like","attributes":{"background":"#e8e0ff"}},{"insert":"\n","attributes":{"list":"unchecked"}},{"insert":"Click "},{"insert":"+ New Page","attributes":{"background":"#defff1","bold":true}},{"insert":" button at the bottom of your sidebar to add a new page"},{"insert":"\n","attributes":{"list":"unchecked"}},{"insert":"Click the "},{"insert":"'","attributes":{"background":"#defff1"}},{"insert":"+'","attributes":{"background":"#defff1","bold":true}},{"insert":" next to any page title in the sidebar to quickly add a new subpage"},{"insert":"\n","attributes":{"list":"unchecked"}},{"insert":"\nHave a question? "},{"insert":"\n","attributes":{"header":2}},{"insert":"Click the "},{"insert":"'?'","attributes":{"background":"#defff1","bold":true}},{"insert":" at the bottom right for help and support.\n\nLike AppFlowy? Follow us:"},{"insert":"\n","attributes":{"header":2}},{"insert":"Github: https://github.com/AppFlowy-IO/appflowy"},{"insert":"\n","attributes":{"blockquote":true}},{"insert":"Twitter: https://twitter.com/appflowy"},{"insert":"\n","attributes":{"blockquote":true}},{"insert":"Newsletter: https://www.appflowy.io/blog"},{"insert":"\n","attributes":{"blockquote":true}}]
\ No newline at end of file
diff --git a/rust-lib/flowy-document/src/services/doc/document/document.rs b/rust-lib/flowy-document/src/services/doc/document/document.rs
index e64b0e163f..5bdc2d6882 100644
--- a/rust-lib/flowy-document/src/services/doc/document/document.rs
+++ b/rust-lib/flowy-document/src/services/doc/document/document.rs
@@ -218,3 +218,15 @@ pub fn trim(delta: &mut Delta) {
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use flowy_ot::core::Delta;
+
+ #[test]
+ fn load_read_me() {
+ let json = include_str!("../../../READ_ME.json");
+ let delta = Delta::from_json(json).unwrap();
+ assert_eq!(delta.to_json(), json);
+ }
+}
diff --git a/rust-lib/flowy-document/src/services/doc/revision/persistence.rs b/rust-lib/flowy-document/src/services/doc/revision/persistence.rs
index 567311bf6d..528ce21618 100644
--- a/rust-lib/flowy-document/src/services/doc/revision/persistence.rs
+++ b/rust-lib/flowy-document/src/services/doc/revision/persistence.rs
@@ -191,14 +191,11 @@ async fn fetch_from_local(doc_id: &str, persistence: Arc<Persistence>) -> DocRes
let rev_id: RevId = revisions.last().unwrap().rev_id.into();
let mut delta = Delta::new();
let mut pre_rev_id = 0;
- for (index, revision) in revisions.into_iter().enumerate() {
- if cfg!(debug_assertions) {
- if index == 0 {
- pre_rev_id = revision.rev_id;
- } else {
- validate_rev_id(pre_rev_id, revision.rev_id);
- }
- }
+ for (_, revision) in revisions.into_iter().enumerate() {
+ pre_rev_id = revision.rev_id;
+
+ #[cfg(debug_assertions)]
+ validate_rev_id(pre_rev_id, revision.rev_id);
match Delta::from_bytes(revision.delta_data) {
Ok(local_delta) => {
@@ -210,9 +207,8 @@ async fn fetch_from_local(doc_id: &str, persistence: Arc<Persistence>) -> DocRes
}
}
- if cfg!(debug_assertions) {
- validate_delta(&doc_id, persistence, conn, &delta);
- }
+ #[cfg(debug_assertions)]
+ validate_delta(&doc_id, persistence, conn, &delta);
match delta.ops.last() {
None => {},
diff --git a/rust-lib/flowy-ot/src/core/flowy_str.rs b/rust-lib/flowy-ot/src/core/flowy_str.rs
index 9cbcc47287..6039319a4b 100644
--- a/rust-lib/flowy-ot/src/core/flowy_str.rs
+++ b/rust-lib/flowy-ot/src/core/flowy_str.rs
@@ -7,7 +7,9 @@ pub struct FlowyStr(pub String);
impl FlowyStr {
pub fn count_utf16_code_units(&self) -> usize { count_utf16_code_units(&self.0) }
- pub fn iter(&self) -> FlowyUtf16Iterator { FlowyUtf16Iterator::new(self, 0) }
+ pub fn utf16_iter(&self) -> FlowyUtf16Iterator { FlowyUtf16Iterator::new(self, 0) }
+
+ pub fn code_point_iter(&self) -> CodePointIterator { CodePointIterator::new(self) }
pub fn sub_str(&self, interval: Interval) -> String {
match self.with_interval(interval) {
@@ -230,7 +232,7 @@ mod tests {
#[test]
fn flowy_str_utf16_test() {
let s: FlowyStr = "πŸ‘‹πŸ˜πŸ‘‹πŸ˜".into();
- let mut iter = s.iter();
+ let mut iter = s.utf16_iter();
assert_eq!(iter.next().unwrap(), "πŸ‘‹".to_string());
assert_eq!(iter.next().unwrap(), "😁".to_string());
assert_eq!(iter.next().unwrap(), "πŸ‘‹".to_string());
@@ -241,7 +243,7 @@ mod tests {
#[test]
fn flowy_str_utf16_iter_test() {
let s: FlowyStr = "πŸ‘‹πŸ‘‹πŸ˜πŸ˜πŸ‘‹πŸ‘‹".into();
- let iter = s.iter();
+ let iter = s.utf16_iter();
let result = iter.skip(2).take(2).collect::<String>();
assert_eq!(result, "😁😁".to_string());
}