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

Text editor functionality #458

Open
kozlovskisarmands opened this issue Feb 19, 2024 · 5 comments
Open

Text editor functionality #458

kozlovskisarmands opened this issue Feb 19, 2024 · 5 comments

Comments

@kozlovskisarmands
Copy link

Is it possible to use usual text editor functionality, like: copy, paste, select all etc.? (Ctrl+C/V/A)
Idea would be to copy whole object to clipboard and then just with Ctrl+V to paste it inside the JSON Viewer, is it possible and/or will it be supported in future?

@pionxzh
Copy link
Collaborator

pionxzh commented Feb 20, 2024

Let me rephrase what I understand:

  1. You want to copy "part of" or "the whole" JSON object, but I'm curious: isn't this already supported?
  2. Allow pasting in json-viewer, and it will accept and update the content?
  3. Not sure what behavior you want to see after user presses ctrl+A

@kozlovskisarmands
Copy link
Author

Hello @pionxzh!

  1. Copy as already supported, you are right.
  2. Yes, If I do Ctrl+V inside the JSON Viewer, the clipboard content should be displayed in the viewer.
  3. I think the main functionality is pasting stuff inside the viewer, but maybe Ctrl+A could highlight all of the JSON Viewer code and then simple Ctrl+C would get the whole object copied.

@pionxzh
Copy link
Collaborator

pionxzh commented Feb 21, 2024

Thanks for the detailed explanation. I believe that the implementation of this request might be more suitable to be put on userland. json-viewer shouldn't listen to these global actions as a "component".

Here are a couple of suggestions:

  1. You could try using a hidden input field that stays "focus" to catch paste events. This field would take the pasted content, figure out what it is, and update the data. It's worth looking into whether there's a simpler way to do this, this is what I have tried before.
  2. The Ctrl + A situation is a bit complicated. You can listen to the Ctrl + A event and highlight the text. Even if the text gets selected correctly, the copied content might not look right as JSON because of how the elements are shown.

I wanted to make a quick demo for you, but Next.js just stopped working on StackBlitz 😞. I'll try to fix it this week.

@kozlovskisarmands
Copy link
Author

Thanks for answer!
First method actually seems doable, I'll try.
What about JSON Viewer supporting onPaste prop itself?

@pionxzh
Copy link
Collaborator

pionxzh commented Feb 24, 2024

That would be kind of weird. You can always update the input value out of the component. paste is something that happened out of the JSON viewer, so it makes no sense to have an onPaste callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants