Recent

Author Topic: WordWrap in Synedit  (Read 13592 times)

Borneq

  • Full Member
  • ***
  • Posts: 127
WordWrap in Synedit
« on: December 14, 2010, 11:28:23 pm »
WordWrap was in old Delphi version Synedit and I can't found it in Lazarus Synedit version. Is possible break (wrap) line especially in html file ?

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: WordWrap in Synedit
« Reply #1 on: December 14, 2010, 11:43:50 pm »
See SysUtils.WrapText(Line :string; MaxCol :integer):string;

Although this function has the stupid behaviour of not to wrap quoted text.
« Last Edit: December 15, 2010, 12:10:44 am by typo »

captian jaster

  • Guest
Re: WordWrap in Synedit
« Reply #2 on: December 15, 2010, 12:37:43 am »
See SysUtils.WrapText(Line :string; MaxCol :integer):string;

Although this function has the stupid behaviour of not to wrap quoted text.
It should be implemented into the Synedit soon..
Hopefully.. ;_;

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5567
    • wiki
Re: WordWrap in Synedit
« Reply #3 on: December 15, 2010, 01:28:20 am »
SynEdit in Lazarus doesn't yet have it.

SysUtils.WrapText( is fundamentally different from what you need to implement WordWrap in SynEdit.

dkjMusic

  • Full Member
  • ***
  • Posts: 146
Re: WordWrap in Synedit
« Reply #4 on: September 20, 2011, 03:31:31 am »
SysUtils.WrapText( is fundamentally different from what you need to implement WordWrap in SynEdit.
Yeah...plus WrapText doesn't work.

Does someone have a WrapText code that does work?
Windows 7 Ultimate/32 bit;
Lazarus 0.9.31/Rev 33300;
FPC 2.7.1/Rev 19464;
GDB 7.0.50;
(via CodeTyphon 2.30)

dabdala

  • New member
  • *
  • Posts: 6
Re: WordWrap in Synedit
« Reply #5 on: July 20, 2016, 05:38:55 pm »
After searching like a mad men (well.. I am), I didn't found wrapping code, so I implemented word wrapping in a similar way Trimming and TabExpansion.

I don't like, but it works. My problem now is I don't know how/where to share the code for others to get inspired and do it properly.

The implementation requires a new class and modifications to existing classes (TCustomSynEdit) and (TSynViewer).

I implemented and tested it on Linux, using Lazarus 1.0.14, and Windows XP, using a newer version of Lazarus (1.6 with FPC 3.0).

Attached is the wrapping class, and a file with the explanation of what to change in other places.

Hope it helps someone.
David.

-- (2016/08/02) --
Updated files with several bugs fixed.
« Last Edit: August 02, 2016, 04:06:07 pm by dabdala »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5567
    • wiki
Re: WordWrap in Synedit
« Reply #6 on: July 20, 2016, 07:41:31 pm »
you could upload it on the bug tracker, and then link it from the wiki too.

If it is on the tracker I can (when I find some time) review it for inclusion.

dabdala

  • New member
  • *
  • Posts: 6
Re: WordWrap in Synedit
« Reply #7 on: July 21, 2016, 02:10:17 pm »
Thanks, I just did both.

tcmdvm

  • New Member
  • *
  • Posts: 16
Re: WordWrap in Synedit
« Reply #8 on: July 21, 2016, 07:56:51 pm »
Could you be more specific where the following code should be located?

Code: Pascal  [Select]
  1. TCustomSynEdit=class..
  2.  [..]
  3.     FWrappedLinesView: TSynEditStringWrappingList;
  4.  [..]
  5.  public
  6.     procedure SaveToStream(Stream:TStream);virtual;
  7.     procedure LoadFromStream(Stream:TStream);virtual;
  8. [..]
  9.  end;

I have put it where I thought it should go but I am getting a EditorMacroScript (has detected a problem and is deactivated), and then it throws a bunch of Access Violations and crashes.

I am testing with FPC 3.0 and Lazarus 1.60 with fixes.

dabdala

  • New member
  • *
  • Posts: 6
Re: WordWrap in Synedit
« Reply #9 on: July 22, 2016, 08:09:14 pm »
Uhhmm.. that sounds like SynEdit has changed a lot between versions.

Right now I can't test with your version, I've developed it in a much older version. The code you posted goes where you added it, in the private part of the class the field definition and in any public part the methods.

You can find the classes I've modified attached. You'll see there are lots of changes from version to version.

Sorry I can't be more helpful.

dabdala

  • New member
  • *
  • Posts: 6
Re: WordWrap in Synedit
« Reply #10 on: August 02, 2016, 04:10:51 pm »
I just realized I'm using version 1.6 (FPC 3.0) on Windows XP and is working properly.

On this setup I had to modify the SynEdit Package (didn't have to on Linux) saving modified file versions on different folder an recompiling the package.

Attached are the modified files I'm using on this version.

McClane

  • New Member
  • *
  • Posts: 22
Re: WordWrap in Synedit
« Reply #11 on: September 26, 2017, 05:47:52 am »
Hi, I really need text wrapping and I don't know how to use it.
I've downloaded the tree files in BugsTracker
syneditwordwrapping.zip [^] (7,646 bytes) 2016-07-21 13:49
syneditwordwrapping_update.zip [^] (8,252 bytes) 2016-08-02 16:13
synedit.zip [^] (132,048 bytes) 2016-08-02 16:13
I've copied all the files in my project folder.
It was compiled and runs but nothing happens.

I've tried save and load from stream, but I get 'Read from Stream is not supported'.
How can i use word wrapping?
Thanks in advance.

dabdala

  • New member
  • *
  • Posts: 6
Re: WordWrap in Synedit
« Reply #12 on: September 26, 2017, 12:39:02 pm »
You didn't mention what version of Lazarus you are using, nor on what platform, so I presume you are on Windows, with latest version.
On Windows you need to copy the files on the folder where the SynEdit package is (the package that is compiled with the IDE), and recompile the package, so the IDE version of the package gets the wordwrapping functionality.
Copying to your project folder is not enough, as you are still using the original version of the files that comes with the package.
Once you recompile the package, you should have the oeWordWrap property, and be able to Save/Load from Stream.
As an example, I created a Frame with a TSynEdit on it, on the constructor of the frame the highlighter is created and assigned to the SynEdit (a custom highlighter in this case), Memo1 is the TSynEdit:
Code: Pascal  [Select]
  1. FHL := TSynMINGGASyn.Create(Memo1);
  2. [..]
  3. FHL.KeyWords.Add('#SS');
  4. Memo1.Highlighter := FHL;
  5. Memo1.Options2 := Memo1.Options2 + [eoWordWrap];
Later..
Code: Pascal  [Select]
  1. st := Tarea.CreateBlobStream(Tarea.FieldByName('contenido'),bmWrite);
  2. try
  3.   Memo1.SaveToStream(st);
  4. finally
  5.   st.Free;
  6. end;
  7.  
Hope this helps.
David.

McClane

  • New Member
  • *
  • Posts: 22
Re: WordWrap in Synedit
« Reply #13 on: September 26, 2017, 04:51:34 pm »
Wow Dave, thank you. It is working but I don't understand tarea.
Please, explain me what kind of stream is st and tarea.
By the way I'm a linux user and I'm using and old Ubuntu and Lazarus 1.6.4 and fpc 3.0.2
Thank you for your reply.

The problem is if i use TMemoryStream doesn't load anything? :O
Code: Pascal  [Select]
  1. var  st:   TMemoryStream
  2. begin
  3.       st:= TMemoryStream.Create;
  4.       try
  5.         SynEdit1.SaveToStream(st);
  6.         SynEdit1.LoadFromStream(st);
  7.       finally
  8.         st.Free;
  9.       end;
  10.  

« Last Edit: September 26, 2017, 05:09:43 pm by McClane »

dabdala

  • New member
  • *
  • Posts: 6
Re: WordWrap in Synedit
« Reply #14 on: September 26, 2017, 05:20:01 pm »
Sorry, my example is missing context..
I'm using a BlobStream in the example, Tabla is a DataSet.
In your case, the problem is that after SaveToStream(), the Stream is at the end, so if you plan to load from the stream, you need to reposition it:
Code: Pascal  [Select]
  1. st := TMemoryStream.Create;
  2. try
  3.   SynEdit1.SaveToStream(st);
  4.   st.Position := 0;
  5.   SynEdit2.LoadFromStream(st); //now both should have the same content
  6. finally
  7.   st.Free;
  8. end;