I am afraid that didn’t work either.
My code is very straightforward:
set value (v) {
const state = this.view.state
this.view.dispatch({
changes: { from: 0, to: state.doc.length, insert: v || '' }
})
// This will tell us if the value was just set
this._valueJustSet = true
}
...
this.view = new EditorView({
state: EditorState.create({
extensions: [
...
EditorView.updateListener.of(update => this._maybeFoldAll(update))
...
_maybeFoldAll (update) {
console.log(`_maybeFoldAll: docChanged: ${update.docChanged}, flags: ${update.flags}, _valueJustSet: ${!!this._valueJustSet}, syntaxTreeAvailable: ${!!syntaxTreeAvailable(this.view.state)}, syntaxParserRunning: ${!!syntaxParserRunning(this.view)}`)
if (!this._valueJustSet) return
if (syntaxParserRunning(this.view)) return
// if (!syntaxTreeAvailable(this.view.state) || ) return
console.log('Folding!')
this._valueJustSet = false
foldAll(this.view)
}
The result is not what was hoped:
Value just set!
co-codemirror.js:150 _maybeFoldAll: docChanged: false, flags: 14, _valueJustSet: true, syntaxTreeAvailable: false, syntaxParserRunning: true
co-codemirror.js:150 _maybeFoldAll: docChanged: false, flags: 0, _valueJustSet: true, syntaxTreeAvailable: false, syntaxParserRunning: true
co-codemirror.js:150 _maybeFoldAll: docChanged: false, flags: 0, _valueJustSet: true, syntaxTreeAvailable: false, syntaxParserRunning: false
co-codemirror.js:154 Folding!
co-codemirror.js:150 _maybeFoldAll: docChanged: false, flags: 6, _valueJustSet: false, syntaxTreeAvailable: false, syntaxParserRunning: false
4co-codemirror.js:150 _maybeFoldAll: docChanged: false, flags: 4, _valueJustSet: false, syntaxTreeAvailable: false, syntaxParserRunning: false
co-codemirror.js:150 _maybeFoldAll: docChanged: false, flags: 4, _valueJustSet: false, syntaxTreeAvailable: false, syntaxParserRunning: true
co-codemirror.js:150 _maybeFoldAll: docChanged: false, flags: 0, _valueJustSet: false, syntaxTreeAvailable: false, syntaxParserRunning: false
co-codemirror.js:150 _maybeFoldAll: docChanged: false, flags: 0, _valueJustSet: false, syntaxTreeAvailable: true, syntaxParserRunning: false
3co-codemirror.js:150 _maybeFoldAll: docChanged: false, flags: 4, _valueJustSet: false, syntaxTreeAvailable: true, syntaxParserRunning: false
Interestingly, only about three quarters of the file was folded. As you can see, the parser stopped running for a while, and then it restarted. I read in the documentation that the parser can, and will, do that if it’s taking too much time.
I looked everywhere for hints – I even checked if the flags might mean something (although they were just Focus, Height, Viewport, Geometry).
Is there anything, at all, that will say “parsing is done”?