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

Ability to Paste into InputText Control #5378

Closed
BabylonJSGuide opened this issue Oct 17, 2018 · 23 comments
Closed

Ability to Paste into InputText Control #5378

BabylonJSGuide opened this issue Oct 17, 2018 · 23 comments
Labels
enhancement gui in progress Someone is currently working on this issue
Milestone

Comments

@BabylonJSGuide
Copy link
Contributor

Feature request

http://www.html5gamedevs.com/topic/40661-gui-input-text-behavior/

Use of CTRL + V to paste into inputText control

Useful Site (?) https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard

@deltakosh
Copy link
Contributor

THanks sir ;)

@ssaket
Copy link
Contributor

ssaket commented Oct 18, 2018

Hi @deltakosh and @BabylonJSGuide
please assign this to me :)

-Thanks

@deltakosh
Copy link
Contributor

It is all yours:)

@deltakosh deltakosh added in progress Someone is currently working on this issue and removed help wanted labels Oct 18, 2018
@BabylonJSGuide
Copy link
Contributor Author

Go for it @ssaket

@ssaket
Copy link
Contributor

ssaket commented Oct 20, 2018

After spending a productive day, this is the first prototype that I have come up with 💯

ice_video_20181020235620

@ssaket
Copy link
Contributor

ssaket commented Oct 20, 2018

It supports copy, paste, cut events (above)

@ssaket
Copy link
Contributor

ssaket commented Oct 20, 2018

I have few doubts on system design, as a newbie its hard for me to figure out what's the best place to
define a new function, class etc. This is what I have done -

  1. Created a new event class in Events called ClipboardEvents(just like Pointer/Keyboard )
  2. Coming to the event listeners, my first thought was to define them in DynamicTexture (because AdvanceDynamicTexture inherits it,
    and has preKeyBoardObservable which basically listens to all events and from which I can later call my corresponding subclass.. blah blah blah.. )
    • Soon after, I realised its not a good idea as DynamicTexture basically deals with texture related things and also it is part of core module (I thought its best not to define clipboard events here and ActionManager's code is really complex! Phew!! ).
    • So, I decided to put them in GUI/controls (only events actions, registration happens in AdvanceDynamicTexture) (please correct me if it shouldn't)

One major impediment-
The typescript version which we are using doesn't support navigator.clipboard or
creation of custom ClipboardEvent( the constructor doesn't let us use clipboardData while init
reference ) because of this I had to take the long route (I kinda mutated them; possible area of improvement)
Happy to discuss this further :)

@deltakosh
Copy link
Contributor

This is fantastic :)
Can you create a PR so we can discuss over it

@ssaket
Copy link
Contributor

ssaket commented Oct 21, 2018

Thanks, Sure !

@ssaket
Copy link
Contributor

ssaket commented Oct 22, 2018

@deltakosh - while working on this, I thought of a cool feature 🏷
Let's say on a PG, I found a golden sphere, which caught my interest 😍 then I decide to copy(ctr-c) it (sphere) to my clipboard and using (ctr-v) place it into some other/different scene.

In short -
Allow copy-pasting of meshes, or also generate a .babylon file using copy (ctr-c)

I think this will help the users to do fast prototyping by having a databank of files(.babylon) of their favourite meshes. Also, if I an drop (.babylon) files onto scene using (ctr-v) What do you think ? also adding @BabylonJSGuide

@deltakosh
Copy link
Contributor

Hahaha. Not sure this is something we want in the framework as it looks pretty specific and hard to discover

@ssaket
Copy link
Contributor

ssaket commented Oct 22, 2018

Fair enough.. but I still would add them in snippets 😃 after I solve my re-triangulation problem



Note* This patch can help only in copy and pasting within the ADT, users won't be able to use navigator's clipboard (); reasons:

  1. Missing Navigator.clipboard (clipboard asynchronous API) microsoft/TypeScript#26728
  2. document.execCommand("paste") is not supported in major browsers including mine.

@ssaket
Copy link
Contributor

ssaket commented Oct 25, 2018

I have realised how silly my idea was !! 🙊 This can be done in 5 line outside the framework, using -

document.addEventListener("copy", (evt) => {
         let scene = this.scene;
         scene.pick(.....) //get the mesh
         let smesh = BABYLON.SceneSerializer.SerializeMesh(mesh);
          evt.clipboardData.setData("application/json", smesh )
}, false)

#feelingEmbarrassed

@deltakosh
Copy link
Contributor

No worry:)

@deltakosh
Copy link
Contributor

Would be ok to create a doc for it? Thanks a lot (with sanples in the playground)

@ssaket
Copy link
Contributor

ssaket commented Nov 4, 2018

Yeah ! Already created a PR - https://github.com/BabylonJS/Documentation/pull/1309

@deltakosh
Copy link
Contributor

You rock

@gernot-nu-IT
Copy link

is there a chance to get a method or property to select the text of the inputText if focused by default?

@ssaket
Copy link
Contributor

ssaket commented Nov 5, 2018

@gernot-nu-IT not as of now, you have to manually add this in onFocusObservable; example- https://www.babylonjs-playground.com/#UWS0TS#22

Now that you have pointed it out, I think it makes sense to have a boolean property like onFocusSelectAll on input text which would allow this.

@gernot-nu-IT
Copy link

@ssaket yes, I think it would be quite useful. also, if text is highlighted (like in your playground example) and you start typing, the highlighted text should be replaced.

@deltakosh
Copy link
Contributor

Agree!

@deltakosh
Copy link
Contributor

Done!

@prithviMP
Copy link

prithviMP commented May 4, 2020

is there an event listener for copy paste as i want to control how this are copied in the inputText

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement gui in progress Someone is currently working on this issue
Projects
None yet
Development

No branches or pull requests

5 participants