mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Load diff for selected doc
This commit is contained in:
parent
c0686b6592
commit
9fa80ad757
2 changed files with 35 additions and 7 deletions
|
@ -112,7 +112,7 @@ define [
|
|||
view.setHoverUnselected()
|
||||
|
||||
triggerChangeDiff: () ->
|
||||
@trigger "change_diff", @collection.models[@selectedFromIndex], @collection.models[@selectedToIndex]
|
||||
@trigger "change_diff", @selectedFromIndex, @selectedToIndex
|
||||
|
||||
listShorterThanContainer: ->
|
||||
@$el.height() > @$(".change-list").height()
|
||||
|
|
|
@ -49,8 +49,8 @@ define [
|
|||
@changeListView.loadUntilFull (error) =>
|
||||
@autoSelectDiff()
|
||||
|
||||
@changeListView.on "change_diff", (fromModel, toModel) =>
|
||||
@showDiff(fromModel, toModel)
|
||||
@changeListView.on "change_diff", (fromIndex, toIndex) =>
|
||||
@showDiff(fromIndex, toIndex)
|
||||
|
||||
@changeListView.on "restore", (change) =>
|
||||
@restore(change)
|
||||
|
@ -84,12 +84,20 @@ define [
|
|||
@showDiff(fromChange, toChange)
|
||||
@changeListView.setSelectionRange(fromIndex, 0)
|
||||
|
||||
showDiff: (fromModel, toModel) ->
|
||||
showDiff: (fromIndex, toIndex) ->
|
||||
doc_id = @doc_id
|
||||
|
||||
{from, to} = @_findDocVersionsRangeInSelection(doc_id, fromIndex, toIndex)
|
||||
|
||||
if !from? or !to?
|
||||
console.log "No diff, should probably just show latest version"
|
||||
return
|
||||
|
||||
@diff = new Diff({
|
||||
project_id: @project_id
|
||||
doc_id: @doc_id
|
||||
from: fromModel.get("fromVersion")
|
||||
to: toModel.get("toVersion")
|
||||
doc_id: doc_id
|
||||
from: from
|
||||
to: to
|
||||
})
|
||||
|
||||
if @diffView?
|
||||
|
@ -100,6 +108,26 @@ define [
|
|||
)
|
||||
@diff.fetch()
|
||||
|
||||
_findDocVersionsRangeInSelection: (doc_id, fromIndex, toIndex) ->
|
||||
from = null
|
||||
to = null
|
||||
|
||||
for change in @changes.models.slice(toIndex, fromIndex + 1)
|
||||
console.log "considering change"
|
||||
for doc in change.get("docs")
|
||||
console.log "considering doc", doc.id, doc_id
|
||||
if doc.id == doc_id
|
||||
if from? and to?
|
||||
from = Math.min(from, doc.fromV)
|
||||
to = Math.max(to, doc.toV)
|
||||
else
|
||||
from = doc.fromV
|
||||
to = doc.toV
|
||||
break
|
||||
console.log "Done", from, to
|
||||
|
||||
return {from, to}
|
||||
|
||||
showEl: ->
|
||||
@ide.editor.hide()
|
||||
@$el.show()
|
||||
|
|
Loading…
Reference in a new issue