PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$  (Read 622 times)

steezware

  • Member
  • **
  • Posts: 16
    • View Profile
    • steezware
Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$
« on: December 04, 2023, 06:21:57 PM »
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

  • Member
  • **
  • Posts: 10
    • View Profile
Re: Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$
« Reply #1 on: December 06, 2023, 10:46:41 AM »
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

  • Member
  • **
  • Posts: 16
    • View Profile
    • steezware
Re: Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$
« Reply #2 on: December 06, 2023, 12:45:40 PM »
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

  • Member
  • **
  • Posts: 16
    • View Profile
    • steezware
Re: Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$
« Reply #3 on: December 06, 2023, 02:22:21 PM »
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

  • Administrator
  • Gold Member
  • *****
  • Posts: 92
    • View Profile
Re: Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$
« Reply #4 on: December 10, 2023, 12:58:39 PM »
Thanks for the info, Scott.  We will review.
PVX Plus Technologies, Ltd.

Mike King

  • Diamond Member
  • *****
  • Posts: 3799
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$
« Reply #5 on: December 11, 2023, 09:58:51 AM »
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.
« Last Edit: December 11, 2023, 07:46:19 PM by Mike King »
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

Mike King

  • Diamond Member
  • *****
  • Posts: 3799
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$
« Reply #6 on: December 11, 2023, 11:00:52 AM »
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.
« Last Edit: December 11, 2023, 07:44:58 PM by Mike King »
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

steezware

  • Member
  • **
  • Posts: 16
    • View Profile
    • steezware
Re: Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$
« Reply #7 on: December 11, 2023, 12:15:58 PM »
Thank you, Mike!