Recent

Author Topic: Tedit selected text  (Read 1500 times)

Paolo

  • Hero Member
  • *****
  • Posts: 538
Tedit selected text
« on: September 18, 2023, 09:41:06 pm »
Hello (FPC/LAZ=3.2.2/2.2.6)

I have a class derived from Tedit where the main purpose is to handle numerical input.

I noticed that if you put on a form a TEdit, say Edit1, and as text you put '100', a double clicking on the number select the whole number, in this way it can be easy overwritten, but if the number (actually the text) is '-100' a double click omits the '-' in the slected text, how can implement a doubleclick that select "negative numbers", ie the whole '-100'. (In this case a sort of "selectall" should be sufficent anyway).

thank you.
« Last Edit: September 18, 2023, 09:45:23 pm by Paolo »

Bart

  • Hero Member
  • *****
  • Posts: 5469
    • Bart en Mariska's Webstek
Re: Tedit selected text
« Reply #1 on: September 18, 2023, 10:06:46 pm »
That depends wether or not the '-100' is in fact the complete text or just a part of the text.
In the first case, just do a SelectAll.
In the seceond case, determine the value of SelStart, see if the character before the selection is a '-', and if that is the case decrement SelStart by 1.

Bart

Paolo

  • Hero Member
  • *****
  • Posts: 538
Re: Tedit selected text
« Reply #2 on: September 24, 2023, 10:11:15 pm »
The criteria how text Is select Is coming from OS settings ? or .. ?

Bart

  • Hero Member
  • *****
  • Posts: 5469
    • Bart en Mariska's Webstek
Re: Tedit selected text
« Reply #3 on: September 25, 2023, 12:01:55 pm »
You can override the DoubleClick method to make the component do whatever you want.

Bart

TRon

  • Hero Member
  • *****
  • Posts: 3650
Re: Tedit selected text
« Reply #4 on: September 25, 2023, 12:10:37 pm »
The criteria how text Is select Is coming from OS settings ? or .. ?
For fun I tried to select the quoted -100 in your first post e.g. " ie the whole '-100'. " by double clicking the number 100.

Now try to guess what happened  ;)
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

Paolo

  • Hero Member
  • *****
  • Posts: 538
Re: Tedit selected text
« Reply #5 on: September 25, 2023, 01:20:10 pm »
In my replay n.4 it was my curiosity to know "who" defined the selection criteria of text in tedit.
For example if you have as text '100-100' (quotes are not really there), a doubleclick on one of '100' it becames the selected text, if you have '100+100' a doubleclick on one '100' selects the whole string. Did you see a different behaviour?

TRon

  • Hero Member
  • *****
  • Posts: 3650
Re: Tedit selected text
« Reply #6 on: September 25, 2023, 01:27:14 pm »
In my replay n.4 it was my curiosity to know "who" defined the selection criteria of text in tedit.
Yeah, I understood what you meant. Making it more clear for you then: OS (but individual software might influence default behaviour).

Quote
For example if you have as text '100-100' (quotes are not really there), a doubleclick on one of '100' it becames the selected text, if you have '100+100' a doubleclick on one '100' selects the whole string. Did you see a different behaviour?
That is indeed remarkable because for me it selects the number 100 only. Either the first one or the last one depending on what number 100 I double-clicked.
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

Paolo

  • Hero Member
  • *****
  • Posts: 538
Re: Tedit selected text
« Reply #7 on: September 25, 2023, 05:01:50 pm »
@TRon, are you on windows ?

TRon

  • Hero Member
  • *****
  • Posts: 3650
Re: Tedit selected text
« Reply #8 on: September 25, 2023, 06:00:10 pm »
@Paolo:
Debian Linux, Mate with Marco and tested with FireFox 117.0.1
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

Bart

  • Hero Member
  • *****
  • Posts: 5469
    • Bart en Mariska's Webstek
Re: Tedit selected text
« Reply #9 on: September 25, 2023, 09:46:29 pm »
For example if you have as text '100-100' (quotes are not really there), a doubleclick on one of '100' it becames the selected text, if you have '100+100' a doubleclick on one '100' selects the whole string. Did you see a different behaviour?
Yeah, confirmed on Win10. And Delphi 7 behaves the same.
Apparently it's the OS that does it (at least in DblClick (implemented in TControl) we do nothig ourselves).

It shows this behaviour for '1+1+1', but not for 'test+test', but it does for '1+a', but for '1+a+b' it selects '1+a' if you double click anywhere in the '1+a' part, otherwise it selects the '+b' part.

There will of course be some reasoning behind this behaviour, but it's beyond me.

Bart
« Last Edit: September 25, 2023, 09:53:57 pm by Bart »

Paolo

  • Hero Member
  • *****
  • Posts: 538
Re: Tedit selected text
« Reply #10 on: September 25, 2023, 10:02:19 pm »
Thanks Bart for checking.

Since I have a lot of numerical input it is annoying that to overwrite a data in case of negative value the user has to edit manually the '-' sign.
However if, as in my case, I have a lot of edit, moving among them via "TAB" always select the whole text (this makes sense because edit doesn't know what you want select).

Ciao.

PS: if I discover where is such setting I'll post here.

Paolo

  • Hero Member
  • *****
  • Posts: 538
Re: Tedit selected text
« Reply #11 on: September 25, 2023, 11:03:07 pm »
it seems no published settings in windows are available to tune this behaviour  %)

https://superuser.com/questions/203163/where-do-i-configure-the-default-text-selection-behavior-in-windows

at the end "SelectAll" is fine for me...

thaks to all.

 

TinyPortal © 2005-2018