Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeError: Selection points outside of document #423

Closed
cloydlau opened this issue Apr 13, 2024 · 2 comments
Closed

RangeError: Selection points outside of document #423

cloydlau opened this issue Apr 13, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@cloydlau
Copy link
Contributor

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: #331

@josdejong
Copy link
Owner

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 5ed8a86 (not yet published)

@josdejong josdejong added the bug Something isn't working label Apr 17, 2024
@josdejong
Copy link
Owner

Fix published now in v0.23.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants