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