Hello,
In a TextArea, I want to select the whole tag when the user clicks in the middle of the tag. It could be HTML tags:
For example, is a tag and . And so on
If the user clicks inside the word this, I want (or given which this was clicked) to be selected. I would it to be as much as integrated as possible (e.g. if the shift key is used, the selection should extend from the initial selection to include the whole tag).
The goal is that the user must not be able to alter defined tags (e.g. if I allow only , , , , , and , the user can’t mess with them and, for example, start editing to become which would have no sense for my application). I’ll handle pasting and text dropping later; that will be easier once I figure out how to include whole tags in selection.
Being a lot of work in all cases, I’m not sure how to start.
I’m seeing 3 possible ways to start:
rely only on the SelChange/TextChange events (or only one of these). I allow the user to do whatever (s)he wants (keystrokes, cut, paste, text drops) and clean the field after the fact. This lacks a lot of control and may result in destruction of data, should the allowed modification delete unexpected parts of the text.
prevent modifications using pre-processing events (filtering KeyDown, handling selection in MouseDown, overwriting the Paste event handler, checking the dropped text in DropObject). This way, unwanted actions can’t be done in the first place. This may be a lot more work, but (1) is cleaner and (2) allows more control.
use both methods. Try to prevent most possible things before modifications and use the SelChange/TextChange events to clean possible remaining errors. This looks the worst solution to me.
For each case, it’s so complex I’m not sure either way will fit my needs and be reliable in the long run.
I can prevent the command key to being used (in Mac, this allows separated characters/words to be selected, which would be disastrous and can’t be handled in Xojo). Keeping double clicks to be allowed to select whole words might also be difficult along with my own code
I’ve already tried something in the MouseDown event. I ended up with a mess: sometimes the returned char is offset by one, sometimes not, so I have random -1 or +1 in my code, which ends up being not reliable for other cases. I’ll have to start again.
Well, any idea greatly welcome!