Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement transformations #92

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

nikmel2803
Copy link
Contributor

  • implement logic for operations transformations (text operations only for now)
  • move logic from the Transformer class to the Operation class

Copy link

github-actions bot commented Aug 31, 2024

⏭️ No files to mutate for ./packages/model

Copy link

github-actions bot commented Aug 31, 2024

⏭️ No files to mutate for ./packages/dom-adapters

Copy link

github-actions bot commented Aug 31, 2024

Coverage report for ./packages/dom-adapters

St.
Category Percentage Covered / Total
🟢 Statements 100% 0/0
🟢 Branches 100% 0/0
🟢 Functions 100% 0/0
🟢 Lines 100% 0/0

Test suite run success

1 tests passing in 1 suite.

Report generated by 🧪jest coverage report action from 1a4cdbf

Copy link

github-actions bot commented Aug 31, 2024

Coverage report for ./packages/model

St.
Category Percentage Covered / Total
🟢 Statements 96.74% 800/827
🟢 Branches 98.17% 214/218
🟢 Functions 88.07% 192/218
🟢 Lines 96.62% 772/799

Test suite run success

404 tests passing in 24 suites.

Report generated by 🧪jest coverage report action from 1a4cdbf

Copy link

github-actions bot commented Aug 31, 2024

Coverage report for ./packages/collaboration-manager

St.
Category Percentage Covered / Total
🟢 Statements
89% (+2.89% 🔼)
89/100
🟢 Branches
82.14% (+19.64% 🔼)
46/56
🟢 Functions 100% 12/12
🟢 Lines
89% (+2.89% 🔼)
89/100
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢 Operation.ts
91.3% (-8.7% 🔻)
89.74% (-10.26% 🔻)
100%
91.3% (-8.7% 🔻)

Test suite run success

22 tests passing in 2 suites.

Report generated by 🧪jest coverage report action from 1a4cdbf

Comment on lines +16 to +17
prevValue: type === OperationType.Delete ? value : '',
newValue: type === OperationType.Insert ? value : '',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls remove this for Add/Remove opeeration, leave just data

/**
* Do not transform operations if they are on different blocks or documents
*/
if (this.index.documentId !== againstOp.index.documentId || this.index.blockIndex !== againstOp.index.blockIndex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to consider block index for text operations, if block before was added or deleted, we need to update the index

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be done in a separate PR

const [ localStartIndex ] = againstOp.index.textRange!;

switch (true) {
case this.type === OperationType.Insert && againstOp.type === OperationType.Insert:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type of the current operation doesn't matter here, index will be changed the same way for both insert and delte

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are only three cases here:

  1. If received operation is delete operatio before (index-wise) the current, we need to update the current one index shifting it left
  2. If received operation is insert operation before (index-wise) the current, we need to shift index right
  3. If operation of any type happened after (index-wise) the current, no need to do anything

expect(transformedOp.index.textRange).toEqual([6, 6]);
});

test('Should not change a received operation if it is at the same position as a local one', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If position is the same, the index should change by the length of text in received operation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants