Skip to content

Commit 9ff0975

Browse files
authored
Merge pull request #1039 from AppFlowy-IO/refactor/lib_ot_attribute
Refactor/lib ot attribute
2 parents 1f9686d + c991473 commit 9ff0975

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+917
-1350
lines changed

frontend/rust-lib/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/rust-lib/flowy-grid/src/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ pub fn make_default_board() -> BuildGridContext {
4949
let done_option = SelectOptionPB::with_color("Done", SelectOptionColorPB::Yellow);
5050
let single_select_type_option = SingleSelectTypeOptionBuilder::default()
5151
.add_option(to_do_option.clone())
52-
.add_option(doing_option.clone())
53-
.add_option(done_option.clone());
52+
.add_option(doing_option)
53+
.add_option(done_option);
5454
let single_select_field = FieldBuilder::new(single_select_type_option)
5555
.name("Status")
5656
.visibility(true)

frontend/rust-lib/flowy-revision/src/conflict_resolve.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ use flowy_sync::{
99
util::make_delta_from_revisions,
1010
};
1111
use lib_infra::future::BoxResultFuture;
12-
use lib_ot::core::{Attributes, EmptyAttributes, Operations};
13-
use lib_ot::text_delta::TextAttributes;
12+
use lib_ot::core::{Attributes, EmptyAttributes, OperationAttributes, Operations};
13+
1414
use serde::de::DeserializeOwned;
1515
use std::{convert::TryFrom, sync::Arc};
1616

1717
pub type DeltaMD5 = String;
1818

1919
pub trait ConflictResolver<T>
2020
where
21-
T: Attributes + Send + Sync,
21+
T: OperationAttributes + Send + Sync,
2222
{
2323
fn compose_delta(&self, delta: Operations<T>) -> BoxResultFuture<DeltaMD5, FlowyError>;
2424
fn transform_delta(&self, delta: Operations<T>) -> BoxResultFuture<TransformDeltas<T>, FlowyError>;
@@ -30,12 +30,12 @@ pub trait ConflictRevisionSink: Send + Sync + 'static {
3030
fn ack(&self, rev_id: String, ty: ServerRevisionWSDataType) -> BoxResultFuture<(), FlowyError>;
3131
}
3232

33-
pub type RichTextConflictController = ConflictController<TextAttributes>;
33+
pub type RichTextConflictController = ConflictController<Attributes>;
3434
pub type PlainTextConflictController = ConflictController<EmptyAttributes>;
3535

3636
pub struct ConflictController<T>
3737
where
38-
T: Attributes + Send + Sync,
38+
T: OperationAttributes + Send + Sync,
3939
{
4040
user_id: String,
4141
resolver: Arc<dyn ConflictResolver<T> + Send + Sync>,
@@ -45,7 +45,7 @@ where
4545

4646
impl<T> ConflictController<T>
4747
where
48-
T: Attributes + Send + Sync + DeserializeOwned + serde::Serialize,
48+
T: OperationAttributes + Send + Sync + DeserializeOwned + serde::Serialize,
4949
{
5050
pub fn new(
5151
user_id: &str,
@@ -147,7 +147,7 @@ fn make_client_and_server_revision<T>(
147147
md5: String,
148148
) -> (Revision, Option<Revision>)
149149
where
150-
T: Attributes + serde::Serialize,
150+
T: OperationAttributes + serde::Serialize,
151151
{
152152
let (base_rev_id, rev_id) = rev_manager.next_rev_id_pair();
153153
let client_revision = Revision::new(
@@ -175,11 +175,11 @@ where
175175
}
176176
}
177177

178-
pub type RichTextTransformDeltas = TransformDeltas<TextAttributes>;
178+
pub type RichTextTransformDeltas = TransformDeltas<Attributes>;
179179

180180
pub struct TransformDeltas<T>
181181
where
182-
T: Attributes,
182+
T: OperationAttributes,
183183
{
184184
pub client_prime: Operations<T>,
185185
pub server_prime: Option<Operations<T>>,

frontend/rust-lib/flowy-text-block/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ unicode-segmentation = "1.8"
2626
log = "0.4.14"
2727
tokio = {version = "1", features = ["sync"]}
2828
tracing = { version = "0.1", features = ["log"] }
29+
2930
bytes = { version = "1.1" }
3031
strum = "0.21"
3132
strum_macros = "0.21"
@@ -42,6 +43,7 @@ futures = "0.3.15"
4243
flowy-test = { path = "../flowy-test" }
4344
flowy-text-block = { path = "../flowy-text-block", features = ["flowy_unit_test"]}
4445
derive_more = {version = "0.99", features = ["display"]}
46+
tracing-subscriber = "0.2.0"
4547

4648
color-eyre = { version = "0.5", default-features = false }
4749
criterion = "0.3"

frontend/rust-lib/flowy-text-block/src/editor.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ use flowy_sync::{
1313
errors::CollaborateResult,
1414
util::make_delta_from_revisions,
1515
};
16+
use lib_ot::core::AttributeEntry;
1617
use lib_ot::{
1718
core::{Interval, Operation},
18-
text_delta::{TextAttribute, TextDelta},
19+
text_delta::TextDelta,
1920
};
2021
use lib_ws::WSConnectState;
2122
use std::sync::Arc;
@@ -85,7 +86,7 @@ impl TextBlockEditor {
8586
Ok(())
8687
}
8788

88-
pub async fn format(&self, interval: Interval, attribute: TextAttribute) -> Result<(), FlowyError> {
89+
pub async fn format(&self, interval: Interval, attribute: AttributeEntry) -> Result<(), FlowyError> {
8990
let (ret, rx) = oneshot::channel::<CollaborateResult<()>>();
9091
let msg = EditorCommand::Format {
9192
interval,

frontend/rust-lib/flowy-text-block/src/queue.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ use flowy_sync::{
1111
errors::CollaborateError,
1212
};
1313
use futures::stream::StreamExt;
14+
use lib_ot::core::{AttributeEntry, Attributes};
1415
use lib_ot::{
1516
core::{Interval, OperationTransform},
16-
text_delta::{TextAttribute, TextAttributes, TextDelta},
17+
text_delta::TextDelta,
1718
};
1819
use std::sync::Arc;
1920
use tokio::sync::{oneshot, RwLock};
@@ -194,7 +195,7 @@ impl EditBlockQueue {
194195
pub(crate) struct TextBlockRevisionCompactor();
195196
impl RevisionCompactor for TextBlockRevisionCompactor {
196197
fn bytes_from_revisions(&self, revisions: Vec<Revision>) -> FlowyResult<Bytes> {
197-
let delta = make_delta_from_revisions::<TextAttributes>(revisions)?;
198+
let delta = make_delta_from_revisions::<Attributes>(revisions)?;
198199
Ok(delta.json_bytes())
199200
}
200201
}
@@ -229,7 +230,7 @@ pub(crate) enum EditorCommand {
229230
},
230231
Format {
231232
interval: Interval,
232-
attribute: TextAttribute,
233+
attribute: AttributeEntry,
233234
ret: Ret<()>,
234235
},
235236
Replace {

frontend/rust-lib/flowy-text-block/src/web_socket.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use flowy_sync::{
1010
errors::CollaborateResult,
1111
};
1212
use lib_infra::future::{BoxResultFuture, FutureResult};
13-
use lib_ot::text_delta::TextAttributes;
13+
use lib_ot::core::Attributes;
14+
1415
use lib_ot::text_delta::TextDelta;
1516
use lib_ws::WSConnectState;
1617
use std::{sync::Arc, time::Duration};
@@ -111,7 +112,7 @@ struct TextBlockConflictResolver {
111112
edit_cmd_tx: EditorCommandSender,
112113
}
113114

114-
impl ConflictResolver<TextAttributes> for TextBlockConflictResolver {
115+
impl ConflictResolver<Attributes> for TextBlockConflictResolver {
115116
fn compose_delta(&self, delta: TextDelta) -> BoxResultFuture<DeltaMD5, FlowyError> {
116117
let tx = self.edit_cmd_tx.clone();
117118
Box::pin(async move {

0 commit comments

Comments
 (0)