Skip to content

Single-character run duplication in update messages (with a fix) #2

Description

@lmparppei

Thank you for the actually best CRDT implementation for Swift! However, when you do single-character edits to YText, the resulting update messages are wrong.

It's caused by the following part in YStringContent:

func encode(into encoder: YUpdateEncoder, offset: Int) {
    if offset == 0 {
        encoder.writeString(self.string as String)
    } else {
        encoder.writeString(self.string.substring(to: offset))
    }
}

These offsets work for longer runs, but fail with single characters. You don't need offset == 0 check here, because we can just create a substring from the given offset, even if it's zero.

func encode(into encoder: YUpdateEncoder, offset: Int) {
    encoder.writeString(self.string.substring(from: offset))
}

I'm not sure if you are willing to maintain the project in any way, so I didn't submit a pull request yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions