View Issue Details

IDProjectCategoryView StatusLast Update
0024371LazarusLCLpublic2018-01-04 15:07
ReporterFabrizio FelliniAssigned ToJuha Manninen 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version1.1 (SVN)Product Build 
Target VersionFixed in Version 
Summary0024371: Wrong usage of SelStart and SelLength in OnChange event only the first time
DescriptionTry to put this code into OnChange of a TEdit with AutoSelect=True:

Edit1.Text := 'ABCDEF';
Edit1.SelStart := 1;
Edit1.SelLength := Length (Edit1.Text);

and after firing OnChange event, only the first time, nothing is selected.
When AutoSelect=False instead everything is fine.
TagsNo tags attached.
Fixed in Revisionr56287
LazTarget-
WidgetsetGTK 2
Attached Files
  • test.zip (3,331 bytes)
  • newpatch.diff (1,000 bytes)
    Index: lcl/interfaces/gtk2/gtk2callback.inc
    ===================================================================
    --- lcl/interfaces/gtk2/gtk2callback.inc	(revisione 41121)
    +++ lcl/interfaces/gtk2/gtk2callback.inc	(copia locale)
    @@ -431,6 +431,7 @@
       NeedCursorCheck := False;
       if GTK_IS_ENTRY(Widget) then
       begin
    +    NeedCursorCheck := True;
         // lcl-do-not-change-selection comes from gtkKeyPress.
         // Only floatspinedit sets that data, so default is nil. issue #18679
         if g_object_get_data(PGObject(Widget),'lcl-do-not-change-selection') = nil then
    @@ -460,7 +461,7 @@
             begin
               // if we change selstart in OnChange event new cursor pos need to
               // be postponed in TGtk2WSCustomEdit.SetSelStart
    -          NeedCursorCheck := True;
    +          //NeedCursorCheck := True;
               if g_object_get_data(PGObject(Widget),'lcl-gtkentry-pasted-data') <> nil then
               begin
                 g_object_set_data(PGObject(Widget),'lcl-gtkentry-pasted-data',nil);
    
    newpatch.diff (1,000 bytes)

Relationships

related to 0020890 resolvedZeljan Rikalo Lazarus Wrong usage of SelStart and SelLength in OnChange event 
related to 0030596 resolvedJuha Manninen Lazarus error in the keyboard backspace key on linux TEdit 
related to 0032321 resolvedMichl Lazarus TEdit / TDbEdit cursor position after overwrite text 
related to 0032583 resolvedJuha Manninen Packages TMemo.SelText does not work correctly 
related to 0032630 closedJuha Manninen Lazarus [patch] Gtk2 TEdit/TMemo: fix text selection, make OnChange event compatible with LCL-Win32 
related to 0032196 closedJuha Manninen Lazarus BorderSpacing changes byt itself when multi-selecting components 

Activities

Fabrizio Fellini

2013-05-03 14:13

reporter   ~0067389

It's related to issue 0020890.

Fabrizio Fellini

2013-05-05 08:56

reporter   ~0067441

Last edited: 2013-05-05 08:57

View 3 revisions

I've done a test, setting a breakpoint on:
  Edit1.Text := 'ABCDEF';
with Lazarus for Linux (versions 0.9.30.4, 1.06, SVN), and for Windows (version 1.08).

When I press a key, the first time, the application stops 6 times; the second, 3 times. Why?

And then, with Windows widgetset, why does the application stop only and always 2 times?

Zeljan Rikalo

2013-05-05 11:09

developer   ~0067451

You are comparing events of 2 totally different widgetsets ? ;)

Zeljan Rikalo

2013-05-05 13:48

developer   ~0067464

Also, just tested this scenario with gtk2 and qt widgetsets (lazarus trunk): both selects complete text (if AutoSelect=True).

Fabrizio Fellini

2013-05-05 15:20

reporter   ~0067470

Last edited: 2013-05-05 15:25

View 2 revisions

The breakpoint isn't in the widgetset's code, but in the application's code... so this code should have the same behavior with all widgetsets!
In my opinion, the Windows behavior (2 stops) is correct, the GTK2 one (6 stops the first time, 3 afterwords) is wrong.

Zeljan Rikalo

2013-05-05 17:55

developer   ~0067475

@Fabrizio: This issue is duplicate of resloved issue 0020890. I can clearly see selection (When AutoSelect=True then complete text is selected, otherwise selection is 1, length(Text)). IMO, this should be closed.

Fabrizio Fellini

2013-05-06 10:16

reporter   ~0067497

Last edited: 2013-05-06 14:54

View 5 revisions

Zeljan,
I tested again after "svn update" (revision 41044).
With Autoselect=True and Text="Edit1", when I press a key, for example "g", the first time, when all "Edit1" is selected, Text value changes in "ABCDEF" but without any selection and with cursor position after "B".
Also Edit1OnChange's calls continue to be 6 instead of 2.
If you may concern, I used a Slackware 13.1 with gtk 2.18.9 over an Aspire One ZG5.

Zeljan Rikalo

2013-05-07 16:21

developer   ~0067543

Please, attach example and steps to reproduce.

Fabrizio Fellini

2013-05-08 09:56

reporter  

test.zip (3,331 bytes)

Fabrizio Fellini

2013-05-08 10:08

reporter   ~0067567

Zeljan,
I noticed this only now, preparing attached file:
it's the breakpoint presence to alter the behavior!
Without breakpoint, the application seems OK!
With breakpoint on "Edit1.Text := 'ABCDEF';", the trouble happens.
See you if something needs to be corrected or not!

Fabrizio Fellini

2013-05-11 10:49

reporter   ~0067636

Last edited: 2013-05-11 10:53

View 2 revisions

Zeljan,
I'm sorry, I made a mistake in last post!
I'm still not very experienced in the use of svn and I launched the application forgetting a small patch in gtk2callbak.inc that solved my problem about cursor position and selection: that's why the application seemed OK!
The problem still remain especially for excessive number of calls of the OnChange event.
Now I'm attaching the patch.

Fabrizio Fellini

2013-05-11 10:51

reporter  

newpatch.diff (1,000 bytes)
Index: lcl/interfaces/gtk2/gtk2callback.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2callback.inc	(revisione 41121)
+++ lcl/interfaces/gtk2/gtk2callback.inc	(copia locale)
@@ -431,6 +431,7 @@
   NeedCursorCheck := False;
   if GTK_IS_ENTRY(Widget) then
   begin
+    NeedCursorCheck := True;
     // lcl-do-not-change-selection comes from gtkKeyPress.
     // Only floatspinedit sets that data, so default is nil. issue #18679
     if g_object_get_data(PGObject(Widget),'lcl-do-not-change-selection') = nil then
@@ -460,7 +461,7 @@
         begin
           // if we change selstart in OnChange event new cursor pos need to
           // be postponed in TGtk2WSCustomEdit.SetSelStart
-          NeedCursorCheck := True;
+          //NeedCursorCheck := True;
           if g_object_get_data(PGObject(Widget),'lcl-gtkentry-pasted-data') <> nil then
           begin
             g_object_set_data(PGObject(Widget),'lcl-gtkentry-pasted-data',nil);
newpatch.diff (1,000 bytes)

Zeljan Rikalo

2013-05-11 16:56

developer   ~0067644

That patch fixes your problem ?

Fabrizio Fellini

2013-05-11 18:02

reporter   ~0067647

Last edited: 2013-05-11 18:08

View 3 revisions

Yes, the problem related to cursor position and selection is fixed by that patch.
But I don't know whether it's right or wrong to call LockOnChange every time we are in a GtkEntry.

Juha Manninen

2017-10-08 14:19

developer   ~0103257

Last edited: 2017-10-20 23:05

View 2 revisions

Please test with r55998.
Actually I had changed that code earlier.
I cannot reproduce the error now but it can happen with some GTK2 versions.

Juha Manninen

2017-10-21 17:29

developer   ~0103653

No feedback. Detaching myself.

Juha Manninen

2017-11-05 22:53

developer   ~0103892

Fixed, please test.

Fedon Kadifeli

2018-01-04 15:07

reporter   ~0105323

