Recent

Author Topic: Error (relasing real numbers) in TSynEditStringWrappingList  (Read 2737 times)

Borneq

  • Full Member
  • ***
  • Posts: 248
Error (relasing real numbers) in TSynEditStringWrappingList
« on: December 12, 2019, 10:45:18 am »
If I call ReWrap followed by UnWrap, fRealLineNumber is cleared:
Code: Pascal  [Select][+][-]
  1. procedure TSynEditStringWrappingList.ListCleared(Sender: TObject);
  2. begin
  3.   Finalize(fRealLineNumber);
  4.   fMaxRealLine:= -1;
  5. end;
Because is
Code: Pascal  [Select][+][-]
  1. procedure TSynEditStringWrappingList.UnWrap;
  2. var
  3.   st:TStrings;
  4.   l:integer;
  5. begin
  6.   //undo wrapping, restoring lines to real lines
  7.   st := TStringList.Create;
  8.   try
  9.      for l:=0 to RealCount-1 do
  10.        st.Add(RealLine[l]);
  11.      fSynStrings.Assign(st);//<---HERE!
  12.   finally
  13.     st.Free;
  14.   end;
  15. end;    
Because fSynStrings has handler:
- Assign causes old fSynStrings is cleared, call first
Code: Pascal  [Select][+][-]
  1. procedure TSynEditStringsLinked.Clear;
  2. begin
  3.   fSynStrings.Clear;
  4. end;  
and fSynStrings.Clear also clears fRealLineNumber.
fSynStrings.Clear on destroy should clear fRealLineNumber but not on assing, how distinguish situation od Assign to not destroy fRealLineNumber , better without modification unit unit LazSynEditText but only unit synedittextwrapper ?

Solution:
Code: Pascal  [Select][+][-]
  1.      for l:=0 to RealCount-1 do
  2.        st.Add(RealLine[l]);
  3.      fSynStrings.Assign(st);
  4.      LinesChanged(fSynStrings, 0, fSynStrings.Count); //<---Added
  5.  
But is problem:
Code: Pascal  [Select][+][-]
  1. procedure TSynEditStringWrappingList.LineCountChanged(Sender: TSynEditStrings;
  2.   AIndex, ACount: Integer);
  3. var
  4.   i, hrl,rn: Integer;
  5. begin
  6.   if (not fEnabled) then exit; <--not enabled!
  7.  
Problem is because is not Enabled because
Code: Pascal  [Select][+][-]
  1. FWrappedLinesView.Enabled := eoWordWrap in fOptions2;
two solutions:
- remove line if (not fEnabled) then exit ?
- or in TSynEditStringWrappingList.LineCountChanged move code to other method,
and will
Code: Pascal  [Select][+][-]
  1. procedure TSynEditStringWrappingList.LineCountChanged(Sender: TSynEditStrings;
  2.   AIndex, ACount: Integer);
  3. var
  4.   i, hrl,rn: Integer;
  5. begin
  6.   if fEnabled then otherMethod(...)
  7. end;
  8.  
and otherMethod will called after assign?
The second is more better.

ALSO:
Code: Pascal  [Select][+][-]
  1. procedure TSynEditStringWrappingList.ReWrap;
  2. var
  3.   l, hrl:integer;
  4. begin
  5.   //foces wrapping and joining of every line
  6.   Inc(FWrappingCount);
  7.   try
  8.     if High(fRealLineNumber) < 0 then begin
  9.       SetLength(fRealLineNumber,fSynStrings.Count);
  10.       for l:= 0 to High(fRealLineNumber) do
  11.         fRealLineNumber[l] := l;
  12.       hrl := High(fRealLineNumber);
  13.       if hrl >= 0 then
  14.         fMaxRealLine:=fRealLineNumber[hrl]
  15.       else
  16.         fMaxRealLine:= -1;
  17.     end;
  18.  
Lines #12 to #16 must be added
« Last Edit: December 12, 2019, 11:35:56 am by Borneq »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9857
  • Debugger - SynEdit - and more
    • wiki
Re: Error (relasing real numbers) in TSynEditStringWrappingList
« Reply #1 on: December 12, 2019, 03:31:29 pm »
Based on which SynEdit port? or with which patch added?
Looks like some patch, since it has references to classes that are found only in the Lazarus version.

The current official Lazarus SynEdit does not have this method.

--- EDIT
I guess the patch once worked....
So assign or clear was changed afterwards.
An "svn blame" may tell you why. This may hold a clue how to best fix it.

(if you prefer git blame, there are several git mirrors)
« Last Edit: December 12, 2019, 03:46:34 pm by Martin_fr »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9857
  • Debugger - SynEdit - and more
    • wiki
Re: Error (relasing real numbers) in TSynEditStringWrappingList
« Reply #2 on: December 12, 2019, 03:44:28 pm »
Ok it is from https://bugs.freepascal.org/view.php?id=30395

And just having looked at it reminds me of why (the answer to what I wrote in another thread)
Not sure if this will help: https://bugs.freepascal.org/view.php?id=30395
Dont recall why it was not included, but IIRC there was a reason....

Actually does not even need a look at the code, the reporter wrote it in the issue description:
Quote
Didn't found a way of implementing WordWrapping without disturbing the actual string buffer, which is the way I think should be done.

This of course means (I have not tested, but I am quite sure) that after each re-wrap, undo will stop working.
So imho only usable for a read-only editor.
« Last Edit: December 12, 2019, 03:47:31 pm by Martin_fr »

 

TinyPortal © 2005-2018