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

fix: so mini editor does not recompute entries constantly

parent 0e9fd2ea
No related branches found
No related tags found
No related merge requests found
...@@ -11,15 +11,10 @@ class MiniEditor extends ProseEditor { ...@@ -11,15 +11,10 @@ class MiniEditor extends ProseEditor {
didMount () { didMount () {
this.context.notesProvider.config.miniEditorContext = this.getChildContext() this.context.notesProvider.config.miniEditorContext = this.getChildContext()
this.editorSession.onUpdate('document', this.reComputeEntries, this)
this.context.notesProvider.config.miniEditorSession = this.editorSession this.context.notesProvider.config.miniEditorSession = this.editorSession
this.on('noteSelected', this.scrollTo, this) this.on('noteSelected', this.scrollTo, this)
} }
reComputeEntries () {
this.context.notesProvider.computeEntries()
}
render ($$) { render ($$) {
const el = $$('div').addClass('sc-mini-editor') const el = $$('div').addClass('sc-mini-editor')
let toolbar = this._renderMiniToolbar($$) let toolbar = this._renderMiniToolbar($$)
......
...@@ -74,7 +74,7 @@ class CommentBoxList extends Component { ...@@ -74,7 +74,7 @@ class CommentBoxList extends Component {
const entries = provider.computeEntries() const entries = provider.computeEntries()
const activeEntry = provider.activeEntry const activeEntry = provider.activeEntry
console.log(entries)
this.calculateTops(entries, activeEntry) this.calculateTops(entries, activeEntry)
} }
// TODO move to helper section?? // TODO move to helper section??
......
...@@ -93,6 +93,9 @@ class Notes extends Component { ...@@ -93,6 +93,9 @@ class Notes extends Component {
saveNotes (source) { saveNotes (source) {
const provider = this.getProvider() const provider = this.getProvider()
// For some reason the first character is not in the annotation so it is not getting saved
// so we rerender the Surface
provider.config.miniEditorContext.surfaceManager.getSurface('mini').rerender()
const notes = provider.computeEntries() const notes = provider.computeEntries()
let self = this let self = this
...@@ -136,6 +139,7 @@ class Notes extends Component { ...@@ -136,6 +139,7 @@ class Notes extends Component {
onNotesUpdated (change) { onNotesUpdated (change) {
const notesProvider = this.getProvider() const notesProvider = this.getProvider()
notesProvider.config.miniEditorContext.surfaceManager.getSurface('mini').rerender()
notesProvider.handleDocumentChange(change) notesProvider.handleDocumentChange(change)
// this.el.el.style.height = '95px' // this.el.el.style.height = '95px'
} }
......
...@@ -63,24 +63,19 @@ class NotesProvider extends TOCProvider { ...@@ -63,24 +63,19 @@ class NotesProvider extends TOCProvider {
let notes = _.clone(nodes) let notes = _.clone(nodes)
let rootEl = this.config.miniEditorContext.editor.el let rootEl = this.config.miniEditorContext.editor.el
let i = 0
notes = _.map(notes, function (note) { notes = _.map(notes, function (note) {
const element = Component.unwrap(rootEl.find('p[data-path="' + note.id + '.content"]')) const element = Component.unwrap(rootEl.find('p[data-path="' + note.id + '.content"]'))
// removes a <br> insterted at the end by inline node // removes a <br> insterted at the end by inline node
const text = element.innerHTML.slice(0, -4) const text = element.innerHTML.slice(0, -4)
let noteContent = '<isolated-note data-id="' + note.id + '" parent-id="' + note.parentNoteId + '" data-type="isolated-note">' + text + '</isolated-note>' let noteContent = '<isolated-note data-id="' + note.id + '" parent-id="' + note.parentNoteId + '" data-type="isolated-note">' + text + '</isolated-note>'
// TODO For some reason the first character is not in the annotation so it is not getting saved. For that
// miniEditor has a reComputeEntries and in here we rerender Surface only the first time to get the character.
if (i === 0) this.config.miniEditorContext.surfaceManager.getSurface('mini').rerender()
i++
return { return {
id: note.id, id: note.id,
content: noteContent, content: noteContent,
parentNoteId: note.parentNoteId parentNoteId: note.parentNoteId
} }
}.bind(this)) })
return notes return notes
} }
......
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