Git Product home page Git Product logo

Comments (2)

raararaara avatar raararaara commented on September 2, 2024 2

Case 'insert-front + style'

image

Description

During concurrent editing and styling of a document, there is an issue where the style attribute is applied to newly inserted nodes. This behavior is unexpected and incorrect.

Steps to Reproduce

  1. Set the initial state of the document as follows:
      0               1 2    3               4 5    6               7 8    9
<root> <p color="red"> a </p> <p color="red"> b </p> <p color="red"> c </p> </root>
<root>
  <p color="red">a</p>
  <p color="red">b</p>
  <p color="red">c</p>
</root>
  1. Perform the following changes concurrently:
    • Client1's local change: Edit(Insert) <p italic="true">d</p> at [3, 3]
    • Client2's local change: Style attribute "bold"="aa" at [3, 6]
  2. Sync Client1 and Client2

Current Result

The results after applying and syncing local changes to each client are as follows:

Client1:

  • After Edit(local change)
<root>
  <p color="red">a</p>
  <p italic="true">d</p>
  <p color="red">b</p>
  <p color="red">c</p>
</root>
  • Edit after Style(sync)
<root>
  <p color="red">a</p>
  <p "bold"="aa" italic="true">d</p>
  <p "bold"="aa" color="red">b</p>
  <p color="red">c</p>
</root>

Client2:

  • After Style(local change)
<root>
  <p color="red">a</p>
  <p "bold"="aa" color="red">b</p>
  <p color="red">c</p>
</root>
  • Style after Edit(sync)
<root>
  <p color="red">a</p>
  <p italic="true">d</p>
  <p "bold"="aa" color="red">b</p>
  <p color="red">c</p>
</root>

Suggestion

1. Lamport clock comparison

It is important to differentiate between nodes that have been newly inserted and existing nodes during the concurrent editing and styling process. This distinction will help in precisely applying style operations within the appropriate scope.

By applying the rules below, all failure cases for style-related tests that occurred in the previously written tree-concurrency-test can be resolved.

  • Before
    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)
    }
    }
    })
  • After
	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 editedAt.After(node.ID.CreatedAt) {
					return
				}

				// ...
			}
		})

Since the priority of the Lamport timestamp does not guarantee concurrent causality, this method does not solve the problem.

from yorkie.

hackerwins avatar hackerwins commented on September 2, 2024

from yorkie.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.