Commit ab2c21fe authored by Christos's avatar Christos

Merge branch 'track-changes-fixes' into 'master'

Track changes fixes

See merge request !294
parents c8028cd6 56846aab
......@@ -252,7 +252,14 @@ class ContainerEditor extends SubstanceContainerEditor {
const { trackChangesProvider } = this.context
event.preventDefault()
this._onCopy(event)
trackChangesProvider.handleCut(event)
const options = {
selection: this.editorSession.getSelection(),
user: this.context.editor.props.user,
editorSession: this.editorSession,
surface: this,
}
trackChangesProvider.markNonCollapsedSelectionAsDeleted(options)
}
shouldIgnoreKeypress(event) {
......
......@@ -1032,103 +1032,6 @@ class TrackChangesProvider extends AbstractProvider {
})
}
handleCut(options) {
options.editorSession = this.editorSession
options.user = this.config.user
if (this.editorSession.getSelection().isContainerSelection()) {
this.handleCutContainer(options)
} else {
const additions = getAllAnnotationsByStatus(options, 'add')
const deletions = getAllAnnotationsByStatus(options, 'delete')
const user = this.config.user
const surface = this.getActiveSurface()
// if we need to filter them
// const ownAdditions = filter(additions, annotation => {
// return isAnnotationFromTheSameUser(options, annotation)
// })
//
// const ownDeletions = filter(deletions, annotation => {
// return isAnnotationFromTheSameUser(options, annotation)
// })
const ownAdditions = []
const ownDeletions = []
const selection = this.editorSession.getSelection()
const containerId = surface.containerId
const surfaceId = this.getSurfaceId(containerId)
let diff = 0
let allDiff = 0
let newSel = ''
this.editorSession.transaction(tx => {
if (ownAdditions.length > 0) {
forEach(ownAdditions, (addition, index) => {
const previous = ownAdditions[index - 1]
if (previous) diff += previous.end.offset - previous.start.offset
allDiff += addition.end.offset - addition.start.offset
tx.setSelection({
type: 'property',
path: addition.path,
surfaceId,
startOffset: addition.start.offset - diff,
endOffset: addition.end.offset - diff,
})
tx.deleteSelection()
})
}
if (ownDeletions.length > 0) {
forEach(ownDeletions, (deletion, index) => {
tx.delete(deletion.id)
})
}
tx.create({
status: 'delete',
type: 'track-change',
containerId,
surfaceId,
path: selection.path,
startOffset: selection.start.offset,
endOffset: selection.end.offset - allDiff,
user: {
id: user.id,
username: user.username,
color: user.color,
},
})
tx.setSelection({
type: 'property',
containerId,
surfaceId,
path: selection.path,
startOffset: selection.start.offset,
endOffset: selection.start.offset,
})
//HACK in order to not refresh surface and show the deletion
tx.insertText('')
//Set Selection to all
tx.setSelection({
type: 'property',
containerId,
surfaceId,
path: selection.path,
startOffset: selection.start.offset,
endOffset: selection.end.offset,
})
})
// handle notes
this.updateNotesAsDeleted()
}
}
createSnippet(options) {
const { content, user, SubstanceClipboard } = options
let selection = this.editorSession.getSelection()
......
Markdown is supported
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