mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Allow changing between files while in diff view mode
This commit is contained in:
parent
b99eaecf82
commit
237f738650
7 changed files with 94 additions and 26 deletions
|
@ -35,6 +35,8 @@ define [
|
|||
identifier: "editor"
|
||||
element: @editorPanel
|
||||
@initializeEditor()
|
||||
@bindToFileTreeEvents()
|
||||
@enable()
|
||||
@loadingIndicator = $(@templates.loadingIndicator)
|
||||
@editorPanel.find("#editor").append(@loadingIndicator)
|
||||
@leftPanel = @editorPanel.find("#leftEditorPanel")
|
||||
|
@ -42,6 +44,11 @@ define [
|
|||
@initSplitView()
|
||||
@switchToFlatView()
|
||||
|
||||
bindToFileTreeEvents: () ->
|
||||
@ide.fileTreeManager.on "open:doc", (doc_id, options = {}) =>
|
||||
if @enabled
|
||||
@openDoc doc_id, options
|
||||
|
||||
initSplitView: () ->
|
||||
splitter = @editorPanel.find("#editorSplitter")
|
||||
options =
|
||||
|
@ -351,3 +358,9 @@ define [
|
|||
|
||||
getCurrentDocId: () ->
|
||||
@current_doc_id
|
||||
|
||||
enable: () ->
|
||||
@enabled = true
|
||||
|
||||
disable: () ->
|
||||
@enabled = false
|
||||
|
|
|
@ -76,7 +76,7 @@ define [
|
|||
|
||||
openDoc: (doc, line) ->
|
||||
doc_id = doc.id or doc
|
||||
@ide.editor.openDoc(doc_id, line: line)
|
||||
@trigger "open:doc", doc_id, line: line
|
||||
@selectEntity(doc_id)
|
||||
$.localStorage "doc.open_id.#{@project_id}", doc_id
|
||||
|
||||
|
@ -86,8 +86,7 @@ define [
|
|||
@openDoc(doc_id, line)
|
||||
|
||||
openFile: (file) ->
|
||||
@ide.mainAreaManager.change('file')
|
||||
@ide.fileViewManager.showFile(file)
|
||||
@trigger "open:file", file
|
||||
@selectEntity(file.id)
|
||||
|
||||
openFolder: (folder) ->
|
||||
|
|
|
@ -13,5 +13,20 @@ define [
|
|||
@ide.layoutManager.on "resize", () => @view.onResize()
|
||||
@view.onResize()
|
||||
|
||||
@bindToFileTreeEvents()
|
||||
@enable()
|
||||
|
||||
bindToFileTreeEvents: () ->
|
||||
@ide.fileTreeManager.on "open:file", (file) =>
|
||||
if @enabled
|
||||
@showFile(file)
|
||||
|
||||
showFile: (file) ->
|
||||
@ide.mainAreaManager.change('file')
|
||||
@view.setModel(file)
|
||||
|
||||
enable: () ->
|
||||
@enabled = true
|
||||
|
||||
disable: () ->
|
||||
@enabled = false
|
||||
|
|
|
@ -106,12 +106,12 @@ define [
|
|||
@sideBarView = new SideBarManager(@, $("#sections"))
|
||||
selectElement = @sideBarView.selectElement
|
||||
mainAreaManager = @mainAreaManager = new MainAreaManager(@, $("#content"))
|
||||
@fileTreeManager = new FileTreeManager(@)
|
||||
@editor = new Editor(@)
|
||||
@pdfManager = new PdfManager(@)
|
||||
if @userSettings.autoComplete
|
||||
@autoCompleteManager = new AutoCompleteManager(@)
|
||||
@spellingManager = new SpellingManager(@)
|
||||
@fileTreeManager = new FileTreeManager(@)
|
||||
@fileUploadManager = new FileUploadManager(@)
|
||||
@searchManager = new SearchManager(@)
|
||||
@cursorManager = new CursorManager(@)
|
||||
|
|
|
@ -243,20 +243,20 @@ define [
|
|||
@$(".change-selector-to").prop("checked", checked)
|
||||
|
||||
setSelected: (first, last) ->
|
||||
@$el.addClass("selected")
|
||||
@$el.addClass("selected-change")
|
||||
if first
|
||||
@$el.addClass("selected-to")
|
||||
@$el.addClass("selected-change-to")
|
||||
else
|
||||
@$el.removeClass("selected-to")
|
||||
@$el.removeClass("selected-change-to")
|
||||
if last
|
||||
@$el.addClass("selected-from")
|
||||
@$el.addClass("selected-change-from")
|
||||
else
|
||||
@$el.removeClass("selected-from")
|
||||
@$el.removeClass("selected-change-from")
|
||||
|
||||
setUnselected: () ->
|
||||
@$el.removeClass("selected-to")
|
||||
@$el.removeClass("selected-from")
|
||||
@$el.removeClass("selected")
|
||||
@$el.removeClass("selected-change-to")
|
||||
@$el.removeClass("selected-change-from")
|
||||
@$el.removeClass("selected-change")
|
||||
|
||||
setHoverSelected: (first, last) ->
|
||||
@$el.addClass("hover-selected")
|
||||
|
|
|
@ -24,6 +24,16 @@ define [
|
|||
e.preventDefault
|
||||
@hide()
|
||||
|
||||
@bindToFileTreeEvents()
|
||||
|
||||
@disable()
|
||||
|
||||
bindToFileTreeEvents: () ->
|
||||
@ide.fileTreeManager.on "open:doc", (doc_id) =>
|
||||
if @enabled
|
||||
@doc_id = doc_id
|
||||
@updateDiff()
|
||||
|
||||
@ide.fileTreeManager.on "contextmenu:beforeshow", (entity, entries) =>
|
||||
if entity instanceof Doc
|
||||
entries.push {
|
||||
|
@ -31,12 +41,11 @@ define [
|
|||
}, {
|
||||
text: "History"
|
||||
onClick: () =>
|
||||
@show(entity.id)
|
||||
@doc_id = entity.id
|
||||
@show()
|
||||
}
|
||||
|
||||
show: (@doc_id) ->
|
||||
@ide.fileTreeManager.selectEntity(@doc_id)
|
||||
|
||||
show: () ->
|
||||
@changes = new ChangeList([], project_id: @project_id, ide: @ide)
|
||||
|
||||
@changeListView = new ChangeListView(
|
||||
|
@ -48,7 +57,7 @@ define [
|
|||
@autoSelectDiff()
|
||||
|
||||
@changeListView.on "change_diff", (fromIndex, toIndex) =>
|
||||
@showDiff(fromIndex, toIndex)
|
||||
@selectDocAndUpdateDiff(fromIndex, toIndex)
|
||||
|
||||
@changeListView.on "restore", (change) =>
|
||||
@restore(change)
|
||||
|
@ -57,9 +66,16 @@ define [
|
|||
@diffView.destroy()
|
||||
|
||||
@ide.mainAreaManager.change "trackChanges"
|
||||
@ide.editor.disable()
|
||||
@ide.fileViewManager.disable()
|
||||
@enable()
|
||||
|
||||
hide: () ->
|
||||
@ide.editor.enable()
|
||||
@ide.fileViewManager.enable()
|
||||
@disable()
|
||||
@ide.fileTreeManager.openDoc(@doc_id)
|
||||
@ide.mainAreaManager.change "editor"
|
||||
|
||||
autoSelectDiff: () ->
|
||||
if @changes.models.length == 0
|
||||
|
@ -78,13 +94,29 @@ define [
|
|||
|
||||
toChange = @changes.models[0]
|
||||
fromChange = @changes.models[fromIndex]
|
||||
@showDiff(fromChange, toChange)
|
||||
@changeListView.setSelectionRange(fromIndex, 0)
|
||||
@updateDiff()
|
||||
|
||||
showDiff: (fromIndex, toIndex) ->
|
||||
doc_id = @doc_id
|
||||
selectDocAndUpdateDiff: (fromIndex, toIndex) ->
|
||||
doc_ids = []
|
||||
for change in @changes.models.slice(toIndex, fromIndex + 1)
|
||||
for doc in change.get("docs") or []
|
||||
doc_ids.push doc.id if doc.id not in doc_ids
|
||||
|
||||
{from, to} = @_findDocVersionsRangeInSelection(doc_id, fromIndex, toIndex)
|
||||
if !@doc_id? or @doc_id not in doc_ids
|
||||
@doc_id = doc_ids[0]
|
||||
|
||||
@updateDiff()
|
||||
|
||||
updateDiff: () ->
|
||||
fromIndex = @changeListView.selectedFromIndex
|
||||
toIndex = @changeListView.selectedToIndex
|
||||
|
||||
if !toIndex? or !fromIndex?
|
||||
console.log "No selection - what should we do!?"
|
||||
return
|
||||
|
||||
{from, to} = @_findDocVersionsRangeInSelection(@doc_id, fromIndex, toIndex)
|
||||
|
||||
if !from? or !to?
|
||||
console.log "No diff, should probably just show latest version"
|
||||
|
@ -92,7 +124,7 @@ define [
|
|||
|
||||
@diff = new Diff({
|
||||
project_id: @project_id
|
||||
doc_id: doc_id
|
||||
doc_id: @doc_id
|
||||
from: from
|
||||
to: to
|
||||
})
|
||||
|
@ -105,6 +137,9 @@ define [
|
|||
)
|
||||
@diff.fetch()
|
||||
|
||||
@ide.fileTreeManager.selectEntity(@doc_id)
|
||||
|
||||
|
||||
_findDocVersionsRangeInSelection: (doc_id, fromIndex, toIndex) ->
|
||||
from = null
|
||||
to = null
|
||||
|
@ -155,4 +190,10 @@ define [
|
|||
callback(error)
|
||||
}
|
||||
|
||||
enable: () ->
|
||||
@enabled = true
|
||||
|
||||
disable: () ->
|
||||
@enabled = false
|
||||
|
||||
return TrackChangesManager
|
||||
|
|
|
@ -160,7 +160,7 @@
|
|||
li.loading-changes, li.empty-message {
|
||||
padding: 6px;
|
||||
}
|
||||
li.selected {
|
||||
li.selected-change {
|
||||
background-color: #eaeaea;
|
||||
.change-selectors {
|
||||
.range {
|
||||
|
@ -168,7 +168,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
li.selected-to {
|
||||
li.selected-change-to {
|
||||
.change-selectors {
|
||||
.range {
|
||||
top: 10px;
|
||||
|
@ -178,7 +178,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
li.selected-from {
|
||||
li.selected-change-from {
|
||||
.change-selectors {
|
||||
.range {
|
||||
bottom: 37px;
|
||||
|
@ -230,7 +230,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
li.selected-from.hover-selected-from {
|
||||
li.selected-change-from.hover-selected-from {
|
||||
.change-selectors {
|
||||
.range {
|
||||
bottom: 37px;
|
||||
|
|
Loading…
Reference in a new issue