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

handle deletions when collapsed and on an existing track annotation

parent f1e9d6d8
No related branches found
No related tags found
No related merge requests found
...@@ -101,6 +101,7 @@ class ContainerEditor extends SubstanceContainerEditor { ...@@ -101,6 +101,7 @@ class ContainerEditor extends SubstanceContainerEditor {
const trackChangesProvider = this.context.trackChangesProvider const trackChangesProvider = this.context.trackChangesProvider
const options = { const options = {
key: (direction === 'left') ? 'BACKSPACE' : 'DELETE',
move: direction, move: direction,
status: 'delete' status: 'delete'
} }
......
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
import { import {
createAnnotation, createAnnotation,
deleteCharacter as deleteChar,
expandAnnotation, expandAnnotation,
truncateAnnotation truncateAnnotation
} from 'substance' } from 'substance'
...@@ -25,10 +26,9 @@ class TrackChangesProvider { ...@@ -25,10 +26,9 @@ class TrackChangesProvider {
handleAdd (options) { handleAdd (options) {
const { event, status } = options const { event, status } = options
if (status !== 'add') return if (status !== 'add') return
// console.log('adding')
const isSelectionCollapsed = this.isSelectionCollapsed() const isSelectionCollapsed = this.isSelectionCollapsed()
// const mode = this.getMode()
let selection let selection
if (isSelectionCollapsed) { if (isSelectionCollapsed) {
...@@ -71,32 +71,57 @@ class TrackChangesProvider { ...@@ -71,32 +71,57 @@ class TrackChangesProvider {
} }
handleDelete (options) { handleDelete (options) {
const { move, status } = options const { key, move, status } = options
if (status !== 'delete') return if (status !== 'delete') return
// console.log('deleting')
const mode = this.getMode()
const isSelectionCollapsed = this.isSelectionCollapsed() const isSelectionCollapsed = this.isSelectionCollapsed()
let selection let selection
const direction = { const direction = {
cursorTo: (move === 'left') ? 'start' : 'end', cursorTo: (move === 'left') ? 'start' : 'end',
key: key,
move: move move: move
} }
if (isSelectionCollapsed) { if (isSelectionCollapsed) {
if (!mode) { const notOnTrack = this.isNotOnTrackAnnotation()
if (notOnTrack) {
selection = this.setSelectionPlusOne(direction.move) selection = this.setSelectionPlusOne(direction.move)
this.createDeleteAnnotation(selection) this.createDeleteAnnotation(selection)
this.moveCursorTo(direction.cursorTo) this.moveCursorTo(direction.cursorTo)
return return
} } else {
if (mode === 'delete') { const isOnAdd = this.isOnAnnotation('add')
selection = this.setSelectionPlusOne(direction.move) const isOnDelete = this.isOnAnnotation('delete')
const annotation = this.getAnnotationByStatus('delete')
this.expandTrackAnnotation(selection, annotation) if (isOnDelete) {
this.moveCursorTo(direction.cursorTo) selection = this.setSelectionPlusOne(direction.move)
return const annotation = this.getAnnotationByStatus('delete')
this.expandTrackAnnotation(selection, annotation)
this.moveCursorTo(direction.cursorTo)
return
}
if (isOnAdd) {
const annotation = this.getAnnotationByStatus('add')
const isOnLeftEdge = this.isOnLeftEdge(annotation)
const isOnRightEdge = this.isOnRightEdge(annotation)
const key = direction.key
if (
(isOnLeftEdge && key === 'BACKSPACE') ||
(isOnRightEdge && key === 'DELETE')
) {
selection = this.setSelectionPlusOne(direction.move)
this.createDeleteAnnotation(selection)
this.moveCursorTo(direction.cursorTo)
return
}
this.deleteCharacter(direction.move)
return
}
} }
} else { } else {
selection = this.getSelection() selection = this.getSelection()
...@@ -168,6 +193,18 @@ class TrackChangesProvider { ...@@ -168,6 +193,18 @@ class TrackChangesProvider {
}, { action: 'type' }) }, { action: 'type' })
} }
deleteCharacter (direction) {
const surface = this.getSurface()
const info = { action: 'delete' }
const transformation = (tx, args) => {
args.direction = direction
return deleteChar(tx, args)
}
surface.transaction(transformation, info)
}
/* /*
ANNOTATION HELPERS ANNOTATION HELPERS
...@@ -223,6 +260,11 @@ class TrackChangesProvider { ...@@ -223,6 +260,11 @@ class TrackChangesProvider {
return (selection.startOffset === annotation.startOffset) return (selection.startOffset === annotation.startOffset)
} }
isOnRightEdge (annotation) {
const selection = this.getSelection()
return (selection.endOffset === annotation.endOffset)
}
isNotOnTrackAnnotation () { isNotOnTrackAnnotation () {
const mode = this.getMode() const mode = this.getMode()
return (mode === null) return (mode === null)
......
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