Skip to content
Snippets Groups Projects
Commit f1e9d6d8 authored by john's avatar john
Browse files

expand add annotation when writing on its left edge

parent db8493e2
No related branches found
No related tags found
No related merge requests found
...@@ -27,17 +27,35 @@ class TrackChangesProvider { ...@@ -27,17 +27,35 @@ class TrackChangesProvider {
if (status !== 'add') return if (status !== 'add') return
const isSelectionCollapsed = this.isSelectionCollapsed() const isSelectionCollapsed = this.isSelectionCollapsed()
const mode = this.getMode() // const mode = this.getMode()
let selection let selection
if (isSelectionCollapsed) { if (isSelectionCollapsed) {
this.insertText(event) this.insertText(event)
if (mode) return
selection = this.setSelectionPlusOne('left') const notOnTrack = this.isNotOnTrackAnnotation()
this.createAddAnnotation(selection)
this.moveCursorTo('end') if (notOnTrack) {
return selection = this.setSelectionPlusOne('left')
this.createAddAnnotation(selection)
this.moveCursorTo('end')
return
} else {
const isOnAdd = this.isOnAnnotation('add')
if (isOnAdd) {
const annotation = this.getAnnotationByStatus('add')
const isOnLeftEdge = this.isOnLeftEdge(annotation)
if (isOnLeftEdge) {
selection = this.setSelectionPlusOne('left')
this.expandTrackAnnotation(selection, annotation)
this.moveCursorTo('end')
return
}
}
}
} else { } else {
selection = this.getSelection() selection = this.getSelection()
this.createDeleteAnnotation(selection) this.createDeleteAnnotation(selection)
...@@ -98,8 +116,9 @@ class TrackChangesProvider { ...@@ -98,8 +116,9 @@ class TrackChangesProvider {
createTrackAnnotation (selection, status) { createTrackAnnotation (selection, status) {
const surface = this.getSurface() const surface = this.getSurface()
const info = this.getInfo()
surface.transaction((tx, args) => { const transformation = (tx, args) => {
const newNode = { const newNode = {
selection: selection, selection: selection,
node: { node: {
...@@ -108,18 +127,23 @@ class TrackChangesProvider { ...@@ -108,18 +127,23 @@ class TrackChangesProvider {
} }
} }
createAnnotation(tx, newNode) createAnnotation(tx, newNode)
}) }
surface.transaction(transformation, info)
} }
expandTrackAnnotation (selection, annotation) { expandTrackAnnotation (selection, annotation) {
const surface = this.getSurface() const surface = this.getSurface()
const info = this.getInfo()
surface.transaction((tx, args) => { const transformation = (tx, args) => {
args.selection = selection args.selection = selection
args.anno = annotation args.anno = annotation
expandAnnotation(tx, args) expandAnnotation(tx, args)
}) }
surface.transaction(transformation, info)
} }
separateAnnotations () { separateAnnotations () {
...@@ -177,6 +201,12 @@ class TrackChangesProvider { ...@@ -177,6 +201,12 @@ class TrackChangesProvider {
return annotations return annotations
} }
// prevent substance from running getBoundingRectangle,
// as we will unset the selection manually
getInfo () {
return { skipSelection: true }
}
// returns whether the selection is on an add / delete tracked change // returns whether the selection is on an add / delete tracked change
isOnAnnotation (status) { isOnAnnotation (status) {
const annotations = this.getAllExistingTrackAnnotations() const annotations = this.getAllExistingTrackAnnotations()
...@@ -188,6 +218,16 @@ class TrackChangesProvider { ...@@ -188,6 +218,16 @@ class TrackChangesProvider {
return true return true
} }
isOnLeftEdge (annotation) {
const selection = this.getSelection()
return (selection.startOffset === annotation.startOffset)
}
isNotOnTrackAnnotation () {
const mode = this.getMode()
return (mode === null)
}
/** /**
HISTORY HANDLERS HISTORY HANDLERS
......
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