josdejong / svelte-jsoneditor

A web-based tool to view, edit, format, repair, query, transform, and validate JSON
https://jsoneditoronline.org
Other
814 stars 108 forks source link

RangeError: Selection points outside of document #423

Closed cloydlau closed 2 months ago

cloydlau commented 2 months ago

Hello,

Minimal reproduction:

<!doctype html>
<html lang="en">
  <body>
    <div id="jsoneditor"></div>
    <button onclick="set()">set value</button>
    <script type="module">
      import { JSONEditor } from 'https://cdn.jsdelivr.net/npm/vanilla-jsoneditor/standalone.js'

      const editor = new JSONEditor({
        target: document.getElementById('jsoneditor'),
        props: {
          content: {
            text: '',
          },
          mode: 'text',
        },
      })

      window.set = () => {
        editor.set({
          text: '',
        })
      }
    </script>
  </body>
</html>

Steps to reproduce:

  1. Input anything in the editor
  2. Click the 'set value' button to set a new value

It seems different from this one: https://github.com/josdejong/svelte-jsoneditor/issues/331

josdejong commented 2 months ago

Thanks for reporting. The issue was that the editor still kept the old selection (like the caret is at the 3th character, which is invalid when the new contents is empty and doesn't ahve a 3rd character.

Fixed via https://github.com/josdejong/svelte-jsoneditor/commit/5ed8a86a6166064d8bd27af6299db18cdf762885 (not yet published)

josdejong commented 2 months ago

Fix published now in v0.23.2