mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -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
|
leftMenuShown: false
|
||||||
view: "editor"
|
view: "editor"
|
||||||
}
|
}
|
||||||
|
$scope.user = window.user
|
||||||
|
|
||||||
window._ide = ide
|
window._ide = ide
|
||||||
|
|
||||||
|
|
|
@ -93,11 +93,9 @@ define [
|
||||||
coords.pageY = coords.pageY - offset.top
|
coords.pageY = coords.pageY - offset.top
|
||||||
|
|
||||||
if coords.pageY > 100
|
if coords.pageY > 100
|
||||||
console.log "middle of page", height - coords.pageY
|
|
||||||
top = "auto"
|
top = "auto"
|
||||||
bottom = height - coords.pageY
|
bottom = height - coords.pageY
|
||||||
else
|
else
|
||||||
console.log "top of page", coords.pageY
|
|
||||||
top = coords.pageY + @editor.renderer.lineHeight
|
top = coords.pageY + @editor.renderer.lineHeight
|
||||||
bottom = "auto"
|
bottom = "auto"
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ define [
|
||||||
$scope.hoveringOverListSelectors = false
|
$scope.hoveringOverListSelectors = false
|
||||||
|
|
||||||
$scope.recalculateSelectedUpdates = () ->
|
$scope.recalculateSelectedUpdates = () ->
|
||||||
|
console.log "RECALCULATING UPDATES"
|
||||||
beforeSelection = true
|
beforeSelection = true
|
||||||
afterSelection = false
|
afterSelection = false
|
||||||
$scope.trackChanges.selection.updates = []
|
$scope.trackChanges.selection.updates = []
|
||||||
|
@ -65,16 +66,16 @@ define [
|
||||||
App.controller "TrackChangesListItemController", ["$scope", ($scope) ->
|
App.controller "TrackChangesListItemController", ["$scope", ($scope) ->
|
||||||
$scope.$watch "update.selectedFrom", (selectedFrom, oldSelectedFrom) ->
|
$scope.$watch "update.selectedFrom", (selectedFrom, oldSelectedFrom) ->
|
||||||
if selectedFrom
|
if selectedFrom
|
||||||
|
console.log "SELECTED FROM CHANGED", $scope.update, selectedFrom, oldSelectedFrom
|
||||||
for update in $scope.trackChanges.updates
|
for update in $scope.trackChanges.updates
|
||||||
update.selectedFrom = false unless update == $scope.update
|
update.selectedFrom = false unless update == $scope.update
|
||||||
if selectedFrom != oldSelectedFrom
|
|
||||||
$scope.recalculateSelectedUpdates()
|
$scope.recalculateSelectedUpdates()
|
||||||
|
|
||||||
$scope.$watch "update.selectedTo", (selectedTo, oldSelectedTo) ->
|
$scope.$watch "update.selectedTo", (selectedTo, oldSelectedTo) ->
|
||||||
if selectedTo
|
if selectedTo
|
||||||
|
console.log "SELECTED TO CHANGED", $scope.update, selectedTo, oldSelectedTo
|
||||||
for update in $scope.trackChanges.updates
|
for update in $scope.trackChanges.updates
|
||||||
update.selectedTo = false unless update == $scope.update
|
update.selectedTo = false unless update == $scope.update
|
||||||
if selectedTo != oldSelectedTo
|
|
||||||
$scope.recalculateSelectedUpdates()
|
$scope.recalculateSelectedUpdates()
|
||||||
|
|
||||||
$scope.select = () ->
|
$scope.select = () ->
|
||||||
|
|
|
@ -3,6 +3,34 @@ define [
|
||||||
], () ->
|
], () ->
|
||||||
class TrackChangesManager
|
class TrackChangesManager
|
||||||
constructor: (@ide, @$scope) ->
|
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 = {
|
@$scope.trackChanges = {
|
||||||
updates: []
|
updates: []
|
||||||
nextBeforeTimestamp: null
|
nextBeforeTimestamp: null
|
||||||
|
@ -20,24 +48,19 @@ define [
|
||||||
diff: null
|
diff: null
|
||||||
}
|
}
|
||||||
|
|
||||||
@$scope.toggleTrackChanges = () =>
|
autoSelectRecentUpdates: () ->
|
||||||
if @$scope.ui.view == "track-changes"
|
console.log "AUTO SELECTING UPDATES", @$scope.trackChanges.updates.length
|
||||||
@$scope.ui.view = "editor"
|
return if @$scope.trackChanges.updates.length == 0
|
||||||
else
|
|
||||||
@$scope.ui.view = "track-changes"
|
|
||||||
|
|
||||||
@$scope.$on "file-tree:initialized", () =>
|
@$scope.trackChanges.updates[0].selectedTo = true
|
||||||
@fetchNextBatchOfChanges()
|
|
||||||
|
|
||||||
@$scope.$watch "trackChanges.selection.updates", () =>
|
indexOfLastUpdateNotByMe = 0
|
||||||
@$scope.trackChanges.selection.range = @_calculateRangeFromSelection()
|
for update, i in @$scope.trackChanges.updates
|
||||||
@reloadDiff()
|
if @_updateContainsUserId(update, @$scope.user.id)
|
||||||
|
break
|
||||||
|
indexOfLastUpdateNotByMe = i
|
||||||
|
|
||||||
@$scope.$on "entity:selected", (event, entity) =>
|
@$scope.trackChanges.updates[indexOfLastUpdateNotByMe].selectedFrom = true
|
||||||
if (@$scope.ui.view == "track-changes") and (entity.type == "doc")
|
|
||||||
@$scope.trackChanges.selection.doc = entity
|
|
||||||
@$scope.trackChanges.selection.range = @_calculateRangeFromSelection()
|
|
||||||
@reloadDiff()
|
|
||||||
|
|
||||||
BATCH_SIZE: 4
|
BATCH_SIZE: 4
|
||||||
fetchNextBatchOfChanges: () ->
|
fetchNextBatchOfChanges: () ->
|
||||||
|
@ -181,4 +204,31 @@ define [
|
||||||
end_ts = update.meta.end_ts
|
end_ts = update.meta.end_ts
|
||||||
break
|
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