yorkie icon indicating copy to clipboard operation
yorkie copied to clipboard

Handling errors in concurrent editing and styling

Open raararaara opened this issue 4 months ago • 1 comments

What this PR does / why we need it: Refer to #780 , there is an error occurring in the concurrent editing and styling (Edit+Style) handling. In a concurrent editing and styling situation, I've concerned the difference between the creation time of nodes included in the style operation range and the time ticket for concurrent editing.

Which issue(s) this PR fixes:

Fixes #788 Related #780

Special notes for your reviewer: For handle this error, I added logic to ignore style operation(+ removeStyle) for nodes created before concurrency edit writed below. A list of tests resolved with this change can be found in #788 (All test cases related to Style).

  • AS-IS:
err = t.traverseInPosRange(fromParent, fromLeft, toParent, toLeft,
func(token index.TreeToken[*TreeNode], _ bool) {
	node := token.Node
	if !node.IsRemoved() && !node.IsText() && len(attributes) > 0 {
		if node.Attrs == nil {
			node.Attrs = NewRHT()
		}

		for key, value := range attributes {
			node.Attrs.Set(key, value, editedAt)
		}
	}
})
  • TO-BE:
err = t.traverseInPosRange(fromParent, fromLeft, toParent, toLeft,
func(token index.TreeToken[*TreeNode], _ bool) {
	node := token.Node
	if !node.IsRemoved() && !node.IsText() && len(attributes) > 0 {
		// Added here
		if editedAt.After(node.ID.CreatedAt) {
			return
		}
		if node.Attrs == nil {
			node.Attrs = NewRHT()
		}

		for key, value := range attributes {
			node.Attrs.Set(key, value, editedAt)
		}
	}
})

Does this PR introduce a user-facing change?:


Additional documentation:


Checklist:

  • [ ] Added relevant tests or not required
  • [ ] Didn't break anything

raararaara avatar Feb 14 '24 07:02 raararaara