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

Move Caret to End of Input Box #419

Closed
Stuyk opened this issue Feb 22, 2023 · 9 comments
Closed

Move Caret to End of Input Box #419

Stuyk opened this issue Feb 22, 2023 · 9 comments
Labels
enhancement New feature or request

Comments

@Stuyk
Copy link

Stuyk commented Feb 22, 2023

I can't find any relevant information on this and the traditional functions that are utilized in normal javascript aren't available here.

Any options for this?

@mikke89 mikke89 added the enhancement New feature or request label Feb 22, 2023
@mikke89
Copy link
Owner

mikke89 commented Feb 22, 2023

Yeah, I can see this as being useful. I'm sure we could add an API for that. Do you have a suggestion?

As a work-around in the mean time, you could possibly get away with sending a keydown event to the element with the KI_END key.

@Stuyk
Copy link
Author

Stuyk commented Feb 22, 2023

Thank you for the tip on that. That being said a general API for determining where to place the caret based on length of the content inside would probably be sufficient. 👍🏻

@mikke89
Copy link
Owner

mikke89 commented Feb 24, 2023

Alright, I am trying to understand your needs more clearly. Can you give more details on the suggested general API, or do you mean simply a MoveCaretToEnd() function with no inputs?

Can you point me to the related DOM/Javscript functions?

@Stuyk
Copy link
Author

Stuyk commented Feb 24, 2023

I think this would be sufficient. It allows you to select a range of text; or simply just move the selection to the very end of the input box.

https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange

Alternatively setting a value on an input box and moving the cursor to the end automatically could be sufficient for the input box behavior as well.

mikke89 added a commit that referenced this issue Mar 12, 2023
@mikke89
Copy link
Owner

mikke89 commented Mar 12, 2023

Hey, I tried to implement this API now. Could you test it out, and let me know how it works for you?
If you find any issues, or some of its behavior could be improved, please let me know.

I didn't implement automatic movement of the cursor to the end. I'm a bit worried about how it plays out together with data bindings, and I figured it's safer to give that control fully to the user.

@ShawnCZek
Copy link
Contributor

Being able to move the input caret around is really useful. And at least in my case scenario, it works perfectly fine 🚀

Would it also be possible to add a getter for the current text selection? In JavaScript, which was referenced earlier, this is done by calling window.getSelection(). It returns a complex object with all kinds of stuff. Doing something similar is overkill for this library, in my opinion, and just returning a pair of integers for the start and end index will be good enough.

Similarly, are there any plans for adding these functions to Lua? 👀

@mikke89
Copy link
Owner

mikke89 commented Mar 23, 2023

Good to hear it's working!

A GetSelection method sounded useful to me, so I went ahead and added it to the same elements, Do you think this API is suitable? If you could test it a bit and see if it works for you, let me know.

As for the Lua plugin, that is mostly user-contributed. I'll happily accept any PRs ;)

ShawnCZek added a commit to ShawnCZek/RmlUi that referenced this issue Mar 24, 2023
@ShawnCZek
Copy link
Contributor

The API feels clean and works as expected, too! I was first confused by UTF-8 strings but then realized that it was just a problem with Visual Studio and the Windows console I used for debugging.

I have also locally made Lua bindings for all three new methods. I guess it makes more sense to make a PR for this once the API is stable. In other words, once it is merged into the master branch.

@mikke89
Copy link
Owner

mikke89 commented Mar 24, 2023

Great, I've merged it into master now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants