Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
editoria
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yannis Barlas
editoria
Commits
6e81f305
Commit
6e81f305
authored
8 years ago
by
john
Browse files
Options
Downloads
Patches
Plain Diff
handle track changes events when on an existing tracked deletion
parent
8e784db2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js
+140
-20
140 additions, 20 deletions
...impleEditor/elements/track_change/TrackChangesProvider.js
with
140 additions
and
20 deletions
app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js
+
140
−
20
View file @
6e81f305
...
...
@@ -42,11 +42,12 @@ class TrackChangesProvider {
let
selection
if
(
isSelectionCollapsed
)
{
this
.
insertText
(
event
)
//
this.insertText(event)
const
notOnTrack
=
this
.
isNotOnTrackAnnotation
()
if
(
notOnTrack
)
{
this
.
insertText
(
event
)
selection
=
this
.
setSelectionPlusOne
(
'
left
'
)
this
.
createAddAnnotation
(
selection
)
this
.
moveCursorTo
(
'
end
'
)
...
...
@@ -58,6 +59,7 @@ class TrackChangesProvider {
const
annotation
=
this
.
getAnnotationByStatus
(
'
add
'
)
const
isOnLeftEdge
=
this
.
isOnLeftEdge
(
annotation
)
this
.
insertText
(
event
)
if
(
isOnLeftEdge
)
{
selection
=
this
.
setSelectionPlusOne
(
'
left
'
)
this
.
expandTrackAnnotation
(
selection
,
annotation
)
...
...
@@ -65,6 +67,47 @@ class TrackChangesProvider {
return
}
}
const
isOnDelete
=
this
.
isOnAnnotation
(
'
delete
'
)
if
(
isOnDelete
)
{
console
.
log
(
'
on delete
'
)
const
annotation
=
this
.
getAnnotationByStatus
(
'
delete
'
)
const
withinAnnotation
=
this
.
isSelectionContainedWithin
(
annotation
,
true
)
if
(
withinAnnotation
)
{
// console.log('in')
this
.
moveCursorTo
(
annotation
.
endOffset
)
this
.
insertText
(
event
)
selection
=
this
.
setSelectionPlusOne
(
'
left
'
)
this
.
createAddAnnotation
(
selection
)
this
.
separateAnnotations
()
this
.
moveCursorTo
(
'
end
'
)
return
}
console
.
log
(
'
out
'
)
const
isOnLeftEdge
=
this
.
isOnLeftEdge
(
annotation
)
if
(
isOnLeftEdge
)
{
// console.log('left')
this
.
insertText
(
event
)
selection
=
this
.
setSelectionPlusOne
(
'
left
'
)
this
.
createAddAnnotation
(
selection
)
this
.
moveCursorTo
(
'
end
'
)
return
}
const
isOnRightEdge
=
this
.
isOnRightEdge
(
annotation
)
if
(
isOnRightEdge
)
{
// console.log('right')
this
.
insertText
(
event
)
selection
=
this
.
setSelectionPlusOne
(
'
left
'
)
this
.
createAddAnnotation
(
selection
)
this
.
separateAnnotations
()
this
.
moveCursorTo
(
'
end
'
)
return
}
}
}
}
else
{
selection
=
this
.
getSelection
()
...
...
@@ -103,6 +146,35 @@ class TrackChangesProvider {
selection
=
this
.
setSelectionPlusOne
(
'
left
'
)
this
.
createAddAnnotation
(
selection
)
this
.
moveCursorTo
(
'
end
'
)
return
}
const
isOnDelete
=
this
.
isOnAnnotation
(
'
delete
'
)
if
(
isOnDelete
)
{
const
annotation
=
this
.
getAnnotationByStatus
(
'
delete
'
)
const
withinAnnotation
=
this
.
isSelectionContainedWithin
(
annotation
)
if
(
withinAnnotation
)
{
this
.
moveCursorTo
(
annotation
.
endOffset
)
this
.
insertText
(
event
)
selection
=
this
.
setSelectionPlusOne
(
'
left
'
)
this
.
createAddAnnotation
(
selection
)
this
.
separateAnnotations
()
this
.
moveCursorTo
(
'
end
'
)
return
}
selection
=
this
.
getSelection
()
this
.
expandTrackAnnotation
(
selection
,
annotation
)
this
.
moveCursorTo
(
annotation
.
endOffset
)
this
.
insertText
(
event
)
selection
=
this
.
setSelectionPlusOne
(
'
left
'
)
this
.
createAddAnnotation
(
selection
)
this
.
separateAnnotations
()
this
.
moveCursorTo
(
'
end
'
)
return
}
}
}
...
...
@@ -130,16 +202,6 @@ class TrackChangesProvider {
return
}
else
{
const
isOnAdd
=
this
.
isOnAnnotation
(
'
add
'
)
const
isOnDelete
=
this
.
isOnAnnotation
(
'
delete
'
)
if
(
isOnDelete
)
{
selection
=
this
.
setSelectionPlusOne
(
direction
.
move
)
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
)
...
...
@@ -159,6 +221,34 @@ class TrackChangesProvider {
this
.
deleteCharacter
(
direction
.
move
)
return
}
const
isOnDelete
=
this
.
isOnAnnotation
(
'
delete
'
)
if
(
isOnDelete
)
{
const
annotation
=
this
.
getAnnotationByStatus
(
'
delete
'
)
const
isOnLeftEdge
=
this
.
isOnLeftEdge
(
annotation
)
const
isOnRightEdge
=
this
.
isOnRightEdge
(
annotation
)
const
key
=
direction
.
key
let
moveOnly
,
point
if
(
!
isOnLeftEdge
&&
!
isOnRightEdge
)
{
point
=
annotation
[
direction
.
cursorTo
+
'
Offset
'
]
moveOnly
=
true
}
else
if
(
isOnLeftEdge
&&
key
===
'
DELETE
'
)
{
point
=
annotation
.
endOffset
moveOnly
=
true
}
else
if
(
isOnRightEdge
&&
key
===
'
BACKSPACE
'
)
{
point
=
annotation
.
startOffset
moveOnly
=
true
}
if
(
moveOnly
)
return
this
.
moveCursorTo
(
point
)
selection
=
this
.
setSelectionPlusOne
(
direction
.
move
)
this
.
expandTrackAnnotation
(
selection
,
annotation
)
this
.
moveCursorTo
(
direction
.
cursorTo
)
return
}
}
}
else
{
const
notOnTrack
=
this
.
isNotOnTrackAnnotation
()
...
...
@@ -194,6 +284,28 @@ class TrackChangesProvider {
this
.
separateAnnotations
()
return
}
const
isOnDelete
=
this
.
isOnAnnotation
(
'
delete
'
)
if
(
isOnDelete
)
{
const
annotation
=
this
.
getAnnotationByStatus
(
'
delete
'
)
const
containedWithin
=
this
.
isSelectionContainedWithin
(
annotation
)
if
(
containedWithin
)
{
const
point
=
annotation
[
direction
.
cursorTo
+
'
Offset
'
]
return
this
.
moveCursorTo
(
point
)
}
const
selection
=
this
.
getSelection
()
this
.
expandTrackAnnotation
(
selection
,
annotation
)
const
key
=
direction
.
key
let
point
if
(
key
===
'
BACKSPACE
'
)
point
=
selection
.
startOffset
if
(
key
===
'
DELETE
'
)
point
=
selection
.
endOffset
this
.
moveCursorTo
(
point
)
}
}
}
...
...
@@ -211,6 +323,7 @@ class TrackChangesProvider {
this
.
createTrackAnnotation
(
selection
,
'
delete
'
)
}
// TODO -- selection could default to current selection
createTrackAnnotation
(
selection
,
status
)
{
const
surface
=
this
.
getSurface
()
const
info
=
this
.
getInfo
()
...
...
@@ -245,6 +358,7 @@ class TrackChangesProvider {
separateAnnotations
()
{
const
surface
=
this
.
getSurface
()
const
info
=
this
.
getInfo
()
// TODO -- separate all annotations
// to see this fail:
...
...
@@ -255,11 +369,13 @@ class TrackChangesProvider {
const
addAnnotation
=
this
.
getAnnotationByStatus
(
'
add
'
)
const
deleteAnnotation
=
this
.
getAnnotationByStatus
(
'
delete
'
)
surface
.
transac
tion
(
(
tx
,
args
)
=>
{
const
transforma
tion
=
(
tx
,
args
)
=>
{
args
.
anno
=
deleteAnnotation
args
.
selection
=
addAnnotation
.
getSelection
()
truncateAnnotation
(
tx
,
args
)
})
}
surface
.
transaction
(
transformation
,
info
)
}
insertText
(
event
)
{
...
...
@@ -495,11 +611,11 @@ class TrackChangesProvider {
return
selection
}
isAnnotationContainedWithinSelection
(
annotation
)
{
isAnnotationContainedWithinSelection
(
annotation
,
strict
)
{
const
selection
=
this
.
getSelection
()
const
annotationSelection
=
annotation
.
getSelection
()
return
selection
.
contains
(
annotationSelection
)
return
selection
.
contains
(
annotationSelection
,
strict
)
}
isSelectionCollapsed
()
{
...
...
@@ -508,14 +624,18 @@ class TrackChangesProvider {
return
isCollapsed
}
isSelectionContainedWithin
(
annotation
)
{
// TODO -- refactor this and isAnnotationContainedWithinSelection into one
isSelectionContainedWithin
(
annotation
,
strict
)
{
const
selection
=
this
.
getSelection
()
const
annotationSelection
=
annotation
.
getSelection
()
const
leftSide
=
(
selection
.
startOffset
<
annotation
.
startOffset
)
const
rightSide
=
(
selection
.
endOffset
>
annotation
.
endOffset
)
return
annotationSelection
.
contains
(
selection
,
strict
)
if
(
leftSide
||
rightSide
)
return
false
return
true
// const leftSide = (selection.startOffset < annotation.startOffset)
// const rightSide = (selection.endOffset > annotation.endOffset)
//
// if (leftSide || rightSide) return false
// return true
}
/*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment