mirror of
https://github.com/overleaf/overleaf.git
synced 2025-03-15 08:23:08 +00:00
Allow track changes to be toggled on and off
This commit is contained in:
parent
60a81beb11
commit
2ac405e58c
3 changed files with 25 additions and 13 deletions
|
@ -101,7 +101,8 @@ define [
|
||||||
|
|
||||||
# If the insert is overlapping another insert, either at the beginning in the middle or touching the end,
|
# If the insert is overlapping another insert, either at the beginning in the middle or touching the end,
|
||||||
# then we merge them into one.
|
# then we merge them into one.
|
||||||
if is_change_overlapping and
|
if @track_changes and
|
||||||
|
is_change_overlapping and
|
||||||
!is_insert_blocked_by_delete and
|
!is_insert_blocked_by_delete and
|
||||||
!already_merged and
|
!already_merged and
|
||||||
is_same_user
|
is_same_user
|
||||||
|
@ -115,7 +116,7 @@ define [
|
||||||
# If not merged above, then it must be blocked by a delete, and will be after this insert, so we shift it along as well
|
# If not merged above, then it must be blocked by a delete, and will be after this insert, so we shift it along as well
|
||||||
change.op.p += op_length
|
change.op.p += op_length
|
||||||
moved_changes.push change
|
moved_changes.push change
|
||||||
else if !is_same_user and change_start < op_start < change_end
|
else if (!is_same_user or !@track_changes) and change_start < op_start < change_end
|
||||||
# This user is inserting inside a change by another user, so we need to split the
|
# This user is inserting inside a change by another user, so we need to split the
|
||||||
# other user's change into one before and after this one.
|
# other user's change into one before and after this one.
|
||||||
offset = op_start - change_start
|
offset = op_start - change_start
|
||||||
|
@ -139,7 +140,7 @@ define [
|
||||||
|
|
||||||
previous_change = change
|
previous_change = change
|
||||||
|
|
||||||
if !already_merged
|
if @track_changes and !already_merged
|
||||||
@_addOp op, metadata
|
@_addOp op, metadata
|
||||||
for {op, metadata} in new_changes
|
for {op, metadata} in new_changes
|
||||||
@_addOp op, metadata
|
@_addOp op, metadata
|
||||||
|
@ -216,21 +217,27 @@ define [
|
||||||
op_modifications.push modification
|
op_modifications.push modification
|
||||||
else if change.op.d?
|
else if change.op.d?
|
||||||
change_start = change.op.p
|
change_start = change.op.p
|
||||||
if op_end < change_start
|
if op_end < change_start or (!@track_changes and op_end == change_start)
|
||||||
# Shift ops after us (but not touching) back by our length
|
# Shift ops after us back by our length.
|
||||||
|
# If we're tracking changes, it must be strictly before, since we'll merge
|
||||||
|
# below if they are touching. Otherwise, touching is fine.
|
||||||
change.op.p -= op_length
|
change.op.p -= op_length
|
||||||
moved_changes.push change
|
moved_changes.push change
|
||||||
else if op_start <= change_start <= op_end
|
else if op_start <= change_start <= op_end
|
||||||
# If we overlap a delete, add it in our content, and delete the existing change
|
if @track_changes
|
||||||
offset = change_start - op_start
|
# If we overlap a delete, add it in our content, and delete the existing change
|
||||||
op_modifications.push { i: change.op.d, p: offset }
|
offset = change_start - op_start
|
||||||
remove_changes.push change
|
op_modifications.push { i: change.op.d, p: offset }
|
||||||
|
remove_changes.push change
|
||||||
|
else
|
||||||
|
change.op.p = op_start
|
||||||
|
moved_changes.push change
|
||||||
|
|
||||||
for change in remove_changes
|
for change in remove_changes
|
||||||
@_removeChange change
|
@_removeChange change
|
||||||
|
|
||||||
op.d = @_applyOpModifications(op.d, op_modifications)
|
op.d = @_applyOpModifications(op.d, op_modifications)
|
||||||
if op.d.length > 0
|
if @track_changes and op.d.length > 0
|
||||||
@_addOp op, metadata
|
@_addOp op, metadata
|
||||||
else
|
else
|
||||||
# It's possible that we deleted an insert between two other inserts. I.e.
|
# It's possible that we deleted an insert between two other inserts. I.e.
|
||||||
|
@ -240,9 +247,10 @@ define [
|
||||||
# |-- user_1 insert --||-- user_1 insert --|
|
# |-- user_1 insert --||-- user_1 insert --|
|
||||||
# We need to merge these together again
|
# We need to merge these together again
|
||||||
results = @_scanAndMergeAdjacentUpdates()
|
results = @_scanAndMergeAdjacentUpdates()
|
||||||
moved_changed = moved_changes.concat(results.moved_changes)
|
moved_changes = moved_changes.concat(results.moved_changes)
|
||||||
for change in results.remove_changes
|
for change in results.remove_changes
|
||||||
@_removeChange change
|
@_removeChange change
|
||||||
|
moved_changes = moved_changes.filter (c) -> c != change
|
||||||
|
|
||||||
if moved_changes.length > 0
|
if moved_changes.length > 0
|
||||||
@emit "changes:moved", moved_changes
|
@emit "changes:moved", moved_changes
|
||||||
|
|
|
@ -9,19 +9,25 @@ define [
|
||||||
|
|
||||||
constructor: (@$scope, @editor, @element) ->
|
constructor: (@$scope, @editor, @element) ->
|
||||||
@changesTracker = new ChangesTracker()
|
@changesTracker = new ChangesTracker()
|
||||||
|
@changesTracker.track_changes = true
|
||||||
@changeIdToMarkerIdMap = {}
|
@changeIdToMarkerIdMap = {}
|
||||||
@enabled = false
|
@enabled = false
|
||||||
window.changesTracker ?= @changesTracker
|
window.changesTracker ?= @changesTracker
|
||||||
|
|
||||||
@changesTracker.on "insert:added", (change) =>
|
@changesTracker.on "insert:added", (change) =>
|
||||||
|
sl_console.log "[insert:added]", change
|
||||||
@_onInsertAdded(change)
|
@_onInsertAdded(change)
|
||||||
@changesTracker.on "insert:removed", (change) =>
|
@changesTracker.on "insert:removed", (change) =>
|
||||||
|
sl_console.log "[insert:removed]", change
|
||||||
@_onInsertRemoved(change)
|
@_onInsertRemoved(change)
|
||||||
@changesTracker.on "delete:added", (change) =>
|
@changesTracker.on "delete:added", (change) =>
|
||||||
|
sl_console.log "[delete:added]", change
|
||||||
@_onDeleteAdded(change)
|
@_onDeleteAdded(change)
|
||||||
@changesTracker.on "delete:removed", (change) =>
|
@changesTracker.on "delete:removed", (change) =>
|
||||||
|
sl_console.log "[delete:removed]", change
|
||||||
@_onDeleteRemoved(change)
|
@_onDeleteRemoved(change)
|
||||||
@changesTracker.on "changes:moved", (changes) =>
|
@changesTracker.on "changes:moved", (changes) =>
|
||||||
|
sl_console.log "[changes:moved]", changes
|
||||||
@_onChangesMoved(changes)
|
@_onChangesMoved(changes)
|
||||||
|
|
||||||
onChange = (e) =>
|
onChange = (e) =>
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
define [
|
define [
|
||||||
"base"
|
"base"
|
||||||
], (App) ->
|
], (App) ->
|
||||||
console.log "Defingint", "reviePanelSorted"
|
|
||||||
App.directive "reviewPanelSorted", () ->
|
App.directive "reviewPanelSorted", () ->
|
||||||
return {
|
return {
|
||||||
link: (scope, element, attrs) ->
|
link: (scope, element, attrs) ->
|
||||||
scope.$watch "reviewPanel.entries", (value) ->
|
scope.$watch "reviewPanel.entries", (value) ->
|
||||||
return if !value?
|
return if !value?
|
||||||
console.log "reviewPanel.entries updates", entries
|
|
||||||
entries = []
|
entries = []
|
||||||
for el in element.find(".review-entry")
|
for el in element.find(".review-entry")
|
||||||
entries.push {
|
entries.push {
|
||||||
|
|
Loading…
Reference in a new issue