TurboPack / SynEdit

SynEdit is a syntax highlighting edit control, not based on the Windows common controls.
216 stars 72 forks source link

OnChange() has wrong Modification flag if user presses Ctrl+Z #246

Open danielmarschall opened 8 months ago

danielmarschall commented 8 months ago

Example code:

procedure TForm1.SynEdit1Change(Sender: TObject);
var
  tmp: string;
begin
  tmp := StringReplace(Caption, '*', '', [rfReplaceAll]);
  if SynEdit1.Modified then tmp := tmp + '*';
  if Caption <> tmp then Caption := tmp;
end;

If the user enters something, then a asterisk will be added to the Caption.

If the change is reverted using Ctrl+Z , the asterisk should disappear again, but this does not work because SynEdit1.Modified is true inside the OnChange Event. Modified should be false not true in this case.

However, after the OnChange Event, the Modified flag is set correctly.

So the "dumb" workaround for the issue is checking it with a timer.

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  SynEdit1Change(SynEdit1);
end;
danielmarschall commented 8 months ago

(Addendum: If you fix it, please also verify that the Modification will be true if the user reverts the revert by pressing Ctrl+Y. This might be another case to be considered)

pyscripter commented 8 months ago

Use the OnStatusChange event for this purpose.