Closed cloydlau closed 5 months ago
A quick work around I'm using is to create it in tree mode; then immediately call jsonEditor.updateProps({ mode: Mode.text })
to convert it to text.
Thanks for the reproduction Cloyd, that helps.
The steps to reproduce are:
text
mode which is emptyeditor.set({ text: '123' })
, then the error occursThe error only occurs when the new contents have a large length, i.e. to get the error again, you can call editor.set({ text: '12345' })
. But the error does not occur when making the contents shorter, like editor.set({ text: '12' })
.
I haven't figured out what is causing this error. When using editor.set
, a new instance of the code editor (CodeMirror) is created and hence should not have any knowledge about the previous contents. Help debugging this further would be welcome.
Fixed now in v0.21.3
I'm still seeing the issue with vanilla-jsoneditor.
"name": "vanilla-jsoneditor" "version": "0.21.3"
new JSONEditor({
target: element,
props: {
readOnly: true,
mainMenuBar: false,
navigationBar: false,
statusBar: false,
mode: Mode.text
}
});
RangeError: Invalid position 1 in document of length 0
at TextLeaf.lineAt (index.js:10:19)
at WrappedLineIndent.getVisibleLines (index.js:58:40)
at WrappedLineIndent.addStyleToBuilder (index.js:40:35)
at Object.read (index.js:31:30)
at index.js:7249:34
at Array.map (<anonymous>)
at EditorView.measure (index.js:7247:42)
at index.js:7382:79
Thanks for testing with the latest version. I've tried to reproduce your issue but without success so far:
https://jsbin.com/pufufol/edit?html,output
Can you share more details?
I added an update to the jsbin code and got the error.
editor.update({
json: {}
})
"RangeError: Invalid position 1 in document of length 0
at t.value (https://cdn.jsdelivr.net/npm/vanilla-jsoneditor@0.21.3/standalone.min.js:25:416667)
at e.value (https://cdn.jsdelivr.net/npm/vanilla-jsoneditor@0.21.3/standalone.min.js:25:879553)
at e.value (https://cdn.jsdelivr.net/npm/vanilla-jsoneditor@0.21.3/standalone.min.js:25:879060)
at Object.read (https://cdn.jsdelivr.net/npm/vanilla-jsoneditor@0.21.3/standalone.min.js:25:878894)
at https://cdn.jsdelivr.net/npm/vanilla-jsoneditor@0.21.3/standalone.min.js:25:620350
at Array.map (<anonymous>)
at e.value (https://cdn.jsdelivr.net/npm/vanilla-jsoneditor@0.21.3/standalone.min.js:25:620320)
at https://cdn.jsdelivr.net/npm/vanilla-jsoneditor@0.21.3/standalone.min.js:25:622924"
I also tested with an initial value, incase it was related to using update without an initial value to start but had no luck.
.update https://jsbin.com/carasariki/1/edit?html,console,output .set https://jsbin.com/yexapezasi/1/edit?html,console,output
Thanks, I'll do further debugging.
As a workaround you can, you can just not call .update
right after the editor is created (the contents is passed to along the constructor anyway). If you need that right after construction, you can maybe add a setTimeout(() => { editor.update(...) })
for the time being.
This is the work around I'm using
https://jsbin.com/desowehibi/1/edit?html,console,output
I have an Angular component using the editor; so it's created in the component constructor and the data is set in an @Input set function. So the workaround I'm using flows best in this scenario.
It looks like the issue originates from the codemirror-wrapped-line-indent extension that we use, I've reported the issue there: https://github.com/fauzi9331/codemirror-wrapped-line-indent/issues/1.
This should be fixed now in v0.21.4
, can you give it a try @thaneuk ?
Can confirm, not having the issue now with the latest update.
Many thanks for the attention to this.
Thanks for your feedback, good to hear!
Hello jos, Here is the minimal reproduction: https://github.com/cloydlau/reproduction.git