-
Notifications
You must be signed in to change notification settings - Fork 454
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
adds setText to text api. #88
base: master
Are you sure you want to change the base?
Conversation
Closes issue josephg#35 (josephg#35) Uses existing del and insert ops.
Ok to merge, @nornagon ? |
I'm happy with @CrypticSwarm's reasoning :) |
looks like this cannot be merged automatically any more? |
Most likely due to the generated compressed code. I should probably not have included those in the PR. The fix would be to rebuild and accept the rebuilt version. |
Well, it still needs the unit test that Joseph wants too :-) |
I gave it a try with a test, and I had to add the same function to all the text APIs. That works for most but not for text-tp2. Take a look at wmertens@6e84dc7 Any way to implement it better for text-tp2? |
@CrypticSwarm ping? |
Eeep. Not sure off hand. It is probably related to how tp2 works. I think tp2 leaves tombstones in place of deletes instead of deleting them. Perhaps that is making it fail. |
Escalating to @josephg :-) What do you think Joseph? On Feb 28, 2013, at 21:08 , CrypticSwarm [email protected] wrote:
|
This is a really roundabout way to replace the text contents, and it still has the bug @nornagon was talking about --- if the first submit fails, the error is discarded. Why not just submit a single operation that deletes the entire document and inserts the string you want? For the non composable text type, make an op that deletes everything then inserts text: setText: (text, callback) ->
op = [{p:0, d:@snapshot.length}, {p:0, i:text}]
@submitOp op, callback
op For composable text, do the same thing: setText: (text, callback) ->
op = [{d:@snapshot.length}, text]
@submitOp op, callback
op For TP2 its a little more complicated, because you need to delete all the characters, which have tombstones between them. Luckily, deleting a tombstone is a no-op so we can just delete everything. setText: (text, callback) ->
op = [{d:@snapshot.totalLength}, {i:text}]
@submitOp op, callback
op Interestingly, in the TP2 case you could swap the insert & delete and submit There's a comment at the top of each OT type that tells you what operations look like. Take a look at the comment describing the TP2 type to understand a bit of whats going on there. |
Also, this is missing tests. |
Closes issue #35
(#35)
Uses existing del and insert ops.