Sorry, I am new to this. But, this problem still persists in Lazarus 1.8.0 which supposedly contains r55998.

Where can I find r56287 mentioned in the header? It is not listed in:
http://wiki.freepascal.org/Lazarus_1.8_fixes_branch

Issue History

Date Modified Username Field Change
2013-05-03 14:12 Fabrizio Fellini New Issue
2013-05-03 14:13 Fabrizio Fellini Note Added: 0067389
2013-05-05 08:56 Fabrizio Fellini Note Added: 0067441
2013-05-05 08:57 Fabrizio Fellini Note Edited: 0067441 View Revisions
2013-05-05 08:57 Fabrizio Fellini Note Edited: 0067441 View Revisions
2013-05-05 11:09 Zeljan Rikalo Note Added: 0067451
2013-05-05 13:48 Zeljan Rikalo Note Added: 0067464
2013-05-05 15:20 Fabrizio Fellini Note Added: 0067470
2013-05-05 15:25 Fabrizio Fellini Note Edited: 0067470 View Revisions
2013-05-05 16:25 Juha Manninen Relationship added related to 0020890
2013-05-05 17:55 Zeljan Rikalo Note Added: 0067475
2013-05-06 10:16 Fabrizio Fellini Note Added: 0067497
2013-05-06 10:18 Fabrizio Fellini Note Edited: 0067497 View Revisions
2013-05-06 13:46 Fabrizio Fellini Note Edited: 0067497 View Revisions
2013-05-06 14:53 Fabrizio Fellini Note Edited: 0067497 View Revisions
2013-05-06 14:54 Fabrizio Fellini Note Edited: 0067497 View Revisions
2013-05-07 16:21 Zeljan Rikalo Note Added: 0067543
2013-05-08 09:56 Fabrizio Fellini File Added: test.zip
2013-05-08 10:08 Fabrizio Fellini Note Added: 0067567
2013-05-11 10:49 Fabrizio Fellini Note Added: 0067636
2013-05-11 10:51 Fabrizio Fellini File Added: newpatch.diff
2013-05-11 10:53 Fabrizio Fellini Note Edited: 0067636 View Revisions
2013-05-11 16:56 Zeljan Rikalo Note Added: 0067644
2013-05-11 18:02 Fabrizio Fellini Note Added: 0067647
2013-05-11 18:07 Fabrizio Fellini Note Edited: 0067647 View Revisions
2013-05-11 18:08 Fabrizio Fellini Note Edited: 0067647 View Revisions
2017-08-25 10:18 Juha Manninen Relationship added related to 0032321
2017-10-08 14:01 Juha Manninen Assigned To => Juha Manninen
2017-10-08 14:01 Juha Manninen Status new => assigned
2017-10-08 14:06 Juha Manninen Relationship added related to 0030596
2017-10-08 14:19 Juha Manninen LazTarget => -
2017-10-08 14:19 Juha Manninen Note Added: 0103257
2017-10-08 14:19 Juha Manninen Status assigned => feedback
2017-10-20 22:43 Juha Manninen Relationship added related to 0032581
2017-10-20 22:44 Juha Manninen Relationship deleted related to 0032581
2017-10-20 22:44 Juha Manninen Relationship added related to 0032583
2017-10-20 23:05 Juha Manninen Note Edited: 0103257 View Revisions
2017-10-21 17:29 Juha Manninen Note Added: 0103653
2017-10-21 17:29 Juha Manninen Assigned To Juha Manninen =>
2017-10-21 17:29 Juha Manninen Status feedback => new
2017-10-31 09:15 Juha Manninen Relationship added related to 0032630
2017-11-05 22:53 Juha Manninen Fixed in Revision => r56287
2017-11-05 22:53 Juha Manninen Note Added: 0103892
2017-11-05 22:53 Juha Manninen Status new => resolved
2017-11-05 22:53 Juha Manninen Resolution open => fixed
2017-11-05 22:53 Juha Manninen Assigned To => Juha Manninen
2017-11-24 21:13 Juha Manninen Relationship added related to 0032196
2018-01-04 15:07 Fedon Kadifeli Note Added: 0105323