TurboPack / SynEdit

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

Calling Undo after Lines.LoadFromFile #204

Closed dados closed 2 years ago

dados commented 2 years ago

For example when loading a file using Lines.LoadFromFile the action is undo-able. So when pushing CTRL+Z or just calling synedit.undo; everything is cleared.

Example: synedit1.Lines.LoadFromFile('c:\temp\somefile.txt'); synedit1.Undo; -- Text is cleared

synedit1.Lines.LoadFromFile('c:\temp\somefile.txt'); synedit1.ClearUndo; synedit1.Undo; -- Nothing happens

The same goes for: synedit1.Lines.Text := 'some text'; synedit1.Text := 'some text';

And also if I set some lines in design time and run the application and call synedit.undo; or push CTRL+Z the last line is deleted/removed

This is a different behavior than before. Is this intended to work like this?

pyscripter commented 2 years ago

You can do

fForm.SynEdit.LockUndo;
try
  Synedit.Lines.Text := 'some text';
finally
  fForm.SynEdit.UnlockUndo;
end;
SynEdit.Modified := False

It is faster than calling SynEdit.ClearUndo after loading the file.

dados commented 2 years ago

Thank you :)

But the actual question was the changed behavior. Was that intentional? Normally when loading a file or replacing the whole buffer the undo history is cleared automatically.

pyscripter commented 2 years ago

Yes it was intentional.
The new undo records all changes to the buffer unless you tell it not to.

Normally when or replacing the whole buffer the undo history is cleared automatically.

SynEdit does not know whether say you are pasting text, typing text on an empty buffer or loading a new file. Use LockUndo/UnlockUndo or Clearundo when you load a file.

dados commented 2 years ago

Ok good to know. Thanks :)