Just double-checked API docs, and wanted to write it down in case I'll forget what's the blocker here exactly:
- There is no good way to get cursor position (i.e. where one clicked) when text-box get highlighted.
- Default placing of cursor when selecting the text-box cannot be influenced.
Wrt first issue - there's no widget.get_cursor_position() kind of method that I was able to find, so no good way to code "player clicked here, so when changing text (e.g. removing tags or whatever), reposition the cursor to the same place" behavior.
I think it should be possible to get click position in pixels, and calculate offset within widget, but then guessing text position for that is very difficult, given var-width font of arbitrary size (depending on game settings) - can maybe be done by making mock-widget and measuring same text in it, but that's too complex, error-prone and probably won't work well enough anyway.
Second issue where entire text is selected, if I understand correctly, about default text-box widget behavior, that also can't be changed.
Getting cursor position won't even help here, as with such selection, it should always be at the end, so a bit different problem.
Should be possible to always move cursor to a specific position on click, regardless of where widget was clicked, or how default-selection works, but pretty sure it'd be worse and more counter-intuitive than the standard "select all on first click, put cursor under pointer on subsequent clicks" behavior of text-boxes.
In general, it's one of these "good text editing is very hard" issues, where I think best solution is "don't bother editing >3-line text in factorio textboxes, just use proper editor and paste stuff from there".