[Request] Moving text cursor with arrows keys and mouse
WesCook opened this issue ยท 5 comments
Better Questing is working great, however my biggest hurdle is editing large blocks of text. It's very frustrating having to hold Left or Right arrows for 30+ seconds to get to the correct spot to edit.
Would it be possible to add basic arrow key navigation (up/down, home/end, and maybe ctrl+left/ctrl+right)? Clicking into a spot with your cursor would also be great.
Currently my approach for long fields is to save the file, close the world, and edit them manually in a text editor. It's tricky to do though as you need to remember to properly format linebreaks, quotes, and other special characters.
I know this is probably a more difficult task (even Vanilla has janky editing in books) -- but I feel it would be a significant quality of life upgrade for this mod.
Thanks!
I've been trying to find a reliable way to implement this for a while now (trust me I know how bad the text editor is) but because the UI is dynamically sized which affects the word wrapping, there isn't an easy way of determining a cursor position from an arbitrary location on screen. I have a couple of experimental ideas I could try and implement in a later build for the mouse clicking but the arrow keys are still yet to be worked out.
Ah, I figured it'd be something like that.
I'm going to do the obnoxious thing where the bug reporter acts like they know better for a second, just as a heads up. :)
For a lower-hanging fruit, ctrl+left and ctrl+right should be a lot simpler to program. You can look for the next space character to set the cursor position to. Even holding Ctrl+Right would be significantly faster than holding just Right, so it may be worth implementing sooner, and focusing on the other stuff later.
For the more complex arrow key features (home/end, up/down), what I'd look into is seeing if you could figure out where the text wraps (is that the hard bit?). With that you could build an array using the wrapping point as a separator, and let Home/End go to that point. Setting the same position in the previous or next indice would then work for Up/Down, but you'd need to also subtract any color code characters earlier in that indice.
This is assuming a monospace font. Otherwise it gets even trickier.
For the cursor detection... I don't really know. It might be something you can calculate with monospaced fonts, but I'm not sure how badly GUI scaling and scrolling would mess that up. Then you have the color codes problem again.
Not sure how best to approach that one, really.
@WesCook Hammered out this part so far (works with all formatting codes too):
https://puu.sh/sYu79/119702b79a.gif
Also I don't mind too much about suggested solutions (as long as you know what you're talking about)
I noticed this was still open and figured I'd give my two-cents. It would require a font change, but you could implement the up/down and home/end keys without much issue if you changed over to a monospaced font for the text editor. All you'd need then is a way to calculate the number of characters on a line (textbox width / character width?) and use that for calculating where to move the cursor to. I'm not sure how you have the special characters implemented (the ones used for colors and formatting), but they'd need to be ignored in the cursor movement math. That shouldn't be too difficult since they're already hidden in the textbox though (then again, I haven't looked at how the box is implemented and could be assuming all wrong here). Anyways, it's just a thought. Might not want to change fonts though lol