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)
Make text in textfields selectable in code
Re: Make text in textfields selectable in code
I have added this to the next version of 0.17 (I have source access).
LuaGuiElement::select(start, end)
LuaGuiElement::select_all()
LuaGuiElement::select(start, end)
LuaGuiElement::select_all()
Re: Make text in textfields selectable in code
Thanks a bunch!
Re: Make text in textfields selectable in code
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](https://forums.factorio.com/images/ext/fe79b46320f458cd87a1e8640245b8d3.png)
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.
![Image](https://forums.factorio.com/images/ext/fe79b46320f458cd87a1e8640245b8d3.png)
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.
Re: Make text in textfields selectable in code
As a guess, try making it focused at the same time as selecting text.
Re: Make text in textfields selectable in code
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.