mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 10:10:38 -05:00
Merge branch 'ja-review-panel' of github.com:sharelatex/web-sharelatex into ja-review-panel
This commit is contained in:
commit
9a4ee0470a
3 changed files with 99 additions and 81 deletions
|
@ -53,6 +53,9 @@ define [
|
||||||
|
|
||||||
@$scope.$on "comment:unresolve", (e, comment_id) =>
|
@$scope.$on "comment:unresolve", (e, comment_id) =>
|
||||||
@unresolveCommentId(comment_id)
|
@unresolveCommentId(comment_id)
|
||||||
|
|
||||||
|
@$scope.$on "review-panel:recalculate-screen-positions", () =>
|
||||||
|
@recalculateReviewEntriesScreenPositions()
|
||||||
|
|
||||||
onChange = (e) =>
|
onChange = (e) =>
|
||||||
if !@editor.initing and @enabled
|
if !@editor.initing and @enabled
|
||||||
|
@ -255,77 +258,15 @@ define [
|
||||||
op = @_aceChangeToShareJs(delta)
|
op = @_aceChangeToShareJs(delta)
|
||||||
@changesTracker.applyOp(op, metadata)
|
@changesTracker.applyOp(op, metadata)
|
||||||
|
|
||||||
updateReviewEntriesScope: () ->
|
|
||||||
entries = @_getCurrentDocEntries()
|
|
||||||
|
|
||||||
# Assume we'll delete everything until we see it, then we'll remove it from this object
|
|
||||||
delete_changes = {}
|
|
||||||
delete_changes[change_id] = true for change_id, change of entries
|
|
||||||
|
|
||||||
for change in @changesTracker.changes
|
|
||||||
delete delete_changes[change.id]
|
|
||||||
entries[change.id] ?= {}
|
|
||||||
|
|
||||||
# Update in place to avoid a full DOM redraw via angular
|
|
||||||
metadata = {}
|
|
||||||
metadata[key] = value for key, value of change.metadata
|
|
||||||
new_entry = {
|
|
||||||
type: if change.op.i then "insert" else "delete"
|
|
||||||
content: change.op.i or change.op.d
|
|
||||||
offset: change.op.p
|
|
||||||
metadata: change.metadata
|
|
||||||
}
|
|
||||||
for key, value of new_entry
|
|
||||||
entries[change.id][key] = value
|
|
||||||
|
|
||||||
for comment in @changesTracker.comments
|
|
||||||
delete delete_changes[comment.id]
|
|
||||||
entries[comment.id] ?= {}
|
|
||||||
new_entry = {
|
|
||||||
type: "comment"
|
|
||||||
thread: comment.metadata.thread
|
|
||||||
resolved: comment.metadata.resolved
|
|
||||||
offset: comment.offset
|
|
||||||
length: comment.length
|
|
||||||
}
|
|
||||||
for key, value of new_entry
|
|
||||||
entries[comment.id][key] = value
|
|
||||||
|
|
||||||
for change_id, _ of delete_changes
|
|
||||||
delete entries[change_id]
|
|
||||||
|
|
||||||
@updateFocus()
|
|
||||||
@recalculateReviewEntriesScreenPositions()
|
|
||||||
|
|
||||||
updateFocus: () ->
|
updateFocus: () ->
|
||||||
@updateEntryGeneration()
|
|
||||||
selection = @editor.getSelectionRange()
|
selection = @editor.getSelectionRange()
|
||||||
cursor_offset = @_aceRangeToShareJs(selection.start)
|
cursor_offset = @_aceRangeToShareJs(selection.start)
|
||||||
entries = @_getCurrentDocEntries()
|
entries = @_getCurrentDocEntries()
|
||||||
|
selection = !(selection.start.column == selection.end.column and selection.start.row == selection.end.row)
|
||||||
if selection.start.column == selection.end.column and selection.start.row == selection.end.row
|
@$scope.$emit "editor:focus:changed", cursor_offset, selection
|
||||||
# No selection
|
|
||||||
delete entries["add-comment"]
|
|
||||||
else
|
|
||||||
entries["add-comment"] = {
|
|
||||||
type: "add-comment"
|
|
||||||
offset: cursor_offset
|
|
||||||
}
|
|
||||||
|
|
||||||
for id, entry of entries
|
|
||||||
if entry.type == "comment" and not entry.resolved
|
|
||||||
entry.focused = (entry.offset <= cursor_offset <= entry.offset + entry.length)
|
|
||||||
else if entry.type == "insert"
|
|
||||||
entry.focused = (entry.offset <= cursor_offset <= entry.offset + entry.content.length)
|
|
||||||
else if entry.type == "delete"
|
|
||||||
entry.focused = (entry.offset == cursor_offset)
|
|
||||||
else if entry.type == "add-comment" and !selection.isEmpty()
|
|
||||||
entry.focused = true
|
|
||||||
|
|
||||||
updateEntryGeneration: () ->
|
broadcastChange: () ->
|
||||||
# Rather than making angular deep watch the whole entries array
|
@$scope.$emit "editor:track-changes:changed", @$scope.docId
|
||||||
@$scope.reviewPanel.entryGeneration ?= 0
|
|
||||||
@$scope.reviewPanel.entryGeneration++
|
|
||||||
|
|
||||||
recalculateReviewEntriesScreenPositions: () ->
|
recalculateReviewEntriesScreenPositions: () ->
|
||||||
session = @editor.getSession()
|
session = @editor.getSession()
|
||||||
|
@ -376,7 +317,7 @@ define [
|
||||||
background_marker_id = session.addMarker background_range, "track-changes-marker track-changes-added-marker", "text"
|
background_marker_id = session.addMarker background_range, "track-changes-marker track-changes-added-marker", "text"
|
||||||
callout_marker_id = @_createCalloutMarker(start, "track-changes-added-marker-callout")
|
callout_marker_id = @_createCalloutMarker(start, "track-changes-added-marker-callout")
|
||||||
@changeIdToMarkerIdMap[change.id] = { background_marker_id, callout_marker_id }
|
@changeIdToMarkerIdMap[change.id] = { background_marker_id, callout_marker_id }
|
||||||
@updateReviewEntriesScope()
|
@broadcastChange()
|
||||||
|
|
||||||
_onDeleteAdded: (change) ->
|
_onDeleteAdded: (change) ->
|
||||||
position = @_shareJsOffsetToAcePosition(change.op.p)
|
position = @_shareJsOffsetToAcePosition(change.op.p)
|
||||||
|
@ -391,7 +332,7 @@ define [
|
||||||
|
|
||||||
callout_marker_id = @_createCalloutMarker(position, "track-changes-deleted-marker-callout")
|
callout_marker_id = @_createCalloutMarker(position, "track-changes-deleted-marker-callout")
|
||||||
@changeIdToMarkerIdMap[change.id] = { background_marker_id, callout_marker_id }
|
@changeIdToMarkerIdMap[change.id] = { background_marker_id, callout_marker_id }
|
||||||
@updateReviewEntriesScope()
|
@broadcastChange()
|
||||||
|
|
||||||
_onInsertRemoved: (change) ->
|
_onInsertRemoved: (change) ->
|
||||||
{background_marker_id, callout_marker_id} = @changeIdToMarkerIdMap[change.id]
|
{background_marker_id, callout_marker_id} = @changeIdToMarkerIdMap[change.id]
|
||||||
|
@ -399,7 +340,7 @@ define [
|
||||||
session = @editor.getSession()
|
session = @editor.getSession()
|
||||||
session.removeMarker background_marker_id
|
session.removeMarker background_marker_id
|
||||||
session.removeMarker callout_marker_id
|
session.removeMarker callout_marker_id
|
||||||
@updateReviewEntriesScope()
|
@broadcastChange()
|
||||||
|
|
||||||
_onDeleteRemoved: (change) ->
|
_onDeleteRemoved: (change) ->
|
||||||
{background_marker_id, callout_marker_id} = @changeIdToMarkerIdMap[change.id]
|
{background_marker_id, callout_marker_id} = @changeIdToMarkerIdMap[change.id]
|
||||||
|
@ -407,7 +348,7 @@ define [
|
||||||
session = @editor.getSession()
|
session = @editor.getSession()
|
||||||
session.removeMarker background_marker_id
|
session.removeMarker background_marker_id
|
||||||
session.removeMarker callout_marker_id
|
session.removeMarker callout_marker_id
|
||||||
@updateReviewEntriesScope()
|
@broadcastChange()
|
||||||
|
|
||||||
_onCommentAdded: (comment) ->
|
_onCommentAdded: (comment) ->
|
||||||
if !@changeIdToMarkerIdMap[comment.id]?
|
if !@changeIdToMarkerIdMap[comment.id]?
|
||||||
|
@ -420,7 +361,7 @@ define [
|
||||||
background_marker_id = session.addMarker background_range, "track-changes-marker track-changes-comment-marker", "text"
|
background_marker_id = session.addMarker background_range, "track-changes-marker track-changes-comment-marker", "text"
|
||||||
callout_marker_id = @_createCalloutMarker(start, "track-changes-comment-marker-callout")
|
callout_marker_id = @_createCalloutMarker(start, "track-changes-comment-marker-callout")
|
||||||
@changeIdToMarkerIdMap[comment.id] = { background_marker_id, callout_marker_id }
|
@changeIdToMarkerIdMap[comment.id] = { background_marker_id, callout_marker_id }
|
||||||
@updateReviewEntriesScope()
|
@broadcastChange()
|
||||||
|
|
||||||
_onCommentRemoved: (comment) ->
|
_onCommentRemoved: (comment) ->
|
||||||
if @changeIdToMarkerIdMap[comment.id]?
|
if @changeIdToMarkerIdMap[comment.id]?
|
||||||
|
@ -430,7 +371,7 @@ define [
|
||||||
session = @editor.getSession()
|
session = @editor.getSession()
|
||||||
session.removeMarker background_marker_id
|
session.removeMarker background_marker_id
|
||||||
session.removeMarker callout_marker_id
|
session.removeMarker callout_marker_id
|
||||||
@updateReviewEntriesScope()
|
@broadcastChange()
|
||||||
|
|
||||||
_aceRangeToShareJs: (range) ->
|
_aceRangeToShareJs: (range) ->
|
||||||
lines = @editor.getSession().getDocument().getLines 0, range.row
|
lines = @editor.getSession().getDocument().getLines 0, range.row
|
||||||
|
@ -472,14 +413,14 @@ define [
|
||||||
end = start
|
end = start
|
||||||
@_updateMarker(change.id, start, end)
|
@_updateMarker(change.id, start, end)
|
||||||
@editor.renderer.updateBackMarkers()
|
@editor.renderer.updateBackMarkers()
|
||||||
@updateReviewEntriesScope()
|
@broadcastChange()
|
||||||
|
|
||||||
_onCommentMoved: (comment) ->
|
_onCommentMoved: (comment) ->
|
||||||
start = @_shareJsOffsetToAcePosition(comment.offset)
|
start = @_shareJsOffsetToAcePosition(comment.offset)
|
||||||
end = @_shareJsOffsetToAcePosition(comment.offset + comment.length)
|
end = @_shareJsOffsetToAcePosition(comment.offset + comment.length)
|
||||||
@_updateMarker(comment.id, start, end)
|
@_updateMarker(comment.id, start, end)
|
||||||
@editor.renderer.updateBackMarkers()
|
@editor.renderer.updateBackMarkers()
|
||||||
@updateReviewEntriesScope()
|
@broadcastChange()
|
||||||
|
|
||||||
_updateMarker: (change_id, start, end) ->
|
_updateMarker: (change_id, start, end) ->
|
||||||
return if !@changeIdToMarkerIdMap[change_id]?
|
return if !@changeIdToMarkerIdMap[change_id]?
|
||||||
|
|
|
@ -26,6 +26,14 @@ define [
|
||||||
|
|
||||||
changesTrackers = {}
|
changesTrackers = {}
|
||||||
|
|
||||||
|
getDocEntries = (doc_id) ->
|
||||||
|
$scope.reviewPanel.entries[doc_id] ?= {}
|
||||||
|
return $scope.reviewPanel.entries[doc_id]
|
||||||
|
|
||||||
|
getChangeTracker = (doc_id) ->
|
||||||
|
changesTrackers[doc_id] ?= new ChangesTracker()
|
||||||
|
return changesTrackers[doc_id]
|
||||||
|
|
||||||
# TODO Just for prototyping purposes; remove afterwards.
|
# TODO Just for prototyping purposes; remove afterwards.
|
||||||
mockedUserId = 'mock_user_id_1'
|
mockedUserId = 'mock_user_id_1'
|
||||||
mockedUserId2 = 'mock_user_id_2'
|
mockedUserId2 = 'mock_user_id_2'
|
||||||
|
@ -107,11 +115,13 @@ define [
|
||||||
ide.$scope.$on "file-tree:initialized", () ->
|
ide.$scope.$on "file-tree:initialized", () ->
|
||||||
ide.fileTreeManager.forEachEntity (entity) ->
|
ide.fileTreeManager.forEachEntity (entity) ->
|
||||||
if mock_changes[entity.name]?
|
if mock_changes[entity.name]?
|
||||||
changesTrackers[entity.id] ?= new ChangesTracker()
|
changesTracker = getChangeTracker(entity.id)
|
||||||
for change in mock_changes[entity.name].changes
|
for change in mock_changes[entity.name].changes
|
||||||
changesTrackers[entity.id]._addOp change.op, change.metadata
|
changesTracker._addOp change.op, change.metadata
|
||||||
for comment in mock_changes[entity.name].comments
|
for comment in mock_changes[entity.name].comments
|
||||||
changesTrackers[entity.id].addComment comment.offset, comment.length, comment.metadata
|
changesTracker.addComment comment.offset, comment.length, comment.metadata
|
||||||
|
for doc_id, changesTracker of changesTrackers
|
||||||
|
updateEntries(doc_id)
|
||||||
|
|
||||||
scrollbar = {}
|
scrollbar = {}
|
||||||
$scope.reviewPanelEventsBridge.on "aceScrollbarVisibilityChanged", (isVisible, scrollbarWidth) ->
|
$scope.reviewPanelEventsBridge.on "aceScrollbarVisibilityChanged", (isVisible, scrollbarWidth) ->
|
||||||
|
@ -155,6 +165,77 @@ define [
|
||||||
$scope.$broadcast "review-panel:toggle"
|
$scope.$broadcast "review-panel:toggle"
|
||||||
$scope.$broadcast "review-panel:layout"
|
$scope.$broadcast "review-panel:layout"
|
||||||
|
|
||||||
|
updateEntries = (doc_id) ->
|
||||||
|
changesTracker = getChangeTracker(doc_id)
|
||||||
|
entries = getDocEntries(doc_id)
|
||||||
|
|
||||||
|
# Assume we'll delete everything until we see it, then we'll remove it from this object
|
||||||
|
delete_changes = {}
|
||||||
|
delete_changes[change_id] = true for change_id, change of entries
|
||||||
|
|
||||||
|
for change in changesTracker.changes
|
||||||
|
delete delete_changes[change.id]
|
||||||
|
entries[change.id] ?= {}
|
||||||
|
|
||||||
|
# Update in place to avoid a full DOM redraw via angular
|
||||||
|
metadata = {}
|
||||||
|
metadata[key] = value for key, value of change.metadata
|
||||||
|
new_entry = {
|
||||||
|
type: if change.op.i then "insert" else "delete"
|
||||||
|
content: change.op.i or change.op.d
|
||||||
|
offset: change.op.p
|
||||||
|
metadata: change.metadata
|
||||||
|
}
|
||||||
|
for key, value of new_entry
|
||||||
|
entries[change.id][key] = value
|
||||||
|
|
||||||
|
for comment in changesTracker.comments
|
||||||
|
delete delete_changes[comment.id]
|
||||||
|
entries[comment.id] ?= {}
|
||||||
|
new_entry = {
|
||||||
|
type: "comment"
|
||||||
|
thread: comment.metadata.thread
|
||||||
|
resolved: comment.metadata.resolved
|
||||||
|
offset: comment.offset
|
||||||
|
length: comment.length
|
||||||
|
}
|
||||||
|
for key, value of new_entry
|
||||||
|
entries[comment.id][key] = value
|
||||||
|
|
||||||
|
for change_id, _ of delete_changes
|
||||||
|
delete entries[change_id]
|
||||||
|
|
||||||
|
$scope.$on "editor:track-changes:changed", () ->
|
||||||
|
doc_id = $scope.editor.open_doc_id
|
||||||
|
updateEntries(doc_id)
|
||||||
|
$scope.$broadcast "review-panel:recalculate-screen-positions"
|
||||||
|
$scope.$broadcast "review-panel:layout"
|
||||||
|
|
||||||
|
$scope.$on "editor:focus:changed", (e, cursor_offset, selection) ->
|
||||||
|
doc_id = $scope.editor.open_doc_id
|
||||||
|
entries = getDocEntries(doc_id)
|
||||||
|
|
||||||
|
if !selection
|
||||||
|
delete entries["add-comment"]
|
||||||
|
else
|
||||||
|
entries["add-comment"] = {
|
||||||
|
type: "add-comment"
|
||||||
|
offset: cursor_offset
|
||||||
|
}
|
||||||
|
|
||||||
|
for id, entry of entries
|
||||||
|
if entry.type == "comment" and not entry.resolved
|
||||||
|
entry.focused = (entry.offset <= cursor_offset <= entry.offset + entry.length)
|
||||||
|
else if entry.type == "insert"
|
||||||
|
entry.focused = (entry.offset <= cursor_offset <= entry.offset + entry.content.length)
|
||||||
|
else if entry.type == "delete"
|
||||||
|
entry.focused = (entry.offset == cursor_offset)
|
||||||
|
else if entry.type == "add-comment" and selection
|
||||||
|
entry.focused = true
|
||||||
|
|
||||||
|
$scope.$broadcast "review-panel:recalculate-screen-positions"
|
||||||
|
$scope.$broadcast "review-panel:layout"
|
||||||
|
|
||||||
$scope.acceptChange = (entry_id) ->
|
$scope.acceptChange = (entry_id) ->
|
||||||
$scope.$broadcast "change:accept", entry_id
|
$scope.$broadcast "change:accept", entry_id
|
||||||
|
|
||||||
|
|
|
@ -81,10 +81,6 @@ define [
|
||||||
|
|
||||||
scope.$applyAsync () ->
|
scope.$applyAsync () ->
|
||||||
layout()
|
layout()
|
||||||
|
|
||||||
scope.$watch "reviewPanel.entryGeneration", (value) ->
|
|
||||||
scope.$applyAsync () ->
|
|
||||||
layout()
|
|
||||||
|
|
||||||
scope.$on "review-panel:layout", () ->
|
scope.$on "review-panel:layout", () ->
|
||||||
scope.$applyAsync () ->
|
scope.$applyAsync () ->
|
||||||
|
|
Loading…
Reference in a new issue