Merge branch 'ja-review-panel' of github.com:sharelatex/web-sharelatex into ja-review-panel

This commit is contained in:
Paulo Reis 2016-11-21 16:58:22 +00:00
commit 9a4ee0470a
3 changed files with 99 additions and 81 deletions

View file

@ -54,6 +54,9 @@ define [
@$scope.$on "comment:unresolve", (e, comment_id) =>
@unresolveCommentId(comment_id)
@$scope.$on "review-panel:recalculate-screen-positions", () =>
@recalculateReviewEntriesScreenPositions()
onChange = (e) =>
if !@editor.initing and @enabled
# This change is trigger by a sharejs 'change' event, which is before the
@ -255,77 +258,15 @@ define [
op = @_aceChangeToShareJs(delta)
@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: () ->
@updateEntryGeneration()
selection = @editor.getSelectionRange()
cursor_offset = @_aceRangeToShareJs(selection.start)
entries = @_getCurrentDocEntries()
selection = !(selection.start.column == selection.end.column and selection.start.row == selection.end.row)
@$scope.$emit "editor:focus:changed", cursor_offset, selection
if selection.start.column == selection.end.column and selection.start.row == selection.end.row
# 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: () ->
# Rather than making angular deep watch the whole entries array
@$scope.reviewPanel.entryGeneration ?= 0
@$scope.reviewPanel.entryGeneration++
broadcastChange: () ->
@$scope.$emit "editor:track-changes:changed", @$scope.docId
recalculateReviewEntriesScreenPositions: () ->
session = @editor.getSession()
@ -376,7 +317,7 @@ define [
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")
@changeIdToMarkerIdMap[change.id] = { background_marker_id, callout_marker_id }
@updateReviewEntriesScope()
@broadcastChange()
_onDeleteAdded: (change) ->
position = @_shareJsOffsetToAcePosition(change.op.p)
@ -391,7 +332,7 @@ define [
callout_marker_id = @_createCalloutMarker(position, "track-changes-deleted-marker-callout")
@changeIdToMarkerIdMap[change.id] = { background_marker_id, callout_marker_id }
@updateReviewEntriesScope()
@broadcastChange()
_onInsertRemoved: (change) ->
{background_marker_id, callout_marker_id} = @changeIdToMarkerIdMap[change.id]
@ -399,7 +340,7 @@ define [
session = @editor.getSession()
session.removeMarker background_marker_id
session.removeMarker callout_marker_id
@updateReviewEntriesScope()
@broadcastChange()
_onDeleteRemoved: (change) ->
{background_marker_id, callout_marker_id} = @changeIdToMarkerIdMap[change.id]
@ -407,7 +348,7 @@ define [
session = @editor.getSession()
session.removeMarker background_marker_id
session.removeMarker callout_marker_id
@updateReviewEntriesScope()
@broadcastChange()
_onCommentAdded: (comment) ->
if !@changeIdToMarkerIdMap[comment.id]?
@ -420,7 +361,7 @@ define [
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")
@changeIdToMarkerIdMap[comment.id] = { background_marker_id, callout_marker_id }
@updateReviewEntriesScope()
@broadcastChange()
_onCommentRemoved: (comment) ->
if @changeIdToMarkerIdMap[comment.id]?
@ -430,7 +371,7 @@ define [
session = @editor.getSession()
session.removeMarker background_marker_id
session.removeMarker callout_marker_id
@updateReviewEntriesScope()
@broadcastChange()
_aceRangeToShareJs: (range) ->
lines = @editor.getSession().getDocument().getLines 0, range.row
@ -472,14 +413,14 @@ define [
end = start
@_updateMarker(change.id, start, end)
@editor.renderer.updateBackMarkers()
@updateReviewEntriesScope()
@broadcastChange()
_onCommentMoved: (comment) ->
start = @_shareJsOffsetToAcePosition(comment.offset)
end = @_shareJsOffsetToAcePosition(comment.offset + comment.length)
@_updateMarker(comment.id, start, end)
@editor.renderer.updateBackMarkers()
@updateReviewEntriesScope()
@broadcastChange()
_updateMarker: (change_id, start, end) ->
return if !@changeIdToMarkerIdMap[change_id]?

View file

@ -26,6 +26,14 @@ define [
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.
mockedUserId = 'mock_user_id_1'
mockedUserId2 = 'mock_user_id_2'
@ -107,11 +115,13 @@ define [
ide.$scope.$on "file-tree:initialized", () ->
ide.fileTreeManager.forEachEntity (entity) ->
if mock_changes[entity.name]?
changesTrackers[entity.id] ?= new ChangesTracker()
changesTracker = getChangeTracker(entity.id)
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
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 = {}
$scope.reviewPanelEventsBridge.on "aceScrollbarVisibilityChanged", (isVisible, scrollbarWidth) ->
@ -155,6 +165,77 @@ define [
$scope.$broadcast "review-panel:toggle"
$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.$broadcast "change:accept", entry_id

View file

@ -82,10 +82,6 @@ define [
scope.$applyAsync () ->
layout()
scope.$watch "reviewPanel.entryGeneration", (value) ->
scope.$applyAsync () ->
layout()
scope.$on "review-panel:layout", () ->
scope.$applyAsync () ->
layout()