Closed tatarysh closed 6 months ago
I'm, not sure what you mean. Can you maybe explain it with an example?
Do you mean you're inserting JSON from clipboard into the selected location? You can do that (by hand) by pasting with Ctrl+V
. Or do you mean you would like a keyboard shortcut for the "Insert Structure" button in the context menu?
If you want to insert JSON programmatically, it may be easiest to just take your JSON data and the current selection and insert the JSON that you want directly into the JSON (not via the editor)?
I would like to add an option that will add json code where the cursor is, but the json code is generated and is always different (the structure is always the same)
my sample json:
{
"name": "{name}",
"data": {
"key": "{unique-string}"
}
}
maybe some event that will accept a function that will return what should be added to json?
You can keep track on where the cursor is via onSelect
. You can add a keydown
event listener to the div
where you have created the JSON editor, and listen for the quick key that you want to use for your insert action. When that triggers, you can insert the contents in one of the following ways:
editor.patch(...)
. This would be my preferred solution.
I write a lot of JSON code in which I have to write the same structure, I would like to automate it and create a keyboard shortcut and insert ready-made json, is it possible and if so, how? I tried using
document.execCommand
andnavigator.clipboard.writeText
, unfortunately both solutions do not work.