Skip to content
Snippets Groups Projects
Commit ab028731 authored by Yannis Barlas's avatar Yannis Barlas
Browse files

handle collapsed additions on another users annotation

parent 53643e93
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ class TrackChange extends PropertyAnnotation {}
TrackChange.define({
status: { type: 'string' },
user: {
id: 'string',
roles: 'array',
username: 'string'
}
......
......@@ -5,8 +5,9 @@ export default {
import: function (element, node, converter) {
node.status = element.attr('status')
node.user = {
id: element.attr('user-id'),
roles: element.attr('roles').split(','),
user: element.attr('username')
username: element.attr('username')
}
},
......@@ -15,6 +16,7 @@ export default {
element.setAttribute('status', status)
element.setAttribute('user-id', user.id)
element.setAttribute('roles', user.roles.join(','))
element.setAttribute('username', user.username)
}
......
......@@ -60,9 +60,27 @@ class TrackChangesProvider {
// annotation gets expanded automatically, unless the selection is on its left edge
const annotation = this.getAnnotationByStatus('add')
const isOnLeftEdge = this.isOnLeftEdge(annotation)
const isOnRightEdge = this.isOnRightEdge(annotation)
const isFromSameUser = this.isAnnotationFromTheSameUser(annotation)
const mode = this.getMode()
// console.log(annotation)
if (isFromSameUser) {
this.insertText(event)
if (isOnLeftEdge) this.expandAnnotationToDirection(annotation)
}
if (!isFromSameUser) {
if (isOnRightEdge) {
this.insertCharacterWithoutExpandingAnnotation(annotation, options)
} else {
this.insertText(event)
}
if (mode) this.createAdditionAnnotationOnLastChar()
}
this.insertText(event)
if (isOnLeftEdge) this.expandAnnotationToDirection(annotation)
return
}
......@@ -215,7 +233,7 @@ class TrackChangesProvider {
const endOffset = selection.endOffset - shortenBy
this.updateSelection(selection, startOffset, endOffset)
console.log('collapsed', selection.isCollapsed())
// console.log('collapsed', selection.isCollapsed())
if (selection.isCollapsed()) return this.handleDeleteCollapsed(options)
if (isOnDelete) {
......@@ -392,6 +410,7 @@ class TrackChangesProvider {
status: status,
type: 'track-change',
user: {
id: user.id,
roles: user.roles,
username: user.username
}
......@@ -482,8 +501,6 @@ class TrackChangesProvider {
*/
// is annotation from the same user
getAllAnnotationsByStatus (status) {
const annotations = this.getAllExistingTrackAnnotations()
const annotationsByStatus = filter(annotations, (annotation) => {
......@@ -531,6 +548,14 @@ class TrackChangesProvider {
return { skipSelection: true }
}
isAnnotationFromTheSameUser (annotation) {
const annotationUser = annotation.user.id
const currentUser = this.config.user.id
if (annotationUser === currentUser) return true
return false
}
isNotOnTrackAnnotation () {
const annotations = this.getAllExistingTrackAnnotations()
return (annotations.length === 0)
......@@ -676,10 +701,19 @@ class TrackChangesProvider {
*/
getCommandManager () {
return this.config.commandManager
}
getDocumentSession () {
return this.config.documentSession
}
getMode () {
const trackState = this.getTrackState()
return trackState.mode
}
getSelection () {
const surface = this.getSurface()
return surface.getSelection()
......@@ -691,6 +725,12 @@ class TrackChangesProvider {
return surfaceManager.getSurface(id)
}
getTrackState () {
const commandManager = this.getCommandManager()
const commandStates = commandManager.getCommandStates()
return commandStates['track-change']
}
}
export default TrackChangesProvider
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment