mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Auto select recent changes
This commit is contained in:
parent
b7adaf9f87
commit
5da92dc864
4 changed files with 72 additions and 22 deletions
|
@ -39,6 +39,7 @@ define [
|
|||
leftMenuShown: false
|
||||
view: "editor"
|
||||
}
|
||||
$scope.user = window.user
|
||||
|
||||
window._ide = ide
|
||||
|
||||
|
|
|
@ -93,11 +93,9 @@ define [
|
|||
coords.pageY = coords.pageY - offset.top
|
||||
|
||||
if coords.pageY > 100
|
||||
console.log "middle of page", height - coords.pageY
|
||||
top = "auto"
|
||||
bottom = height - coords.pageY
|
||||
else
|
||||
console.log "top of page", coords.pageY
|
||||
top = coords.pageY + @editor.renderer.lineHeight
|
||||
bottom = "auto"
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ define [
|
|||
$scope.hoveringOverListSelectors = false
|
||||
|
||||
$scope.recalculateSelectedUpdates = () ->
|
||||
console.log "RECALCULATING UPDATES"
|
||||
beforeSelection = true
|
||||
afterSelection = false
|
||||
$scope.trackChanges.selection.updates = []
|
||||
|
@ -65,17 +66,17 @@ define [
|
|||
App.controller "TrackChangesListItemController", ["$scope", ($scope) ->
|
||||
$scope.$watch "update.selectedFrom", (selectedFrom, oldSelectedFrom) ->
|
||||
if selectedFrom
|
||||
console.log "SELECTED FROM CHANGED", $scope.update, selectedFrom, oldSelectedFrom
|
||||
for update in $scope.trackChanges.updates
|
||||
update.selectedFrom = false unless update == $scope.update
|
||||
if selectedFrom != oldSelectedFrom
|
||||
$scope.recalculateSelectedUpdates()
|
||||
$scope.recalculateSelectedUpdates()
|
||||
|
||||
$scope.$watch "update.selectedTo", (selectedTo, oldSelectedTo) ->
|
||||
if selectedTo
|
||||
console.log "SELECTED TO CHANGED", $scope.update, selectedTo, oldSelectedTo
|
||||
for update in $scope.trackChanges.updates
|
||||
update.selectedTo = false unless update == $scope.update
|
||||
if selectedTo != oldSelectedTo
|
||||
$scope.recalculateSelectedUpdates()
|
||||
$scope.recalculateSelectedUpdates()
|
||||
|
||||
$scope.select = () ->
|
||||
$scope.update.selectedTo = true
|
||||
|
|
|
@ -3,6 +3,34 @@ define [
|
|||
], () ->
|
||||
class TrackChangesManager
|
||||
constructor: (@ide, @$scope) ->
|
||||
@reset()
|
||||
|
||||
@$scope.toggleTrackChanges = () =>
|
||||
if @$scope.ui.view == "track-changes"
|
||||
@$scope.ui.view = "editor"
|
||||
else
|
||||
@$scope.ui.view = "track-changes"
|
||||
@onShow()
|
||||
|
||||
@$scope.$watch "trackChanges.selection.updates", (updates) =>
|
||||
if updates? and updates.length > 0
|
||||
@_calculateRangeFromSelection()
|
||||
@_selectDocFromUpdates()
|
||||
@reloadDiff()
|
||||
|
||||
@$scope.$on "entity:selected", (event, entity) =>
|
||||
if (@$scope.ui.view == "track-changes") and (entity.type == "doc")
|
||||
@$scope.trackChanges.selection.doc = entity
|
||||
@$scope.trackChanges.selection.range = @_calculateRangeFromSelection()
|
||||
@reloadDiff()
|
||||
|
||||
onShow: () ->
|
||||
@reset()
|
||||
@fetchNextBatchOfChanges()
|
||||
.success () =>
|
||||
@autoSelectRecentUpdates()
|
||||
|
||||
reset: () ->
|
||||
@$scope.trackChanges = {
|
||||
updates: []
|
||||
nextBeforeTimestamp: null
|
||||
|
@ -20,24 +48,19 @@ define [
|
|||
diff: null
|
||||
}
|
||||
|
||||
@$scope.toggleTrackChanges = () =>
|
||||
if @$scope.ui.view == "track-changes"
|
||||
@$scope.ui.view = "editor"
|
||||
else
|
||||
@$scope.ui.view = "track-changes"
|
||||
autoSelectRecentUpdates: () ->
|
||||
console.log "AUTO SELECTING UPDATES", @$scope.trackChanges.updates.length
|
||||
return if @$scope.trackChanges.updates.length == 0
|
||||
|
||||
@$scope.$on "file-tree:initialized", () =>
|
||||
@fetchNextBatchOfChanges()
|
||||
@$scope.trackChanges.updates[0].selectedTo = true
|
||||
|
||||
@$scope.$watch "trackChanges.selection.updates", () =>
|
||||
@$scope.trackChanges.selection.range = @_calculateRangeFromSelection()
|
||||
@reloadDiff()
|
||||
indexOfLastUpdateNotByMe = 0
|
||||
for update, i in @$scope.trackChanges.updates
|
||||
if @_updateContainsUserId(update, @$scope.user.id)
|
||||
break
|
||||
indexOfLastUpdateNotByMe = i
|
||||
|
||||
@$scope.$on "entity:selected", (event, entity) =>
|
||||
if (@$scope.ui.view == "track-changes") and (entity.type == "doc")
|
||||
@$scope.trackChanges.selection.doc = entity
|
||||
@$scope.trackChanges.selection.range = @_calculateRangeFromSelection()
|
||||
@reloadDiff()
|
||||
@$scope.trackChanges.updates[indexOfLastUpdateNotByMe].selectedFrom = true
|
||||
|
||||
BATCH_SIZE: 4
|
||||
fetchNextBatchOfChanges: () ->
|
||||
|
@ -181,4 +204,31 @@ define [
|
|||
end_ts = update.meta.end_ts
|
||||
break
|
||||
|
||||
return {fromV, toV, start_ts, end_ts}
|
||||
@$scope.trackChanges.selection.range = {fromV, toV, start_ts, end_ts}
|
||||
|
||||
# Set the track changes selected doc to one of the docs in the range
|
||||
# of currently selected updates. If we already have a selected doc
|
||||
# then prefer this one if present.
|
||||
_selectDocFromUpdates: () ->
|
||||
console.log "selecting doc"
|
||||
affected_docs = {}
|
||||
for update in @$scope.trackChanges.selection.updates
|
||||
for doc_id, doc of update.docs
|
||||
affected_docs[doc_id] = true
|
||||
|
||||
selected_doc = @$scope.trackChanges.selection.doc
|
||||
if selected_doc? and affected_docs[selected_doc.id]
|
||||
console.log "An affected doc is already open, bravo!"
|
||||
selected_doc_id = selected_doc.id
|
||||
else
|
||||
console.log "selected doc is not open, selecting first one"
|
||||
for doc_id, doc of affected_docs
|
||||
selected_doc_id = doc_id
|
||||
break
|
||||
|
||||
@$scope.trackChanges.selection.doc = @ide.fileTreeManager.findEntityById(selected_doc_id)
|
||||
|
||||
_updateContainsUserId: (update, user_id) ->
|
||||
for user in update.meta.users
|
||||
return true if user.id == user_id
|
||||
return false
|
||||
|
|
Loading…
Reference in a new issue