Moon Logic deprecated

by mk-fg

Adds Lua-programmable circuit network combinator. Based on Sandboxed LuaCombinator and LuaCombinator2 mods. Probably won't work in multiplayer games.

Content
2 years ago
1.0 - 1.1
5.00K
Circuit network

i [cantfix] Cursor Position

4 years ago

When I click with the mouse on the editor screen, the entire text is selected. I think would be better simply move the cursor to that location.

Thanks.

4 years ago

Don't think it can be controlled from modding api, just click twice on that location, I guess.
There's also a thing where if you have error highlighted in the code, and click on it, cursor gets put into a weird location, because on-click handler removes error tags for copy-pasting, and that changes text from under the cursor.
Didn't see any obvious way to fix that last time I checked, unfortunately, and guess maybe it should be added to Known Issues in the README.

4 years ago
(updated 4 years ago)

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".

4 years ago

I understand.

Thanks for the answer!

New response