Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$

Started by steezware, December 04, 2023, 06:21:57 PM

Previous topic - Next topic

steezware

In a multi-line control I want to grab the portion of the text that the user has selected.

For example...

       
  • a multiline contains "Hello World Canada"
  • the user double-taps on "World" and it shows as selected, highlighted
  • they then click another control on the panel - or simply tab off the multiline
  • in the logic that follows I attempt to grab the 'SelectOffset and 'SelectLength attributes ... but on leaving the multiline the users "World" selection is lost - no longer selected
  • so what I really get in SelectOffset is 12, the zero-based offset for the "d" in "World"
  • I need to get values 6 and 5
This is in Nomads, under *Nomads object control, and I do not have any OnFocus or OnSelect logic tied to the multiline control either in the Nomads panel definition or in my UI class (although I have tried using them and signal-all-changes and signal-on-exit and everything else I could think of).

I can, of course, do a ML'SelectOffset=6 and ML'SelectLength=5 and manually highlight "World", so that works...

...but how to I grab "World" when the user selects it and leaves the multiline control?

Help? Thx!

Arno de Greef

I see the same thing happen, however if I change the multi-line height to 2 (a multi-line multi-line  :D), the problem seems to disappear.

steezware

Turns out that fetching 'SelectOffset and 'SelectLenght does work just fine, but the problem I am having turns out to be that the multiline control as it loses focus clears out the selection. So I need to figure out how to grab the offset/length when Nomads moves off the multiline before it loses focus?

I have tried 'Change and 'OnFocus and even thought maybe 'Validator or 'Formatter Nomads class functions would fire allow me to jump in and get the select offset/length, but no luck.

Or is there some multiline option/attribute that needs to be set to preserve the text selection when the multiline loses focus?

steezware

Okay, putting this question/issue to rest. Arno was correct when he mentioned that making the multiline 2 rows high allowed for fetching 'SelectOffset, 'SelectLength and 'SelectText$.

So, I faked out my panel by making the multiline borderless and 2 lines high. I also messed around with making the font double-sized, which had an affect on fetching the offset and length.

Question to PxPlus is - why is it so difficult to fetch the offset and length of selected text in a multiline without work-arounds like making the control 2 rows high?

Len Vassos

PVX Plus Technologies, Ltd.

Mike King

#5
What you are seeing is normal Windows behavior. 

For example if you run any windows application and ask it to open a file, then in the file name field (a single line entry field) enter your text "Hello World Canada", select the second word and press tab to exit the field, you will see that the selected text get automatically unselected.

Only multiple line inputs preserve the selected text in Windows.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

Mike King

#6
Oh and if you really want to use a single line input and have access to 'SelectOffset, 'SelectLength, etc., use a POPUP menu on the control.

Windows will NOT clear the selection if you right click to invoke the popup menu for the control so in your popup menu logic you can access the selection information.

This is how Windows handles this -- Anything looking to access the selected text generally does so from a Right click popup especially when dealing with single line input fields.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com