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
56c01e2b
Commit
56c01e2b
authored
8 years ago
by
john
Browse files
Options
Downloads
Patches
Plain Diff
handle undo for track changes additions
parent
e500027a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/components/SimpleEditor/ContainerEditor.js
+28
-24
28 additions, 24 deletions
app/components/SimpleEditor/ContainerEditor.js
app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js
+56
-22
56 additions, 22 deletions
...impleEditor/elements/track_change/TrackChangesProvider.js
with
84 additions
and
46 deletions
app/components/SimpleEditor/ContainerEditor.js
+
28
−
24
View file @
56c01e2b
import
{
each
,
keys
,
includes
}
from
'
lodash
'
import
{
each
,
keys
,
includes
}
from
'
lodash
'
import
{
import
{
ContainerEditor
as
SubstanceContainerEditor
,
ContainerEditor
as
SubstanceContainerEditor
,
// createAnnotation,
Surface
,
Surface
,
uuid
uuid
}
from
'
substance
'
}
from
'
substance
'
...
@@ -34,21 +33,42 @@ class ContainerEditor extends SubstanceContainerEditor {
...
@@ -34,21 +33,42 @@ class ContainerEditor extends SubstanceContainerEditor {
// open for editing
// open for editing
// TODO -- should maybe change to isEditable ?
// TODO -- should maybe change to isEditable ?
// or maybe delete
d
? we never pass a disabled prop explicitly
// or maybe delete
it
? we never pass a disabled prop explicitly
if
(
!
this
.
props
.
disabled
)
{
if
(
!
this
.
props
.
disabled
)
{
el
.
addClass
(
'
sm-enabled
'
)
el
.
addClass
(
'
sm-enabled
'
)
el
.
setAttribute
(
'
contenteditable
'
,
true
)
el
.
setAttribute
(
'
contenteditable
'
,
true
)
}
}
// editing locked, selection open (for comments)
// if (this.isReadOnlyMode()) {
// const documentSession = this.getDocumentSession()
// documentSession.on('didUpdate', this.disableToolbar, this)
// }
return
el
return
el
}
}
didMount
()
{
// TODO -- replace with super.didMount()
Surface
.
prototype
.
didMount
.
apply
(
this
,
arguments
)
this
.
container
.
on
(
'
nodes:changed
'
,
this
.
onContainerChange
,
this
)
// this.context.documentSession.on('didUpdate', (change, info) => {
// // console.log(this.getSelection())
// // console.log(this.context.commandManager.getCommandStates().strong.mode)
// // console.log(this.context.commandManager.getCommandStates()['track-change'].mode)
// console.log('\n did update')
// console.log('change', change)
// console.log('info', info)
//
// if (info.track) change.change.info.track = true
// }, this)
if
(
this
.
isEmpty
())
this
.
createText
()
if
(
this
.
isReadOnlyMode
())
{
const
documentSession
=
this
.
getDocumentSession
()
documentSession
.
on
(
'
didUpdate
'
,
this
.
disableToolbar
,
this
)
this
.
addTargetToLinks
()
}
}
onTextInput
(
event
)
{
onTextInput
(
event
)
{
event
.
preventDefault
()
event
.
preventDefault
()
event
.
stopPropagation
()
event
.
stopPropagation
()
...
@@ -69,22 +89,6 @@ class ContainerEditor extends SubstanceContainerEditor {
...
@@ -69,22 +89,6 @@ class ContainerEditor extends SubstanceContainerEditor {
}
}
}
}
didMount
()
{
// TODO -- replace with super.didMount()
Surface
.
prototype
.
didMount
.
apply
(
this
,
arguments
)
this
.
container
.
on
(
'
nodes:changed
'
,
this
.
onContainerChange
,
this
)
if
(
this
.
isEmpty
())
this
.
createText
()
if
(
this
.
isReadOnlyMode
())
{
const
documentSession
=
this
.
getDocumentSession
()
documentSession
.
on
(
'
didUpdate
'
,
this
.
disableToolbar
,
this
)
this
.
addTargetToLinks
()
}
}
// create an empty paragraph with an empty node
// create an empty paragraph with an empty node
// then select it for cursor focus
// then select it for cursor focus
createText
()
{
createText
()
{
...
...
This diff is collapsed.
Click to expand it.
app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js
+
56
−
22
View file @
56c01e2b
import
{
keys
,
last
}
from
'
lodash
'
import
{
createAnnotation
}
from
'
substance
'
import
{
createAnnotation
}
from
'
substance
'
class
TrackChangesProvider
{
class
TrackChangesProvider
{
constructor
(
config
)
{
constructor
(
config
)
{
this
.
config
=
config
this
.
config
=
config
this
.
config
.
documentSession
.
on
(
'
didUpdate
'
,
this
.
handleUndoRedo
,
this
)
}
}
handleTransaction
()
{
handleTransaction
()
{
const
mode
=
this
.
getMode
()
if
(
mode
)
return
const
surface
=
this
.
getSurface
()
const
surface
=
this
.
getSurface
()
surface
.
transac
tion
(
(
tx
,
args
)
=>
{
const
transforma
tion
=
(
tx
,
args
)
=>
{
const
selection
=
this
.
createSelection
(
args
)
const
selection
=
this
.
createSelection
(
args
)
// console.log(this.getTrackState())
const
newNode
=
{
const
newNode
=
{
selection
:
selection
,
selection
:
selection
,
node
:
{
'
type
'
:
'
track-change
'
}
node
:
{
'
type
'
:
'
track-change
'
}
}
}
const
mode
=
this
.
getMode
()
createAnnotation
(
tx
,
newNode
)
this
.
clearSelection
(
args
)
// this.removeAnnotationFromHistory()
}
if
(
!
mode
)
{
const
info
=
{
createAnnotation
(
tx
,
newNode
)
track
:
true
}
else
if
(
mode
===
'
delete
'
)
{
}
// continue here to expand annotation
}
this
.
clearSelection
(
args
)
surface
.
transaction
(
transformation
,
info
)
this
.
removeAnnotationFromHistory
()
}
})
handleUndoRedo
(
update
,
info
)
{
if
(
!
info
.
replay
)
return
console
.
log
(
update
)
console
.
log
(
info
)
this
.
handleUndo
(
update
)
this
.
handleRedo
(
update
)
}
handleUndo
(
update
)
{
const
deleted
=
update
.
change
.
deleted
const
deletedLength
=
keys
(
deleted
).
length
// console.log(keys(deleted))
if
(
deletedLength
===
0
)
return
if
(
deletedLength
>
1
)
{
return
console
.
warn
(
'
FIXME: Multiple operations in track changes replay!
'
)
}
const
deletedOp
=
deleted
[
keys
(
deleted
)[
0
]]
if
(
!
deletedOp
.
type
===
'
track-change
'
)
return
const
documentSession
=
this
.
getDocumentSession
()
documentSession
.
undo
()
}
}
removeAnnotationFromHistory
()
{
handleRedo
()
{
const
documentSession
=
this
.
getDocumentSession
()
const
documentSession
=
this
.
getDocumentSession
()
setTimeout
(()
=>
{
const
undoneChanges
=
documentSession
.
undoneChanges
documentSession
.
doneChanges
.
pop
()
const
lastChange
=
last
(
undoneChanges
)
})
// ensure that text insertion has finished
const
op
=
last
(
lastChange
.
ops
)
const
isTrack
=
op
.
path
[
0
].
split
(
'
-
'
).
slice
(
0
,
-
1
).
join
(
'
-
'
)
===
'
track-change
'
console
.
log
(
isTrack
)
}
}
// removeAnnotationFromHistory () {
// const documentSession = this.getDocumentSession()
// // console.log(documentSession.doneChanges)
// setTimeout(() => {
// console.log(documentSession.doneChanges[1].toJSON())
// // documentSession.doneChanges.pop()
// }) // ensure that text insertion has finished
// }
clearSelection
(
args
)
{
clearSelection
(
args
)
{
const
selection
=
args
.
selection
const
selection
=
args
.
selection
selection
.
startOffset
=
selection
.
endOffset
selection
.
startOffset
=
selection
.
endOffset
...
@@ -64,13 +105,6 @@ class TrackChangesProvider {
...
@@ -64,13 +105,6 @@ class TrackChangesProvider {
return
state
.
mode
return
state
.
mode
}
}
// createCommandState () {
// const commandState = this.getCommandState()
// commandState.disabled = false
// commandState.mode = 'create'
// return commandState
// }
getDocumentSession
()
{
getDocumentSession
()
{
return
this
.
config
.
documentSession
return
this
.
config
.
documentSession
}
}
...
...
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