Skip to content
Snippets Groups Projects
Commit a0d09c1f authored by chris's avatar chris Committed by john
Browse files

delete a note callout deletes the associated isolated note

parent f25d900b
No related branches found
No related tags found
No related merge requests found
...@@ -34,8 +34,8 @@ class ContainerEditor extends SubstanceContainerEditor { ...@@ -34,8 +34,8 @@ class ContainerEditor extends SubstanceContainerEditor {
didMount () { didMount () {
super.didMount() super.didMount()
const containerId = this.getContainerId()
if (this.isEmpty()) this.createText() if (this.isEmpty() && containerId !== 'mini') this.createText()
// TODO -- why this and not this.focus ? // TODO -- why this and not this.focus ?
this.el.focus() this.el.focus()
......
...@@ -30,6 +30,9 @@ class NotesProvider extends TOCProvider { ...@@ -30,6 +30,9 @@ class NotesProvider extends TOCProvider {
mini: entriesMini mini: entriesMini
} }
if (entriesMini && entriesMain.length < entriesMini.length) {
this.findDeletedNote(entries)
}
return entries return entries
} }
...@@ -97,9 +100,9 @@ class NotesProvider extends TOCProvider { ...@@ -97,9 +100,9 @@ class NotesProvider extends TOCProvider {
createIsolatedNote (note) { createIsolatedNote (note) {
const notes = this.computeEntries() const notes = this.computeEntries()
const containerId = this.getMiniContainerId()
let surface = this.config.miniEditorContext.surfaceManager.getSurface(containerId)
if (notes.mini && notes.mini.length > 0) { if (notes.mini && notes.mini.length > 0) {
const containerId = this.getMiniContainerId()
let surface = this.config.miniEditorContext.surfaceManager.getSurface(containerId)
let container = surface.getContainer() let container = surface.getContainer()
let findIndex = _.findIndex(notes.main, ['id', note.id]) let findIndex = _.findIndex(notes.main, ['id', note.id])
...@@ -112,6 +115,7 @@ class NotesProvider extends TOCProvider { ...@@ -112,6 +115,7 @@ class NotesProvider extends TOCProvider {
} }
}) })
} else { } else {
surface.createText()
this.config.miniEditorSession.transaction(function (tx) { this.config.miniEditorSession.transaction(function (tx) {
let nodeData = this.createNodeData(note) let nodeData = this.createNodeData(note)
tx.insertBlockNode(nodeData) tx.insertBlockNode(nodeData)
...@@ -119,6 +123,36 @@ class NotesProvider extends TOCProvider { ...@@ -119,6 +123,36 @@ class NotesProvider extends TOCProvider {
} }
} }
findDeletedNote (entries) {
let position
let note
if (entries.main.length === 0) {
position = 0
note = entries.mini[0]
} else {
_.forEach(entries.main, function (mainNote) {
_.forEach(entries.mini, function (miniNote) {
if (miniNote.parentNoteId !== mainNote.id) {
position = _.findIndex(entries.mini, ['id', miniNote.id])
note = miniNote
}
})
})
}
return this.removeIsolatedNote(position, note)
}
removeIsolatedNote (position, note) {
const containerId = this.getMiniContainerId()
let surface = this.config.miniEditorContext.surfaceManager.getSurface(containerId)
let container = surface.getContainer()
this.config.miniEditorSession.transaction(function (tx) {
tx.update(container.getContentPath(), { type: 'delete', pos: position })
tx.delete(note.id)
})
}
getMiniContainerId () { getMiniContainerId () {
return this.config.miniEditorContext.editor.props.containerId return this.config.miniEditorContext.editor.props.containerId
} }
......
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