mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
Merge pull request #16 from sharelatex/ja-track-changes
Update Ranges Tracker
This commit is contained in:
@@ -105,6 +105,7 @@ load = (EventEmitter) ->
|
|||||||
throw new Error("unknown op type")
|
throw new Error("unknown op type")
|
||||||
|
|
||||||
addComment: (op, metadata) ->
|
addComment: (op, metadata) ->
|
||||||
|
# TODO: Don't allow overlapping comments?
|
||||||
@comments.push comment = {
|
@comments.push comment = {
|
||||||
id: op.t or @newId()
|
id: op.t or @newId()
|
||||||
op: # Copy because we'll modify in place
|
op: # Copy because we'll modify in place
|
||||||
@@ -167,12 +168,14 @@ load = (EventEmitter) ->
|
|||||||
op_length = op.i.length
|
op_length = op.i.length
|
||||||
op_end = op.p + op_length
|
op_end = op.p + op_length
|
||||||
|
|
||||||
|
|
||||||
already_merged = false
|
already_merged = false
|
||||||
previous_change = null
|
previous_change = null
|
||||||
moved_changes = []
|
moved_changes = []
|
||||||
remove_changes = []
|
remove_changes = []
|
||||||
new_changes = []
|
new_changes = []
|
||||||
for change in @changes
|
|
||||||
|
for change, i in @changes
|
||||||
change_start = change.op.p
|
change_start = change.op.p
|
||||||
|
|
||||||
if change.op.d?
|
if change.op.d?
|
||||||
@@ -200,6 +203,16 @@ load = (EventEmitter) ->
|
|||||||
# Only merge inserts if they are from the same user
|
# Only merge inserts if they are from the same user
|
||||||
is_same_user = metadata.user_id == change.metadata.user_id
|
is_same_user = metadata.user_id == change.metadata.user_id
|
||||||
|
|
||||||
|
# If this is an insert op at the end of an existing insert with a delete following, and it cancels out the following
|
||||||
|
# delete then we shouldn't append it to this insert, but instead only cancel the following delete.
|
||||||
|
# E.g.
|
||||||
|
# foo|<--- about to insert 'b' here
|
||||||
|
# inserted 'foo' --^ ^-- deleted 'bar'
|
||||||
|
# should become just 'foo' not 'foob' (with the delete marker becoming just 'ar'), .
|
||||||
|
next_change = @changes[i+1]
|
||||||
|
is_op_adjacent_to_next_delete = next_change? and next_change.op.d? and op.p == change_end and next_change.op.p == op.p
|
||||||
|
will_op_cancel_next_delete = is_op_adjacent_to_next_delete and next_change.op.d.slice(0, op.i.length) == op.i
|
||||||
|
|
||||||
# If there is a delete at the start of the insert, and we're inserting
|
# If there is a delete at the start of the insert, and we're inserting
|
||||||
# at the start, we SHOULDN'T merge since the delete acts as a partition.
|
# at the start, we SHOULDN'T merge since the delete acts as a partition.
|
||||||
# The previous op will be the delete, but it's already been shifted by this insert
|
# The previous op will be the delete, but it's already been shifted by this insert
|
||||||
@@ -223,6 +236,7 @@ load = (EventEmitter) ->
|
|||||||
is_change_overlapping and
|
is_change_overlapping and
|
||||||
!is_insert_blocked_by_delete and
|
!is_insert_blocked_by_delete and
|
||||||
!already_merged and
|
!already_merged and
|
||||||
|
!will_op_cancel_next_delete and
|
||||||
is_same_user
|
is_same_user
|
||||||
offset = op_start - change_start
|
offset = op_start - change_start
|
||||||
change.op.i = change.op.i.slice(0, offset) + op.i + change.op.i.slice(offset)
|
change.op.i = change.op.i.slice(0, offset) + op.i + change.op.i.slice(offset)
|
||||||
@@ -398,8 +412,8 @@ load = (EventEmitter) ->
|
|||||||
_addOp: (op, metadata) ->
|
_addOp: (op, metadata) ->
|
||||||
change = {
|
change = {
|
||||||
id: @newId()
|
id: @newId()
|
||||||
op: op
|
op: @_clone(op) # Don't take a reference to the existing op since we'll modify this in place with future changes
|
||||||
metadata: metadata
|
metadata: @_clone(metadata)
|
||||||
}
|
}
|
||||||
@changes.push change
|
@changes.push change
|
||||||
|
|
||||||
@@ -472,6 +486,11 @@ load = (EventEmitter) ->
|
|||||||
previous_change = change
|
previous_change = change
|
||||||
return { moved_changes, remove_changes }
|
return { moved_changes, remove_changes }
|
||||||
|
|
||||||
|
_clone: (object) ->
|
||||||
|
clone = {}
|
||||||
|
(clone[k] = v for k,v of object)
|
||||||
|
return clone
|
||||||
|
|
||||||
if define?
|
if define?
|
||||||
define ["utils/EventEmitter"], load
|
define ["utils/EventEmitter"], load
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user