Make text in textfields selectable in code

Post Reply
User avatar
Therenas
Factorio Staff
Factorio Staff
Posts: 232
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

Make text in textfields selectable in code

Post by Therenas »

A second idea for today: LuaGuiElements have the attribute selectable that can be set, which is great. This regulates whether text in a text-box is able to be selected by the user. A welcome addition to this would be to have a method similar to focus() (select_text() maybe?) that selects all text in the text-box. This could be used in the following way: The mod listens to an on_gui_click event, and when the user clicks on a text-box, the mod selects all text in it. That way, the user can start typing right away, replacing what was previously in the text-box without having to delete or select it himself first, which can be useful in certain contexts.

(Of course, this would be useful in textfields as well, maybe more so, as you rarely want to delete all the text of a text-box)

Boodals
Fast Inserter
Fast Inserter
Posts: 129
Joined: Sun Feb 11, 2018 7:10 pm
Contact:

Re: Make text in textfields selectable in code

Post by Boodals »

I have added this to the next version of 0.17 (I have source access).
LuaGuiElement::select(start, end)
LuaGuiElement::select_all()

User avatar
Therenas
Factorio Staff
Factorio Staff
Posts: 232
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

Re: Make text in textfields selectable in code

Post by Therenas »

Thanks a bunch!

User avatar
Therenas
Factorio Staff
Factorio Staff
Posts: 232
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

Re: Make text in textfields selectable in code

Post by Therenas »

Although what is still wierd with the way Factorio handles selection of textboxes is that when you click away (ie. move the focus to a different element), the text stays selected. This is different from pretty much any other UI I have used, and seems strange. It is fine when you click a button for example, but when you select a different textfield, you can have text selected in multiple different textboxes at once, which is rather confusing. Example:
Image

So I would say it makes sense that text is automatically unselected if you move the focus away from a textbox/field, especially if you select a different textbox/field.

Boodals
Fast Inserter
Fast Inserter
Posts: 129
Joined: Sun Feb 11, 2018 7:10 pm
Contact:

Re: Make text in textfields selectable in code

Post by Boodals »

As a guess, try making it focused at the same time as selecting text.

User avatar
Therenas
Factorio Staff
Factorio Staff
Posts: 232
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

Re: Make text in textfields selectable in code

Post by Therenas »

Well what I am describing is not an issue with the modding API, but more with how the base game works. You can, with your mouse, just select text from multiple textfields, and when you select a new one, the old selection stays (like the image shows). This is with no interference from any mod. This is what I find kind of unintuitive as a user. I guess this case doesn't come up very often in unmodded Factorio, because there are seldom multiple textfields on screen at the same time. But for mods, this is the case sometimes, and it seems wierd.

Post Reply

Return to “Implemented mod requests”